can render form yey

Oleg committed Sep 27, 2011
commit 61f43438631bd644b14948ae4751048c0fecf7b5
Showing 7 changed files with 27 additions and 28 deletions
comfortable_mexican_sofa/form_builder.rb b/lib/comfortable_mexican_sofa/form_builder.rb +7 -8
@@ @@ -71,13 +71,12 @@ class ComfortableMexicanSofa::FormBuilder < ActionView::Helpers::FormBuilder
options[:content_field_method] ||= :text_field_tag
field =
options[:field] ||
- @template.send(
- options[:content_field_method],
- 'page[blocks_attributes][][content]',
- tag.content,
- :id => nil,
- :class => field_css_class
- )
+ case method = options[:content_field_method]
+ when :file_field_tag
+ @template.send(method, 'page[blocks_attributes][][content]', :id => nil, :class => field_css_class)
+ else
+ @template.send(method, 'page[blocks_attributes][][content]', tag.content, :id => nil, :class => field_css_class)
+ end
content = "#{field} #{@template.hidden_field_tag('page[blocks_attributes][][label]', tag.label, :id => nil)}"
simple_field(label, content, :class => css_class)
end
@@ @@ -119,7 +118,7 @@ class ComfortableMexicanSofa::FormBuilder < ActionView::Helpers::FormBuilder
end
def page_file(tag)
- default_tag_field(tag, :content_field_method => :file_field) +
+ default_tag_field(tag, :content_field_method => :file_field_tag) +
"FILES: #{tag.block.files.to_yaml}"
end
comfortable_mexican_sofa/tag.rb b/lib/comfortable_mexican_sofa/tag.rb +1 -11
@@ @@ -3,7 +3,7 @@
# This module provides all Tag classes with neccessary methods.
# Example class that will behave as a Tag:
# class MySpecialTag
- # include CmsTag
+ # include ComfortableMexicanSofa::Tag
# ...
# end
module ComfortableMexicanSofa::Tag
@@ @@ -76,16 +76,6 @@ module ComfortableMexicanSofa::Tag
page.blocks.detect{|b| b.label == self.label.to_s} || page.blocks.build(:label => self.label.to_s)
end
- # Find or initialize Cms::Snippet object
- def snippet
- page.site.snippets.detect{|s| s.slug == self.label.to_s} || page.site.snippets.build(:slug => self.label.to_s)
- end
-
- # Initializing Cms::File object
- def file
- page.site.files.detect{|f| f.file_file_name == self.label.to_s}
- end
-
# Checks if this tag is using Cms::Block
def is_cms_block?
%w(page field collection file).member?(self.class.to_s.demodulize.underscore.split(/_/).first)
comfortable_mexican_sofa/tags/collection.rb b/lib/comfortable_mexican_sofa/tags/collection.rb +0 -4
@@ @@ -47,10 +47,6 @@ class ComfortableMexicanSofa::Tag::Collection
klass.respond_to?(:cms_collection) ? klass.cms_collection(*collection_params).all : klass.all
end
- def content=(value)
- block.content = value
- end
-
def content
block.content
end
comfortable_mexican_sofa/tags/file.rb b/lib/comfortable_mexican_sofa/tags/file.rb +5 -0
@@ @@ -6,6 +6,11 @@ class ComfortableMexicanSofa::Tag::File
/\{\{\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
comfortable_mexican_sofa/tags/page_file.rb b/lib/comfortable_mexican_sofa/tags/page_file.rb +4 -0
@@ @@ -1,6 +1,10 @@
class ComfortableMexicanSofa::Tag::PageFile
include ComfortableMexicanSofa::Tag
+ # Signature of a tag:
+ # {{ cms:page_file:some_label:file_partial:params }}
+ # Simple tag can be:
+ # {{ cms:page_file:some_label }}
def self.regex_tag_signature(label = nil)
label ||= /[\w\-]+/
/\{\{\s*cms:page_file:(#{label}):?(.*?)\s*\}\}/
comfortable_mexican_sofa/tags/snippet.rb b/lib/comfortable_mexican_sofa/tags/snippet.rb +5 -0
@@ @@ -6,6 +6,11 @@ class ComfortableMexicanSofa::Tag::Snippet
/\{\{\s*cms:snippet:(#{label})\s*\}\}/
end
+ # Find or initialize Cms::Snippet object
+ def snippet
+ page.site.snippets.detect{|s| s.slug == self.label.to_s} || page.site.snippets.build(:slug => self.label.to_s)
+ end
+
def content
snippet.content
end
test/unit/tags/collection_test.rb +5 -5
@@ @@ -74,10 +74,10 @@ class CollectionTagTest < ActiveSupport::TestCase
assert tag = ComfortableMexicanSofa::Tag::Collection.initialize_tag(
cms_pages(:default), '{{ cms:collection:snippet:cms/snippet }}'
)
- assert tag.content.blank?
+ assert tag.block.content.blank?
snippet = cms_snippets(:default)
- tag.content = snippet.id
+ tag.block.content = snippet.id
assert_equal snippet.id, tag.block.content
assert_equal snippet.id, tag.content
assert_equal "<%= render :partial => 'partials/cms/snippets', :locals => {:model => 'Cms::Snippet', :identifier => '#{snippet.id}'} %>", tag.render
@@ @@ -87,10 +87,10 @@ class CollectionTagTest < ActiveSupport::TestCase
assert tag = ComfortableMexicanSofa::Tag::Collection.initialize_tag(
cms_pages(:default), '{{ cms:collection:snippet:cms/snippet:path/to/partial:label:slug:param_a:param_b }}'
)
- assert tag.content.blank?
+ assert tag.block.content.blank?
snippet = cms_snippets(:default)
- tag.content = snippet.slug
+ tag.block.content = snippet.slug
assert_equal snippet.slug, tag.block.content
assert_equal snippet.slug, tag.content
assert_equal "<%= render :partial => 'path/to/partial', :locals => {:model => 'Cms::Snippet', :identifier => '#{snippet.slug}', :param_1 => 'param_a', :param_2 => 'param_b'} %>", tag.render
@@ @@ -100,7 +100,7 @@ class CollectionTagTest < ActiveSupport::TestCase
assert tag = ComfortableMexicanSofa::Tag::Collection.initialize_tag(
cms_pages(:default), '{{ cms:collection:snippet:cms/snippet:path/to/partial }}'
)
- assert tag.content.blank?
+ assert tag.block.content.blank?
assert_equal '', tag.render
end