Sha256: 96b3d0991d96ba0c34c3eb1b0921b52470e42eeeda6ececc1e4c408863f2ab39

Contents?: true

Size: 644 Bytes

Versions: 12

Compression:

Stored size: 644 Bytes

Contents

class ComfortableMexicanSofa::Tag::File
  include ComfortableMexicanSofa::Tag
  
  def self.regex_tag_signature(label = nil)
    label ||= /[\w\-\.]+/
    /\{\{\s*cms:file:(#{label}):?(.*?)\s*\}\}/
  end
  
  # Initializing Cms::File object
  def file
    page.site.files.detect{|f| f.file_file_name == self.label.to_s}
  end
  
  def content
    return unless file
    
    format  = params[0]
    text    = params[1] || label
    
    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.5.11 lib/comfortable_mexican_sofa/tags/file.rb
comfortable_mexican_sofa-1.5.10 lib/comfortable_mexican_sofa/tags/file.rb
comfortable_mexican_sofa-1.5.9 lib/comfortable_mexican_sofa/tags/file.rb
comfortable_mexican_sofa-1.5.8 lib/comfortable_mexican_sofa/tags/file.rb
comfortable_mexican_sofa-1.5.7 lib/comfortable_mexican_sofa/tags/file.rb
comfortable_mexican_sofa-1.5.6 lib/comfortable_mexican_sofa/tags/file.rb
comfortable_mexican_sofa-1.5.5 lib/comfortable_mexican_sofa/tags/file.rb
comfortable_mexican_sofa-1.5.4 lib/comfortable_mexican_sofa/tags/file.rb
comfortable_mexican_sofa-1.5.3 lib/comfortable_mexican_sofa/tags/file.rb
comfortable_mexican_sofa-1.5.2 lib/comfortable_mexican_sofa/tags/file.rb
comfortable_mexican_sofa-1.5.1 lib/comfortable_mexican_sofa/tags/file.rb
comfortable_mexican_sofa-1.5.0 lib/comfortable_mexican_sofa/tags/file.rb