Sha256: 4101d9280888b74205d35f6232ea611c62ff537cb5713fadc75fb52efb358c71

Contents?: true

Size: 686 Bytes

Versions: 12

Compression:

Stored size: 686 Bytes

Contents

class ComfortableMexicanSofa::Tag::File
  include ComfortableMexicanSofa::Tag
  
  def self.regex_tag_signature(identifier = nil)
    identifier ||= IDENTIFIER_REGEX
    /\{\{\s*cms:file:(#{identifier}):?(.*?)\s*\}\}/
  end
  
  # Initializing Comfy::Cms::File object
  def file
    blockable.site.files.detect{|f| f.file_file_name == self.identifier.to_s}
  end
  
  def content
    return unless file
    
    format  = params[0]
    text    = params[1] || identifier
    
    case format
    when 'link'
      "<a href='#{file.file.url}' target='_blank'>#{text}</a>"
    when 'image'
      "<img src='#{file.file.url}' alt='#{text}' />"
    else
      file.file.url
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-1.12.11 lib/comfortable_mexican_sofa/tags/file.rb
comfortable_mexican_sofa-1.12.10 lib/comfortable_mexican_sofa/tags/file.rb
comfortable_mexican_sofa-1.12.9 lib/comfortable_mexican_sofa/tags/file.rb
comfortable_mexican_sofa-1.12.8 lib/comfortable_mexican_sofa/tags/file.rb
comfortable_mexican_sofa-1.12.7 lib/comfortable_mexican_sofa/tags/file.rb
comfortable_mexican_sofa-1.12.6 lib/comfortable_mexican_sofa/tags/file.rb
comfortable_mexican_sofa-1.12.5 lib/comfortable_mexican_sofa/tags/file.rb
comfortable_mexican_sofa-1.12.4 lib/comfortable_mexican_sofa/tags/file.rb
comfortable_mexican_sofa-1.12.3 lib/comfortable_mexican_sofa/tags/file.rb
comfortable_mexican_sofa-1.12.2 lib/comfortable_mexican_sofa/tags/file.rb
comfortable_mexican_sofa-1.12.1 lib/comfortable_mexican_sofa/tags/file.rb
comfortable_mexican_sofa-1.12.0 lib/comfortable_mexican_sofa/tags/file.rb