Class: ComfortableMexicanSofa::Tag::PageFile
Constant Summary
IDENTIFIER_REGEX, TOKENIZER_REGEX
Instance Attribute Summary
#blockable, #identifier, #namespace, #params, #parent
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.regex_tag_signature(identifier = nil) ⇒ Object
Signature of a tag:
{{ cms:page_file:some_label:type:params }}
Simple tag can be:
{{ cms:page_file:some_label }}
8
9
10
11
|
# File 'lib/comfortable_mexican_sofa/tags/page_file.rb', line 8
def self.regex_tag_signature(identifier = nil)
identifier ||= IDENTIFIER_REGEX
/\{\{\s*cms:page_file:(#{identifier}):?(.*?)\s*\}\}/
end
|
Instance Method Details
#content ⇒ Object
23
24
25
|
# File 'lib/comfortable_mexican_sofa/tags/page_file.rb', line 23
def content
block.files.first
end
|
#dimensions ⇒ Object
19
20
21
|
# File 'lib/comfortable_mexican_sofa/tags/page_file.rb', line 19
def dimensions
params[0].to_s.match(/\[(.*?)\]/)[1] rescue nil
end
|
#render ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/comfortable_mexican_sofa/tags/page_file.rb', line 27
def render
file = block.files.first
case self.type
when 'url' then render_url(file)
when 'link' then render_link(file)
when 'image' then render_image(file)
when 'partial' then render_partial(file)
else ''
end
end
|
#render_image(file) ⇒ Object
49
50
51
52
53
|
# File 'lib/comfortable_mexican_sofa/tags/page_file.rb', line 49
def render_image(file)
return '' unless file
text = params[1] || file.label
"<img src='#{file.file.url}' alt='#{text}' />"
end
|
#render_link(file) ⇒ Object
43
44
45
46
47
|
# File 'lib/comfortable_mexican_sofa/tags/page_file.rb', line 43
def render_link(file)
return '' unless file
text = params[1] || identifier
"<a href='#{file.file.url}' target='_blank'>#{text}</a>"
end
|
#render_partial(file) ⇒ Object
55
56
57
58
59
60
|
# File 'lib/comfortable_mexican_sofa/tags/page_file.rb', line 55
def render_partial(file)
path = params[1] || 'partials/page_file'
ps = (self.params[2..-1] || []).collect_with_index{|p, i| ":param_#{i+1} => '#{p}'"}.join(', ')
ps = ps.present?? ", #{ps}" : ''
"<%= render :partial => '#{path}', :locals => {:identifier => #{file.try(:id) || 'nil'}#{ps}} %>"
end
|
#render_url(file) ⇒ Object
38
39
40
41
|
# File 'lib/comfortable_mexican_sofa/tags/page_file.rb', line 38
def render_url(file)
return '' unless file
file.file.url
end
|
#type ⇒ Object
Type of the tag controls how file is rendered
14
15
16
17
|
# File 'lib/comfortable_mexican_sofa/tags/page_file.rb', line 14
def type
s = params[0].to_s.gsub(/\[.*?\]/, '')
%w(partial url image link field).member?(s) ? s : 'url'
end
|