class EditorJs::Blocks::AttachesBlock
attaches block
Constants
- EXTENSIONS
- ICONS
Public Instance Methods
plain()
click to toggle source
# File lib/editor_js/blocks/attaches_block.rb, line 107 def plain decode_html data['title'].strip end
render(_options = {})
click to toggle source
# File lib/editor_js/blocks/attaches_block.rb, line 71 def render(_options = {}) file_info = data['file'] title = data['title'] extension = file_info['name']&.split('.')&.last extension = '' unless EXTENSIONS.key?(extension) content_tag :div, class: css_name do html_str = content_tag :div, class: "#{css_name}__file-icon", data: {extension: extension}, style: "color: #{EXTENSIONS[extension]};" do (EXTENSIONS[extension] ? ICONS[:file_icon] : ICONS[:custom_file_icon]).html_safe end html_str += content_tag :div, class: "#{css_name}__file-info" do [ content_tag(:div, title, class: "#{css_name}__title"), content_tag(:div, number_to_human_size(file_info['size']), class: "#{css_name}__size") ].join().html_safe end html_str += content_tag :a, class: "#{css_name}__download-button", href: file_info['url'], target: '_blank', rel: 'nofollow noindex noreferrer' do ICONS[:download_icon].html_safe end html_str.html_safe end end
sanitize!()
click to toggle source
# File lib/editor_js/blocks/attaches_block.rb, line 96 def sanitize! data['title'] = Sanitize.fragment(data['title'], remove_contents: true).strip file_info = data['file'] || {} file_info.each do |key, val| break if key == 'size' file_info[key] = Sanitize.fragment(val, remove_contents: true).strip end data['file'] = file_info end
schema()
click to toggle source
# File lib/editor_js/blocks/attaches_block.rb, line 9 def schema YAML.safe_load(<<~YAML) type: object additionalProperties: false properties: file: type: object additionalProperties: false properties: url: type: string name: type: string type: type: string size: type: number title: type: string required: - file YAML end