Class: ComfortableMexicanSofa::Tag::PageFiles

Inherits:
PageFile
  • Object
show all
Includes:
ComfortableMexicanSofa::Tag
Defined in:
lib/comfortable_mexican_sofa/tags/page_files.rb

Constant Summary

Constants included from ComfortableMexicanSofa::Tag

IDENTIFIER_REGEX, TOKENIZER_REGEX

Instance Attribute Summary

Attributes included from ComfortableMexicanSofa::Tag

#blockable, #identifier, #namespace, #params, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PageFile

#dimensions, #type

Class Method Details

.regex_tag_signature(identifier = nil) ⇒ Object



6
7
8
9
# File 'lib/comfortable_mexican_sofa/tags/page_files.rb', line 6

def self.regex_tag_signature(identifier = nil)
  identifier ||= IDENTIFIER_REGEX
  /\{\{\s*cms:page_files:(#{identifier}):?(.*?)\s*\}\}/
end

Instance Method Details

#contentObject



11
12
13
# File 'lib/comfortable_mexican_sofa/tags/page_files.rb', line 11

def content
  block.files
end

#renderObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/comfortable_mexican_sofa/tags/page_files.rb', line 15

def render
  files = block.files
  case self.type
    when 'url'      then render_url(files)
    when 'link'     then render_link(files)
    when 'image'    then render_image(files)
    when 'partial'  then render_partial(files)
    else ''
  end
end

#render_image(files) ⇒ Object



38
39
40
41
# File 'lib/comfortable_mexican_sofa/tags/page_files.rb', line 38

def render_image(files)
  return '' if files.blank?
  files.collect{|file| super(file)}.join(' ')
end


31
32
33
34
35
36
# File 'lib/comfortable_mexican_sofa/tags/page_files.rb', line 31

def render_link(files)
  return '' if files.blank?
  files.collect do |file|
    "<a href='#{file.file.url}' target='_blank'>#{file.label}</a>"
  end.join(' ')
end

#render_partial(files) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/comfortable_mexican_sofa/tags/page_files.rb', line 43

def render_partial(files)
  path = params[1] || 'partials/page_files'
  ps = (self.params[2..-1] || []).collect_with_index{|p, i| ":param_#{i+1} => '#{p}'"}.join(', ')
  ps = ps.present?? ", #{ps}" : ''
  ids = files.present?? files.collect(&:id).join(',') : ''
  "<%= render :partial => '#{path}', :locals => {:identifier => [#{ids}]#{ps}} %>"
end

#render_url(files) ⇒ Object



26
27
28
29
# File 'lib/comfortable_mexican_sofa/tags/page_files.rb', line 26

def render_url(files)
  return '' if files.blank?
  files.collect{|file| super(file)}.join(', ')
end