snippet fixtures sync is in place;

Oleg committed Apr 29, 2011
commit 670cb4610209933b1da77fdf4313271ef403baa7
Showing 69 changed files with 531 additions and 1202 deletions
cms_fixtures/example.com/layouts/default/_default.yml b/db/cms_fixtures/example.com/layouts/default/_default.yml +1 -0
@@ @@ -0,0 +1 @@
+ label: Default Layout
\ No newline at end of file
cms_fixtures/example.com/layouts/default/content.html b/db/cms_fixtures/example.com/layouts/default/content.html +5 -0
@@ @@ -0,0 +1,5 @@
+ <html>
+ <body>
+ {{ cms:page:content }}
+ </body>
+ </html>
\ No newline at end of file
cms_fixtures/example.com/layouts/default/css.css b/db/cms_fixtures/example.com/layouts/default/css.css +1 -0
@@ @@ -0,0 +1 @@
+ body{color: red}
\ No newline at end of file
cms_fixtures/example.com/layouts/default/js.js b/db/cms_fixtures/example.com/layouts/default/js.js +1 -0
@@ @@ -0,0 +1 @@
+ // default js
\ No newline at end of file
cms_fixtures/example.com/layouts/default/nested/_nested.yml b/db/cms_fixtures/example.com/layouts/default/nested/_nested.yml +1 -0
@@ @@ -0,0 +1 @@
+ label: Default Layout
\ No newline at end of file
cms_fixtures/example.com/layouts/default/nested/content.html b/db/cms_fixtures/example.com/layouts/default/nested/content.html +2 -0
@@ @@ -0,0 +1,2 @@
+ <div class='left'> {{ cms:page:left }} </div>
+ <div class='right'> {{ cms:page:right }} </div>
\ No newline at end of file
cms_fixtures/example.com/layouts/default/nested/css.css b/db/cms_fixtures/example.com/layouts/default/nested/css.css +1 -0
@@ @@ -0,0 +1 @@
+ div{float:left}
\ No newline at end of file
cms_fixtures/example.com/layouts/default/nested/js.js b/db/cms_fixtures/example.com/layouts/default/nested/js.js +1 -0
@@ @@ -0,0 +1 @@
+ // nested js
\ No newline at end of file
cms_fixtures/example.com/pages/index/_index.yml b/db/cms_fixtures/example.com/pages/index/_index.yml +2 -0
@@ @@ -0,0 +1,2 @@
+ label: Home Page
+ layout: default
\ No newline at end of file
cms_fixtures/example.com/pages/index/child/_child.yml b/db/cms_fixtures/example.com/pages/index/child/_child.yml +1 -0
@@ @@ -0,0 +1 @@
+ label: Child Page
\ No newline at end of file
cms_fixtures/example.com/pages/index/child/content.html b/db/cms_fixtures/example.com/pages/index/child/content.html +1 -0
@@ @@ -0,0 +1 @@
+ Child Page Conte dnt
\ No newline at end of file
cms_fixtures/example.com/pages/index/child/subchild/_subchild.yml b/db/cms_fixtures/example.com/pages/index/child/subchild/_subchild.yml +2 -0
@@ @@ -0,0 +1,2 @@
+ label: Sub-Child Page
+ layout: nested
\ No newline at end of file
cms_fixtures/example.com/pages/index/child/subchild/left.html b/db/cms_fixtures/example.com/pages/index/child/subchild/left.html +1 -0
@@ @@ -0,0 +1 @@
+ Sub Child Page Left Content
\ No newline at end of file
cms_fixtures/example.com/pages/index/child/subchild/right.html b/db/cms_fixtures/example.com/pages/index/child/subchild/right.html +1 -0
@@ @@ -0,0 +1 @@
+ Sub Child Page Right Content
\ No newline at end of file
cms_fixtures/example.com/pages/index/content.html b/db/cms_fixtures/example.com/pages/index/content.html +2 -0
@@ @@ -0,0 +1,2 @@
+ Home Page Content
+ {{ cms:snippet:example }}
\ No newline at end of file
cms_fixtures/example.com/snippets/default/_default.yml b/db/cms_fixtures/example.com/snippets/default/_default.yml +1 -0
@@ @@ -0,0 +1 @@
+ label: Default Fixture Snippet
\ No newline at end of file
cms_fixtures/example.com/snippets/default/content.html b/db/cms_fixtures/example.com/snippets/default/content.html +1 -0
@@ @@ -0,0 +1 @@
+ Fixture Content for Default Snippet
\ No newline at end of file
cms_fixtures/example.local/layouts/default/_default.yml b/db/cms_fixtures/example.local/layouts/default/_default.yml +0 -1
@@ @@ -1 +0,0 @@
- label: Default Layout
\ No newline at end of file
cms_fixtures/example.local/layouts/default/content.html b/db/cms_fixtures/example.local/layouts/default/content.html +0 -5
@@ @@ -1,5 +0,0 @@
- <html>
- <body>
- {{ cms:page:content }}
- </body>
- </html>
\ No newline at end of file
cms_fixtures/example.local/layouts/default/css.css b/db/cms_fixtures/example.local/layouts/default/css.css +0 -1
@@ @@ -1 +0,0 @@
- body{color: red}
\ No newline at end of file
cms_fixtures/example.local/layouts/default/js.js b/db/cms_fixtures/example.local/layouts/default/js.js +0 -1
@@ @@ -1 +0,0 @@
- // default js
\ No newline at end of file
cms_fixtures/example.local/layouts/default/nested/_nested.yml b/db/cms_fixtures/example.local/layouts/default/nested/_nested.yml +0 -1
@@ @@ -1 +0,0 @@
- label: Default Layout
\ No newline at end of file
cms_fixtures/example.local/layouts/default/nested/content.html b/db/cms_fixtures/example.local/layouts/default/nested/content.html +0 -2
@@ @@ -1,2 +0,0 @@
- <div class='left'> {{ cms:page:left }} </div>
- <div class='right'> {{ cms:page:right }} </div>
\ No newline at end of file
cms_fixtures/example.local/layouts/default/nested/css.css b/db/cms_fixtures/example.local/layouts/default/nested/css.css +0 -1
@@ @@ -1 +0,0 @@
- div{float:left}
\ No newline at end of file
cms_fixtures/example.local/layouts/default/nested/js.js b/db/cms_fixtures/example.local/layouts/default/nested/js.js +0 -1
@@ @@ -1 +0,0 @@
- // nested js
\ No newline at end of file
cms_fixtures/example.local/pages/index/_index.yml b/db/cms_fixtures/example.local/pages/index/_index.yml +0 -2
@@ @@ -1,2 +0,0 @@
- label: Home Page
- layout: default
\ No newline at end of file
cms_fixtures/example.local/pages/index/child/_child.yml b/db/cms_fixtures/example.local/pages/index/child/_child.yml +0 -1
@@ @@ -1 +0,0 @@
- label: Child Page
\ No newline at end of file
cms_fixtures/example.local/pages/index/child/content.html b/db/cms_fixtures/example.local/pages/index/child/content.html +0 -1
@@ @@ -1 +0,0 @@
- Child Page Conte dnt
\ No newline at end of file
cms_fixtures/example.local/pages/index/child/subchild/_subchild.yml b/db/cms_fixtures/example.local/pages/index/child/subchild/_subchild.yml +0 -2
@@ @@ -1,2 +0,0 @@
- label: Sub-Child Page
- layout: nested
\ No newline at end of file
cms_fixtures/example.local/pages/index/child/subchild/left.html b/db/cms_fixtures/example.local/pages/index/child/subchild/left.html +0 -1
@@ @@ -1 +0,0 @@
- Sub Child Page Left Content
\ No newline at end of file
cms_fixtures/example.local/pages/index/child/subchild/right.html b/db/cms_fixtures/example.local/pages/index/child/subchild/right.html +0 -1
@@ @@ -1 +0,0 @@
- Sub Child Page Right Content
\ No newline at end of file
cms_fixtures/example.local/pages/index/content.html b/db/cms_fixtures/example.local/pages/index/content.html +0 -2
@@ @@ -1,2 +0,0 @@
- Home Page Content
- {{ cms:snippet:example }}
\ No newline at end of file
cms_fixtures/example.local/snippets/default/_default.yml b/db/cms_fixtures/example.local/snippets/default/_default.yml +0 -1
@@ @@ -1 +0,0 @@
- label: Default Snippet
\ No newline at end of file
cms_fixtures/example.local/snippets/default/content.html b/db/cms_fixtures/example.local/snippets/default/content.html +0 -1
@@ @@ -1 +0,0 @@
- Content for Snippet
\ No newline at end of file
comfortable_mexican_sofa.rb b/lib/comfortable_mexican_sofa.rb +1 -1
@@ @@ -7,7 +7,7 @@
'comfortable_mexican_sofa/view_methods',
'comfortable_mexican_sofa/form_builder',
'comfortable_mexican_sofa/acts_as_tree',
- 'comfortable_mexican_sofa/cms_tag',
+ 'comfortable_mexican_sofa/tag',
'comfortable_mexican_sofa/fixtures'
].each do |path|
require File.expand_path(path, File.dirname(__FILE__))
comfortable_mexican_sofa/cms_tag.rb b/lib/comfortable_mexican_sofa/cms_tag.rb +0 -120
@@ @@ -1,120 +0,0 @@
- # This module provides all Tag classes with neccessary methods.
- # Example class that will behave as a Tag:
- # class MySpecialTag
- # include CmsTag
- # ...
- # end
- module ComfortableMexicanSofa::Tag
-
- TOKENIZER_REGEX = /(\{\{\s*cms:[^{}]*\}\})|((?:\{?[^{])+|\{+)/
-
- attr_accessor :params,
- :parent,
- :record_id
-
- module ClassMethods
- # Regex that is used to match tags in the content
- # Example:
- # /\{\{\s*?cms:page:(\w+)\}\}/
- # will match tags like these:
- # {{cms:page:my_label}}
- def regex_tag_signature(label = nil)
- nil
- end
-
- # Initializing tag object for a particular Tag type
- # First capture group in the regex is the tag label
- def initialize_tag(cms_page, tag_signature)
- if match = tag_signature.match(regex_tag_signature)
- if self.respond_to?(:initialize_or_find)
- self.initialize_or_find(cms_page, match[1])
- else
- tag = self.new
- tag.label = match[1]
- tag.params = match[2]
- tag
- end
- end
- end
- end
-
- module InstanceMethods
-
- # String indentifier of the tag
- def identifier
- "#{self.class.to_s.demodulize.underscore}_#{self.label}"
- end
-
- # Ancestors of this tag constructed during rendering process.
- def ancestors
- node, nodes = self, []
- nodes << node = node.parent while node.parent
- nodes
- end
-
- # Regex that is used to identify instance of the tag
- # Example:
- # /<\{\s*?cms:page:tag_label\}/
- def regex_tag_signature
- self.class.regex_tag_signature(label)
- end
-
- # Content that is accociated with Tag instance.
- def content
- nil
- end
-
- # Content that is used during page rendering. Outputting existing content
- # as a default.
- def render
- # cleaning content from possible irb stuff. Partial and Helper tags are OK.
- if !ComfortableMexicanSofa.config.allow_irb &&
- ![ComfortableMexicanSofa::Tag::Partial, ComfortableMexicanSofa::Tag::Helper].member?(self.class)
- content.to_s.gsub('<%', '&lt;%').gsub('%>', '%&gt;')
- else
- content.to_s
- end
- end
- end
-
- private
-
- # Initializes a tag. It's handled by one of the tag classes
- def self.initialize_tag(page, tag_signature)
- tag_instance = nil
- tag_classes.find{ |c| tag_instance = c.initialize_tag(page, tag_signature) }
- tag_instance
- end
-
- # Scanning provided content and splitting it into [tag, text] tuples.
- # Tags are processed further and their content is expanded in the same way.
- # Tags are defined in the parent tags are ignored and not rendered.
- def self.process_content(page, content = '', parent_tag = nil)
- tokens = content.to_s.scan(TOKENIZER_REGEX)
- tokens.collect do |tag_signature, text|
- if tag_signature
- if tag = self.initialize_tag(page, tag_signature)
- tag.parent = parent_tag if parent_tag
- if tag.ancestors.select{|a| a.identifier == tag.identifier}.blank?
- page.tags << tag
- self.process_content(page, tag.render, tag)
- end
- end
- else
- text
- end
- end.join('')
- end
-
- def self.included(tag)
- tag.send(:include, ComfortableMexicanSofa::Tag::InstanceMethods)
- tag.send(:extend, ComfortableMexicanSofa::Tag::ClassMethods)
- @@tag_classes ||= []
- @@tag_classes << tag
- end
-
- # A list of registered Tag classes
- def self.tag_classes
- @@tag_classes ||= []
- end
- end
\ No newline at end of file
comfortable_mexican_sofa/cms_tag/field_datetime.rb b/lib/comfortable_mexican_sofa/cms_tag/field_datetime.rb +0 -21
@@ @@ -1,21 +0,0 @@
- class ComfortableMexicanSofa::Tag::FieldDateTime < Cms::Block
- include ComfortableMexicanSofa::Tag
-
- def self.regex_tag_signature(label = nil)
- label ||= /[\w\-]+/
- /\{\{\s*cms:field:(#{label}):datetime\s*\}\}/
- end
-
- def content=(value)
- write_attribute(:content, value)
- end
-
- def content
- read_attribute(:content)
- end
-
- def render
- ''
- end
-
- end
\ No newline at end of file
comfortable_mexican_sofa/cms_tag/field_integer.rb b/lib/comfortable_mexican_sofa/cms_tag/field_integer.rb +0 -21
@@ @@ -1,21 +0,0 @@
- class ComfortableMexicanSofa::Tag::FieldInteger < Cms::Block
- include ComfortableMexicanSofa::Tag
-
- def self.regex_tag_signature(label = nil)
- label ||= /[\w\-]+/
- /\{\{\s*cms:field:(#{label}):integer\s*\}\}/
- end
-
- def content=(value)
- write_attribute(:content, value)
- end
-
- def content
- read_attribute(:content)
- end
-
- def render
- ''
- end
-
- end
\ No newline at end of file
comfortable_mexican_sofa/cms_tag/field_string.rb b/lib/comfortable_mexican_sofa/cms_tag/field_string.rb +0 -21
@@ @@ -1,21 +0,0 @@
- class ComfortableMexicanSofa::Tag::FieldString < Cms::Block
- include ComfortableMexicanSofa::Tag
-
- def self.regex_tag_signature(label = nil)
- label ||= /[\w\-]+/
- /\{\{\s*cms:field:(#{label}):?(?:string)?\s*\}\}/
- end
-
- def content=(value)
- write_attribute(:content, value)
- end
-
- def content
- read_attribute(:content)
- end
-
- def render
- ''
- end
-
- end
\ No newline at end of file
comfortable_mexican_sofa/cms_tag/field_text.rb b/lib/comfortable_mexican_sofa/cms_tag/field_text.rb +0 -21
@@ @@ -1,21 +0,0 @@
- class ComfortableMexicanSofa::Tag::FieldText < Cms::Block
- include ComfortableMexicanSofa::Tag
-
- def self.regex_tag_signature(label = nil)
- label ||= /[\w\-]+/
- /\{\{\s*cms:field:(#{label}):?(?:text)?\s*?\}\}/
- end
-
- def content=(value)
- write_attribute(:content, value)
- end
-
- def content
- read_attribute(:content)
- end
-
- def render
- ''
- end
-
- end
\ No newline at end of file
comfortable_mexican_sofa/cms_tag/helper.rb b/lib/comfortable_mexican_sofa/cms_tag/helper.rb +0 -15
@@ @@ -1,15 +0,0 @@
- class ComfortableMexicanSofa::Tag::Helper
- include ComfortableMexicanSofa::Tag
-
- attr_accessor :label
-
- def self.regex_tag_signature(label = nil)
- label ||= /[\w\-]+/
- /\{\{\s*cms:helper:(#{label}):?(.*?)\s*\}\}/
- end
-
- def content
- "<%= #{label}(#{params.split(':').collect{|p| "'#{p}'"}.join(', ')}) %>"
- end
-
- end
\ No newline at end of file
comfortable_mexican_sofa/cms_tag/page_datetime.rb b/lib/comfortable_mexican_sofa/cms_tag/page_datetime.rb +0 -17
@@ @@ -1,17 +0,0 @@
- class ComfortableMexicanSofa::Tag::PageDateTime < Cms::Block
- include ComfortableMexicanSofa::Tag
-
- def self.regex_tag_signature(label = nil)
- label ||= /[\w\-]+/
- /\{\{\s*cms:page:(#{label}):datetime\s*\}\}/
- end
-
- def content=(value)
- write_attribute(:content, value)
- end
-
- def content
- read_attribute(:content)
- end
-
- end
\ No newline at end of file
comfortable_mexican_sofa/cms_tag/page_integer.rb b/lib/comfortable_mexican_sofa/cms_tag/page_integer.rb +0 -17
@@ @@ -1,17 +0,0 @@
- class ComfortableMexicanSofa::Tag::PageInteger < Cms::Block
- include ComfortableMexicanSofa::Tag
-
- def self.regex_tag_signature(label = nil)
- label ||= /[\w\-]+/
- /\{\{\s*cms:page:(#{label}):integer\s*\}\}/
- end
-
- def content=(value)
- write_attribute(:content, value)
- end
-
- def content
- read_attribute(:content)
- end
-
- end
\ No newline at end of file
comfortable_mexican_sofa/cms_tag/page_rich_text.rb b/lib/comfortable_mexican_sofa/cms_tag/page_rich_text.rb +0 -17
@@ @@ -1,17 +0,0 @@
- class ComfortableMexicanSofa::Tag::PageRichText < Cms::Block
- include ComfortableMexicanSofa::Tag
-
- def self.regex_tag_signature(label = nil)
- label ||= /[\w\-]+/
- /\{\{\s*cms:page:(#{label}):rich_text\s*\}\}/
- end
-
- def content=(value)
- write_attribute(:content, value)
- end
-
- def content
- read_attribute(:content)
- end
-
- end
\ No newline at end of file
comfortable_mexican_sofa/cms_tag/page_string.rb b/lib/comfortable_mexican_sofa/cms_tag/page_string.rb +0 -17
@@ @@ -1,17 +0,0 @@
- class ComfortableMexicanSofa::Tag::PageString < Cms::Block
- include ComfortableMexicanSofa::Tag
-
- def self.regex_tag_signature(label = nil)
- label ||= /[\w\-]+/
- /\{\{\s*cms:page:(#{label}):string\s*\}\}/
- end
-
- def content=(value)
- write_attribute(:content, value)
- end
-
- def content
- read_attribute(:content)
- end
-
- end
\ No newline at end of file
comfortable_mexican_sofa/cms_tag/page_text.rb b/lib/comfortable_mexican_sofa/cms_tag/page_text.rb +0 -17
@@ @@ -1,17 +0,0 @@
- class ComfortableMexicanSofa::Tag::PageText < Cms::Block
- include ComfortableMexicanSofa::Tag
-
- def self.regex_tag_signature(label = nil)
- label ||= /[\w\-]+/
- /\{\{\s*cms:page:(#{label}):?(?:text)?\s*\}\}/
- end
-
- def content=(value)
- write_attribute(:content, value)
- end
-
- def content
- read_attribute(:content)
- end
-
- end
\ No newline at end of file
comfortable_mexican_sofa/cms_tag/partial.rb b/lib/comfortable_mexican_sofa/cms_tag/partial.rb +0 -16
@@ @@ -1,16 +0,0 @@
- class ComfortableMexicanSofa::Tag::Partial
- include ComfortableMexicanSofa::Tag
-
- attr_accessor :label
-
- def self.regex_tag_signature(label = nil)
- label ||= /[\w\/\-]+/
- /\{\{\s*cms:partial:(#{label}):?(.*?)\s*\}\}/
- end
-
- def content
- ps = params.split(':').collect_with_index{|p, i| ":param_#{i+1} => '#{p}'"}.join(', ')
- "<%= render :partial => '#{label}'#{ps.blank?? nil : ", :locals => {#{ps}}"} %>"
- end
-
- end
\ No newline at end of file
comfortable_mexican_sofa/cms_tag/snippet.rb b/lib/comfortable_mexican_sofa/cms_tag/snippet.rb +0 -17
@@ @@ -1,17 +0,0 @@
- class ComfortableMexicanSofa::Tag::Snippet < Cms::Snippet
- include ComfortableMexicanSofa::Tag
-
- def identifier
- "#{self.class.to_s.demodulize.underscore}_#{self.slug}"
- end
-
- def self.regex_tag_signature(label = nil)
- label ||= /[\w\-]+/
- /\{\{\s*cms:snippet:(#{label})\s*\}\}/
- end
-
- def content
- self.read_attribute(:content)
- end
-
- end
\ No newline at end of file
comfortable_mexican_sofa/engine.rb b/lib/comfortable_mexican_sofa/engine.rb +1 -1
@@ @@ -8,7 +8,7 @@ module ComfortableMexicanSofa
class Engine < ::Rails::Engine
config.after_initialize do
- Dir.glob(File.expand_path('cms_tag/*.rb', File.dirname(__FILE__))).each do |tag_path|
+ Dir.glob(File.expand_path('tags/*.rb', File.dirname(__FILE__))).each do |tag_path|
require tag_path
end
end
comfortable_mexican_sofa/fixtures.rb b/lib/comfortable_mexican_sofa/fixtures.rb +54 -2
@@ @@ -1,7 +1,59 @@
module ComfortableMexicanSofa::Fixtures
- def self.sync!
- raise 'hello'
+ def self.sync
+
+ end
+
+ def self.sync_layouts(site)
+ return unless path = find_path(site, 'layouts')
+
+
+ end
+
+ def self.sync_pages
+
+ end
+
+ def self.sync_snippets(site)
+ return unless path = find_path(site, 'snippets')
+
+ snippet_ids = []
+ Dir.glob("#{path}/*").select{|s| File.directory?(s)}.each do |path|
+ slug = path.split('/').last
+ snippet = site.snippets.find_by_slug(slug) || site.snippets.new(:slug => slug)
+
+ # updating attributes
+ if File.exists?(file_path = File.join(path, "_#{slug}.yml"))
+ if snippet.new_record? || File.mtime(file_path) > snippet.updated_at
+ snippet_attributes = YAML.load_file(file_path).symbolize_keys!
+ snippet.label = snippet_attributes[:label] || slug.titleize
+ end
+ elsif snippet.new_record?
+ snippet.label = slug.titleize
+ end
+
+ # updating content
+ if File.exists?(file_path = File.join(path, "content.html"))
+ if snippet.new_record? || File.mtime(file_path) > snippet.updated_at
+ snippet.content = File.open(file_path, 'rb').read
+ end
+ end
+
+ # saving
+ snippet.save! if snippet.changed?
+ snippet_ids << snippet.id
+ end
+
+ # removing all db entries that are not in fixtures
+ Cms::Snippet.where('id NOT IN (?)', snippet_ids).each{ |s| s.destroy }
+ end
+
+ def self.find_path(site, dir)
+ path = nil
+ File.exists?(path = File.join(ComfortableMexicanSofa.config.fixtures_path, site.hostname, dir)) ||
+ !ComfortableMexicanSofa.config.enable_multiple_sites &&
+ File.exists?(path = File.join(ComfortableMexicanSofa.config.fixtures_path, dir))
+ return path
end
end
\ No newline at end of file
comfortable_mexican_sofa/tag.rb b/lib/comfortable_mexican_sofa/tag.rb +120 -0
@@ @@ -0,0 +1,120 @@
+ # This module provides all Tag classes with neccessary methods.
+ # Example class that will behave as a Tag:
+ # class MySpecialTag
+ # include CmsTag
+ # ...
+ # end
+ module ComfortableMexicanSofa::Tag
+
+ TOKENIZER_REGEX = /(\{\{\s*cms:[^{}]*\}\})|((?:\{?[^{])+|\{+)/
+
+ attr_accessor :params,
+ :parent,
+ :record_id
+
+ module ClassMethods
+ # Regex that is used to match tags in the content
+ # Example:
+ # /\{\{\s*?cms:page:(\w+)\}\}/
+ # will match tags like these:
+ # {{cms:page:my_label}}
+ def regex_tag_signature(label = nil)
+ nil
+ end
+
+ # Initializing tag object for a particular Tag type
+ # First capture group in the regex is the tag label
+ def initialize_tag(cms_page, tag_signature)
+ if match = tag_signature.match(regex_tag_signature)
+ if self.respond_to?(:initialize_or_find)
+ self.initialize_or_find(cms_page, match[1])
+ else
+ tag = self.new
+ tag.label = match[1]
+ tag.params = match[2]
+ tag
+ end
+ end
+ end
+ end
+
+ module InstanceMethods
+
+ # String indentifier of the tag
+ def identifier
+ "#{self.class.to_s.demodulize.underscore}_#{self.label}"
+ end
+
+ # Ancestors of this tag constructed during rendering process.
+ def ancestors
+ node, nodes = self, []
+ nodes << node = node.parent while node.parent
+ nodes
+ end
+
+ # Regex that is used to identify instance of the tag
+ # Example:
+ # /<\{\s*?cms:page:tag_label\}/
+ def regex_tag_signature
+ self.class.regex_tag_signature(label)
+ end
+
+ # Content that is accociated with Tag instance.
+ def content
+ nil
+ end
+
+ # Content that is used during page rendering. Outputting existing content
+ # as a default.
+ def render
+ # cleaning content from possible irb stuff. Partial and Helper tags are OK.
+ if !ComfortableMexicanSofa.config.allow_irb &&
+ ![ComfortableMexicanSofa::Tag::Partial, ComfortableMexicanSofa::Tag::Helper].member?(self.class)
+ content.to_s.gsub('<%', '&lt;%').gsub('%>', '%&gt;')
+ else
+ content.to_s
+ end
+ end
+ end
+
+ private
+
+ # Initializes a tag. It's handled by one of the tag classes
+ def self.initialize_tag(page, tag_signature)
+ tag_instance = nil
+ tag_classes.find{ |c| tag_instance = c.initialize_tag(page, tag_signature) }
+ tag_instance
+ end
+
+ # Scanning provided content and splitting it into [tag, text] tuples.
+ # Tags are processed further and their content is expanded in the same way.
+ # Tags are defined in the parent tags are ignored and not rendered.
+ def self.process_content(page, content = '', parent_tag = nil)
+ tokens = content.to_s.scan(TOKENIZER_REGEX)
+ tokens.collect do |tag_signature, text|
+ if tag_signature
+ if tag = self.initialize_tag(page, tag_signature)
+ tag.parent = parent_tag if parent_tag
+ if tag.ancestors.select{|a| a.identifier == tag.identifier}.blank?
+ page.tags << tag
+ self.process_content(page, tag.render, tag)
+ end
+ end
+ else
+ text
+ end
+ end.join('')
+ end
+
+ def self.included(tag)
+ tag.send(:include, ComfortableMexicanSofa::Tag::InstanceMethods)
+ tag.send(:extend, ComfortableMexicanSofa::Tag::ClassMethods)
+ @@tag_classes ||= []
+ @@tag_classes << tag
+ end
+
+ # A list of registered Tag classes
+ def self.tag_classes
+ @@tag_classes ||= []
+ end
+ end
\ No newline at end of file
test/integration/fixtures_test.rb +0 -58
@@ @@ -1,58 +0,0 @@
- require File.expand_path('../test_helper', File.dirname(__FILE__))
-
- class FixturesTest < ActionDispatch::IntegrationTest
-
- def test_inactivity
- assert_equal false, ComfortableMexicanSofa.config.enable_fixtures
- assert_no_difference ['Cms::Layout.count', 'Cms::Page.count', 'Cms::Block.count', 'Cms::Snippet.count'] do
- get '/'
- assert_response :success
- end
- end
-
- def test_initialization
- ComfortableMexicanSofa.config.enable_fixtures = true
- get '/'
- end
-
- def test_layout_file_update
- flunk
- end
-
- def test_page_file_update
- flunk
- end
-
- def test_snippet_file_update
- flunk
- end
-
- def test_layout_file_removal
- flunk
- end
-
- def test_page_file_removal
- flunk
- end
-
- def test_snippet_file_removal
- flunk
- end
-
- def test_layout_creation_failure
- flunk
- end
-
- def test_page_creation_failure
- flunk
- end
-
- def test_snippet_creation_failure
- flunk
- end
-
- def test_single_site_path_option
- flunk
- end
-
- end
\ No newline at end of file
test/unit/cms_configuration_test.rb +0 -23
@@ @@ -1,23 +0,0 @@
- require File.expand_path('../test_helper', File.dirname(__FILE__))
-
- class CmsConfigurationTest < ActiveSupport::TestCase
-
- def test_configuration_presense
- assert config = ComfortableMexicanSofa.configuration
- assert_equal 'ComfortableMexicanSofa MicroCMS', config.cms_title
- assert_equal 'ComfortableMexicanSofa::HttpAuth', config.authentication
- assert_equal 'cms-admin', config.admin_route_prefix
- assert_equal '/cms-admin/pages', config.admin_route_redirect
- assert_equal false, config.enable_multiple_sites
- assert_equal false, config.allow_irb
- assert_equal true, config.enable_caching
- assert_equal false, config.enable_fixtures
- assert_equal File.expand_path('db/cms_fixtures', Rails.root), config.fixtures_path
- end
-
- def test_initialization_overrides
- ComfortableMexicanSofa.configuration.cms_title = 'New Title'
- assert_equal 'New Title', ComfortableMexicanSofa.configuration.cms_title
- end
-
- end
\ No newline at end of file
test/unit/cms_tag_test.rb +0 -206
@@ @@ -1,206 +0,0 @@
- require File.expand_path('../test_helper', File.dirname(__FILE__))
-
- class CmsTagTest < ActiveSupport::TestCase
-
- def test_tokenizer_regex
- regex = ComfortableMexicanSofa::Tag::TOKENIZER_REGEX
-
- tokens = 'text { text } text'.scan(regex)
- assert_equal nil, tokens[0][0]
- assert_equal 'text { text } text', tokens[0][1]
-
- tokens = 'content<{{cms:some_tag content'.scan(regex)
- assert_equal nil, tokens[0][0]
- assert_equal 'content<', tokens[0][1]
- assert_equal nil, tokens[1][0]
- assert_equal '{{', tokens[1][1]
- assert_equal nil, tokens[2][0]
- assert_equal 'cms:some_tag content', tokens[2][1]
-
- tokens = 'content<{{cms some_tag}}>content'.scan(regex)
- assert_equal nil, tokens[0][0]
- assert_equal 'content<', tokens[0][1]
- assert_equal nil, tokens[1][0]
- assert_equal '{{', tokens[1][1]
- assert_equal nil, tokens[2][0]
- assert_equal 'cms some_tag}}>content',tokens[2][1]
-
- tokens = 'content<{{cms:some_tag}}>content'.scan(regex)
- assert_equal nil, tokens[0][0]
- assert_equal 'content<', tokens[0][1]
- assert_equal '{{cms:some_tag}}', tokens[1][0]
- assert_equal nil, tokens[1][1]
- assert_equal nil, tokens[2][0]
- assert_equal '>content', tokens[2][1]
-
- tokens = 'content<{{cms:type:label}}>content'.scan(regex)
- assert_equal nil, tokens[0][0]
- assert_equal 'content<', tokens[0][1]
- assert_equal '{{cms:type:label}}', tokens[1][0]
- assert_equal nil, tokens[1][1]
- assert_equal nil, tokens[2][0]
- assert_equal '>content', tokens[2][1]
-
- tokens = 'content<{{cms:type:label }}>content'.scan(regex)
- assert_equal nil, tokens[0][0]
- assert_equal 'content<', tokens[0][1]
- assert_equal '{{cms:type:label }}', tokens[1][0]
- assert_equal nil, tokens[1][1]
- assert_equal nil, tokens[2][0]
- assert_equal '>content', tokens[2][1]
-
- tokens = 'content<{{ cms:type:la/b el }}>content'.scan(regex)
- assert_equal nil, tokens[0][0]
- assert_equal 'content<', tokens[0][1]
- assert_equal '{{ cms:type:la/b el }}',tokens[1][0]
- assert_equal nil, tokens[1][1]
- assert_equal nil, tokens[2][0]
- assert_equal '>content', tokens[2][1]
- end
-
- def test_tokenizer_regex_limit
- string = '<p>text</p>' * 400
- tokens = string.scan(ComfortableMexicanSofa::Tag::TOKENIZER_REGEX)
- assert_equal 1, tokens.count
- assert_equal nil, tokens[0][0]
- assert_equal string, tokens[0][1]
- end
-
- def test_content_for_existing_page
- page = cms_pages(:default)
- assert page.tags.blank?
- assert_equal rendered_content_formatter(
- '
- layout_content_a
- default_page_text_content_a
- default_snippet_content
- default_page_text_content_b
- layout_content_b
- default_snippet_content
- layout_content_c'
- ), page.content(true)
-
- assert_equal 4, page.tags.size
- assert_equal 'field_text_default_field_text', page.tags[0].identifier
- assert_equal 'page_text_default_page_text', page.tags[1].identifier
- assert_equal 'snippet_default', page.tags[2].identifier
- assert_equal page.tags[1], page.tags[2].parent
- assert_equal 'snippet_default', page.tags[3].identifier
- end
-
- def test_content_for_new_page
- page = Cms::Page.new
- assert page.blocks.blank?
- assert page.tags.blank?
- assert_equal '', page.content
- assert page.tags.blank?
- end
-
- def test_content_for_new_page_with_layout
- page = cms_sites(:default).pages.new(:layout => cms_layouts(:default))
- assert page.blocks.blank?
- assert page.tags.blank?
- assert_equal rendered_content_formatter(
- '
- layout_content_a
-
- layout_content_b
- default_snippet_content
- layout_content_c'
- ), page.content
-
- assert_equal 3, page.tags.size
- assert_equal 'field_text_default_field_text', page.tags[0].identifier
- assert_equal 'page_text_default_page_text', page.tags[1].identifier
- assert_equal 'snippet_default', page.tags[2].identifier
- end
-
- def test_content_for_new_page_with_initilized_cms_blocks
- page = cms_sites(:default).pages.new(:layout => cms_layouts(:default))
- assert page.blocks.blank?
- assert page.tags.blank?
- page.blocks_attributes = [
- {
- :label => 'default_field_text',
- :content => 'new_default_field_content',
- :type => 'CmsTag::FieldText'
- },
- {
- :label => 'default_page_text',
- :content => "new_default_page_text_content\n{{cms:snippet:default}}",
- :type => 'CmsTag::PageText'
- },
- {
- :label => 'bogus_field_that_never_will_get_rendered',
- :content => 'some_content_that_doesnot_matter',
- :type => 'CmsTag::PageText'
- }
- ]
- assert_equal 3, page.blocks.size
-
- assert_equal rendered_content_formatter(
- '
- layout_content_a
- new_default_page_text_content
- default_snippet_content
- layout_content_b
- default_snippet_content
- layout_content_c'
- ), page.content
-
- assert_equal 4, page.tags.size
- assert_equal 'field_text_default_field_text', page.tags[0].identifier
- assert_equal 'page_text_default_page_text', page.tags[1].identifier
- assert_equal 'snippet_default', page.tags[2].identifier
- assert_equal page.tags[1], page.tags[2].parent
- assert_equal 'snippet_default', page.tags[3].identifier
- end
-
- def test_content_with_repeated_tags
- page = cms_pages(:default)
- page.layout.content << "\n{{cms:page:default_page_text:text}}"
- page.layout.save!
-
- assert_equal rendered_content_formatter(
- '
- layout_content_a
- default_page_text_content_a
- default_snippet_content
- default_page_text_content_b
- layout_content_b
- default_snippet_content
- layout_content_c
- default_page_text_content_a
- default_snippet_content
- default_page_text_content_b'
- ), page.content(true)
-
- assert_equal 6, page.tags.size
- assert_equal 'field_text_default_field_text', page.tags[0].identifier
- assert_equal 'page_text_default_page_text', page.tags[1].identifier
- assert_equal 'snippet_default', page.tags[2].identifier
- assert_equal page.tags[1], page.tags[2].parent
- assert_equal 'snippet_default', page.tags[3].identifier
- assert_equal 'page_text_default_page_text', page.tags[4].identifier
- assert_equal 'snippet_default', page.tags[5].identifier
- assert_equal page.tags[4], page.tags[5].parent
- end
-
- def test_content_with_cyclical_tags
- page = cms_pages(:default)
- snippet = cms_snippets(:default)
- snippet.update_attribute(:content, "infinite {{cms:page:default}} loop")
- assert_equal rendered_content_formatter(
- '
- layout_content_a
- default_page_text_content_a
- infinite loop
- default_page_text_content_b
- layout_content_b
- infinite loop
- layout_content_c'
- ), page.content(true)
- assert_equal 6, page.tags.size
- end
-
- end
test/unit/cms_tags/field_datetime_test.rb +0 -44
@@ @@ -1,44 +0,0 @@
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
-
- class FieldDateTimeTest < ActiveSupport::TestCase
-
- def test_initialize_tag
- assert tag = ComfortableMexicanSofa::Tag::FieldDateTime.initialize_tag(
- cms_pages(:default), '{{ cms:field:content:datetime }}'
- )
- assert_equal 'content', tag.label
- assert tag = ComfortableMexicanSofa::Tag::FieldDateTime.initialize_tag(
- cms_pages(:default), '{{cms:field:content:datetime}}'
- )
- assert_equal 'content', tag.label
- assert tag = ComfortableMexicanSofa::Tag::FieldDateTime.initialize_tag(
- cms_pages(:default), '{{cms:field:dash-content:datetime}}'
- )
- assert_equal 'dash-content', tag.label
- end
-
- def test_initialize_tag_failure
- [
- '{{cms:field:content:not_datetime}}',
- '{{cms:field:content}}',
- '{{cms:not_field:content}}',
- '{not_a_tag}'
- ].each do |tag_signature|
- assert_nil ComfortableMexicanSofa::Tag::FieldDateTime.initialize_tag(
- cms_pages(:default), tag_signature
- )
- end
- end
-
- def test_content_and_render
- tag = ComfortableMexicanSofa::Tag::FieldDateTime.initialize_tag(
- cms_pages(:default), '{{cms:field:content:datetime}}'
- )
- assert tag.content.blank?
- time = 2.days.ago
- tag.content = time
- assert_equal time, tag.content
- assert_equal '', tag.render
- end
-
- end
\ No newline at end of file
test/unit/cms_tags/field_integer_test.rb +0 -43
@@ @@ -1,43 +0,0 @@
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
-
- class FieldIntegerTest < ActiveSupport::TestCase
-
- def test_initialize_tag
- assert tag = ComfortableMexicanSofa::Tag::FieldInteger.initialize_tag(
- cms_pages(:default), '{{ cms:field:content:integer }}'
- )
- assert_equal 'content', tag.label
- assert tag = ComfortableMexicanSofa::Tag::FieldInteger.initialize_tag(
- cms_pages(:default), '{{cms:field:content:integer}}'
- )
- assert_equal 'content', tag.label
- assert tag = ComfortableMexicanSofa::Tag::FieldInteger.initialize_tag(
- cms_pages(:default), '{{cms:field:dash-content:integer}}'
- )
- assert_equal 'dash-content', tag.label
- end
-
- def test_initialize_tag_failure
- [
- '{{cms:field:content:not_integer}}',
- '{{cms:field:content}}',
- '{{cms:not_field:content}}',
- '{not_a_tag}'
- ].each do |tag_signature|
- assert_nil ComfortableMexicanSofa::Tag::FieldInteger.initialize_tag(
- cms_pages(:default), tag_signature
- )
- end
- end
-
- def test_content_and_render
- tag = ComfortableMexicanSofa::Tag::FieldInteger.initialize_tag(
- cms_pages(:default), '{{cms:field:content:integer}}'
- )
- assert tag.content.blank?
- tag.content = '5'
- assert_equal '5', tag.content
- assert_equal '', tag.render
- end
-
- end
\ No newline at end of file
test/unit/cms_tags/field_string_test.rb +0 -46
@@ @@ -1,46 +0,0 @@
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
-
- class FieldStringTest < ActiveSupport::TestCase
-
- def test_initialize_tag
- assert tag = ComfortableMexicanSofa::Tag::FieldString.initialize_tag(
- cms_pages(:default), '{{ cms:field:content:string }}'
- )
- assert_equal 'content', tag.label
- assert tag = ComfortableMexicanSofa::Tag::FieldString.initialize_tag(
- cms_pages(:default), '{{cms:field:content:string}}'
- )
- assert_equal 'content', tag.label
- assert tag = ComfortableMexicanSofa::Tag::FieldString.initialize_tag(
- cms_pages(:default), '{{cms:field:content}}'
- )
- assert_equal 'content', tag.label
- assert tag = ComfortableMexicanSofa::Tag::FieldString.initialize_tag(
- cms_pages(:default), '{{cms:field:dash-content}}'
- )
- assert_equal 'dash-content', tag.label
- end
-
- def test_initialize_tag_failure
- [
- '{{cms:field:content:not_string}}',
- '{{cms:not_field:content}}',
- '{not_a_tag}'
- ].each do |tag_signature|
- assert_nil ComfortableMexicanSofa::Tag::FieldString.initialize_tag(
- cms_pages(:default), tag_signature
- )
- end
- end
-
- def test_content_and_render
- tag = ComfortableMexicanSofa::Tag::FieldString.initialize_tag(
- cms_pages(:default), '{{cms:field:content}}'
- )
- assert tag.content.blank?
- tag.content = 'test_content'
- assert_equal 'test_content', tag.content
- assert_equal '', tag.render
- end
-
- end
\ No newline at end of file
test/unit/cms_tags/field_text_test.rb +0 -42
@@ @@ -1,42 +0,0 @@
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
-
- class FieldTextTest < ActiveSupport::TestCase
-
- def test_initialize_tag
- assert tag = ComfortableMexicanSofa::Tag::FieldText.initialize_tag(
- cms_pages(:default), '{{ cms:field:content:text }}'
- )
- assert_equal 'content', tag.label
- assert tag = ComfortableMexicanSofa::Tag::FieldText.initialize_tag(
- cms_pages(:default), '{{cms:field:content:text}}'
- )
- assert_equal 'content', tag.label
- assert tag = ComfortableMexicanSofa::Tag::FieldText.initialize_tag(
- cms_pages(:default), '{{cms:field:dash-content:text}}'
- )
- assert_equal 'dash-content', tag.label
- end
-
- def test_initialize_tag_failure
- [
- '{{cms:field:content:not_text}}',
- '{{cms:not_field:content:text}}',
- '{not_a_tag}'
- ].each do |tag_signature|
- assert_nil ComfortableMexicanSofa::Tag::FieldText.initialize_tag(
- cms_pages(:default), tag_signature
- )
- end
- end
-
- def test_content_and_render
- tag = ComfortableMexicanSofa::Tag::FieldText.initialize_tag(
- cms_pages(:default), '{{cms:field:content:text}}'
- )
- assert tag.content.blank?
- tag.content = 'test_content'
- assert_equal 'test_content', tag.content
- assert_equal '', tag.render
- end
-
- end
\ No newline at end of file
test/unit/cms_tags/helper_test.rb +0 -50
@@ @@ -1,50 +0,0 @@
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
-
- class HelperTest < ActiveSupport::TestCase
-
- def test_initialize_tag
- assert tag = ComfortableMexicanSofa::Tag::Helper.initialize_tag(
- cms_pages(:default), '{{ cms:helper:method_name }}'
- )
- assert_equal 'method_name', tag.label
- assert tag = ComfortableMexicanSofa::Tag::Helper.initialize_tag(
- cms_pages(:default), '{{ cms:helper:method-name }}'
- )
- assert_equal 'method-name', tag.label
- end
-
- def test_initialize_tag_with_parameters
- assert tag = ComfortableMexicanSofa::Tag::Helper.initialize_tag(
- cms_pages(:default), '{{ cms:helper:method_name:param1:param2 }}'
- )
- assert tag.label = 'method_name'
- assert tag.params = 'param1:param2'
- end
-
- def test_initialize_tag_failure
- [
- '{{cms:helper}}',
- '{{cms:not_helper:method_name}}',
- '{not_a_tag}'
- ].each do |tag_signature|
- assert_nil ComfortableMexicanSofa::Tag::Helper.initialize_tag(
- cms_pages(:default), tag_signature
- )
- end
- end
-
- def test_content_and_render
- tag = ComfortableMexicanSofa::Tag::Helper.initialize_tag(
- cms_pages(:default), '{{cms:helper:method_name}}'
- )
- assert_equal "<%= method_name() %>", tag.content
- assert_equal "<%= method_name() %>", tag.render
-
- tag = ComfortableMexicanSofa::Tag::Helper.initialize_tag(
- cms_pages(:default), '{{cms:helper:method_name:param1:param2}}'
- )
- assert_equal "<%= method_name('param1', 'param2') %>", tag.content
- assert_equal "<%= method_name('param1', 'param2') %>", tag.render
- end
-
- end
\ No newline at end of file
test/unit/cms_tags/page_datetime_test.rb +0 -44
@@ @@ -1,44 +0,0 @@
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
-
- class PageDateTimeTest < ActiveSupport::TestCase
-
- def test_initialize_tag
- assert tag = ComfortableMexicanSofa::Tag::PageDateTime.initialize_tag(
- cms_pages(:default), '{{ cms:page:content:datetime }}'
- )
- assert_equal 'content', tag.label
- assert tag = ComfortableMexicanSofa::Tag::PageDateTime.initialize_tag(
- cms_pages(:default), '{{cms:page:content:datetime}}'
- )
- assert_equal 'content', tag.label
- assert tag = ComfortableMexicanSofa::Tag::PageDateTime.initialize_tag(
- cms_pages(:default), '{{cms:page:dash-content:datetime}}'
- )
- assert_equal 'dash-content', tag.label
- end
-
- def test_initialize_tag_failure
- [
- '{{cms:page:content:not_datetime}}',
- '{{cms:page:content}}',
- '{{cms:not_page:content}}',
- '{not_a_tag}'
- ].each do |tag_signature|
- assert_nil ComfortableMexicanSofa::Tag::PageDateTime.initialize_tag(
- cms_pages(:default), tag_signature
- )
- end
- end
-
- def test_content_and_render
- tag = ComfortableMexicanSofa::Tag::PageDateTime.initialize_tag(
- cms_pages(:default), '{{cms:page:content:datetime}}'
- )
- assert tag.content.blank?
- time = 2.days.ago
- tag.content = time
- assert_equal time, tag.content
- assert_equal time.to_s, tag.render
- end
-
- end
\ No newline at end of file
test/unit/cms_tags/page_integer_test.rb +0 -43
@@ @@ -1,43 +0,0 @@
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
-
- class PageIntegerTest < ActiveSupport::TestCase
-
- def test_initialize_tag
- assert tag = ComfortableMexicanSofa::Tag::PageInteger.initialize_tag(
- cms_pages(:default), '{{ cms:page:content:integer }}'
- )
- assert_equal 'content', tag.label
- assert tag = ComfortableMexicanSofa::Tag::PageInteger.initialize_tag(
- cms_pages(:default), '{{cms:page:content:integer}}'
- )
- assert_equal 'content', tag.label
- assert tag = ComfortableMexicanSofa::Tag::PageInteger.initialize_tag(
- cms_pages(:default), '{{cms:page:dash-content:integer}}'
- )
- assert_equal 'dash-content', tag.label
- end
-
- def test_initialize_tag_failure
- [
- '{{cms:page:content:not_integer}}',
- '{{cms:page:content}}',
- '{{cms:not_page:content}}',
- '{not_a_tag}'
- ].each do |tag_signature|
- assert_nil ComfortableMexicanSofa::Tag::PageInteger.initialize_tag(
- cms_pages(:default), tag_signature
- )
- end
- end
-
- def test_content_and_render
- tag = ComfortableMexicanSofa::Tag::PageInteger.initialize_tag(
- cms_pages(:default), '{{cms:page:content:integer}}'
- )
- assert tag.content.blank?
- tag.content = '5'
- assert_equal '5', tag.content
- assert_equal '5', tag.render
- end
-
- end
\ No newline at end of file
test/unit/cms_tags/page_rich_text.rb +0 -43
@@ @@ -1,43 +0,0 @@
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
-
- class PageRichTextTest < ActiveSupport::TestCase
-
- def test_initialize_tag
- assert tag = ComfortableMexicanSofa::Tag::PageRichText.initialize_tag(
- cms_pages(:default), '{{ cms:page:content:rich_text }}'
- )
- assert_equal 'content', tag.label
- assert tag = ComfortableMexicanSofa::Tag::PageRichText.initialize_tag(
- cms_pages(:default), '{{cms:page:content:rich_text}}'
- )
- assert_equal 'content', tag.label
- assert tag = ComfortableMexicanSofa::Tag::PageRichText.initialize_tag(
- cms_pages(:default), '{{cms:page:dash-content:rich_text}}'
- )
- assert_equal 'dash-content', tag.label
- end
-
- def test_initialize_tag_failure
- [
- '{{cms:page:content:not_rich_text}}',
- '{{cms:page:content}}',
- '{{cms:not_page:content}}',
- '{not_a_tag}'
- ].each do |tag_signature|
- assert_nil ComfortableMexicanSofa::Tag::PageRichText.initialize_tag(
- cms_pages(:default), tag_signature
- )
- end
- end
-
- def test_content_and_render
- tag = ComfortableMexicanSofa::Tag::PageRichText.initialize_tag(
- cms_pages(:default), '{{cms:page:content:rich_text}}'
- )
- assert tag.content.blank?
- tag.content = 'test_content'
- assert_equal 'test_content', tag.content
- assert_equal 'test_content', tag.render
- end
-
- end
\ No newline at end of file
test/unit/cms_tags/page_string_test.rb +0 -43
@@ @@ -1,43 +0,0 @@
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
-
- class PageStringTest < ActiveSupport::TestCase
-
- def test_initialize_tag
- assert tag = ComfortableMexicanSofa::Tag::PageString.initialize_tag(
- cms_pages(:default), '{{ cms:page:content:string }}'
- )
- assert_equal 'content', tag.label
- assert tag = ComfortableMexicanSofa::Tag::PageString.initialize_tag(
- cms_pages(:default), '{{cms:page:content:string}}'
- )
- assert_equal 'content', tag.label
- assert tag = ComfortableMexicanSofa::Tag::PageString.initialize_tag(
- cms_pages(:default), '{{cms:page:dash-content:string}}'
- )
- assert_equal 'dash-content', tag.label
- end
-
- def test_initialize_tag_failure
- [
- '{{cms:page:content:not_string}}',
- '{{cms:page:content}}',
- '{{cms:not_page:content}}',
- '{not_a_tag}'
- ].each do |tag_signature|
- assert_nil ComfortableMexicanSofa::Tag::PageString.initialize_tag(
- cms_pages(:default), tag_signature
- )
- end
- end
-
- def test_content_and_render
- tag = ComfortableMexicanSofa::Tag::PageString.initialize_tag(
- cms_pages(:default), '{{cms:page:content:string}}'
- )
- assert tag.content.blank?
- tag.content = 'test_content'
- assert_equal 'test_content', tag.content
- assert_equal 'test_content', tag.render
- end
-
- end
\ No newline at end of file
test/unit/cms_tags/page_text_test.rb +0 -46
@@ @@ -1,46 +0,0 @@
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
-
- class PageTextTest < ActiveSupport::TestCase
-
- def test_initialize_tag
- assert tag = ComfortableMexicanSofa::Tag::PageText.initialize_tag(
- cms_pages(:default), '{{ cms:page:content:text }}'
- )
- assert_equal 'content', tag.label
- assert tag = ComfortableMexicanSofa::Tag::PageText.initialize_tag(
- cms_pages(:default), '{{cms:page:content}}'
- )
- assert_equal 'content', tag.label
- assert tag = ComfortableMexicanSofa::Tag::PageText.initialize_tag(
- cms_pages(:default), '{{cms:page:content:text}}'
- )
- assert_equal 'content', tag.label
- assert tag = ComfortableMexicanSofa::Tag::PageText.initialize_tag(
- cms_pages(:default), '{{cms:page:dash-content}}'
- )
- assert_equal 'dash-content', tag.label
- end
-
- def test_initialize_tag_failure
- [
- '{{cms:page:content:not_text}}',
- '{{cms:not_page:content}}',
- '{not_a_tag}'
- ].each do |tag_signature|
- assert_nil ComfortableMexicanSofa::Tag::PageText.initialize_tag(
- cms_pages(:default), tag_signature
- )
- end
- end
-
- def test_content_and_render
- tag = ComfortableMexicanSofa::Tag::PageText.initialize_tag(
- cms_pages(:default), '{{cms:page:content}}'
- )
- assert tag.content.blank?
- tag.content = 'test_content'
- assert_equal 'test_content', tag.content
- assert_equal 'test_content', tag.render
- end
-
- end
\ No newline at end of file
test/unit/cms_tags/partial_test.rb +0 -60
@@ @@ -1,60 +0,0 @@
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
-
- class PartialTest < ActiveSupport::TestCase
-
- def test_initialize_tag
- assert tag = ComfortableMexicanSofa::Tag::Partial.initialize_tag(
- cms_pages(:default), '{{ cms:partial:partial_name }}'
- )
- assert_equal 'partial_name', tag.label
- assert tag = ComfortableMexicanSofa::Tag::Partial.initialize_tag(
- cms_pages(:default), '{{cms:partial:path/to/partial}}'
- )
- assert_equal 'path/to/partial', tag.label
- assert tag = ComfortableMexicanSofa::Tag::Partial.initialize_tag(
- cms_pages(:default), '{{cms:partial:path/to/dashed-partial}}'
- )
- assert_equal 'path/to/dashed-partial', tag.label
- end
-
- def test_initialize_tag_with_parameters
- assert tag = ComfortableMexicanSofa::Tag::Partial.initialize_tag(
- cms_pages(:default), '{{cms:partial:path/to/partial:param1:param2}}'
- )
- assert tag.label = 'path/to/partial'
- assert tag.params = 'param1:param2'
- end
-
- def test_initialize_tag_failure
- [
- '{{cms:partial}}',
- '{{cms:not_partial:label}}',
- '{not_a_tag}'
- ].each do |tag_signature|
- assert_nil ComfortableMexicanSofa::Tag::Partial.initialize_tag(
- cms_pages(:default), tag_signature
- )
- end
- end
-
- def test_content_and_render
- tag = ComfortableMexicanSofa::Tag::Partial.initialize_tag(
- cms_pages(:default), '{{cms:partial:path/to/partial}}'
- )
- assert_equal "<%= render :partial => 'path/to/partial' %>", tag.content
- assert_equal "<%= render :partial => 'path/to/partial' %>", tag.render
-
- tag = ComfortableMexicanSofa::Tag::Partial.initialize_tag(
- cms_pages(:default), '{{cms:partial:path/to/partial:param1}}'
- )
- assert_equal "<%= render :partial => 'path/to/partial', :locals => {:param_1 => 'param1'} %>", tag.content
- assert_equal "<%= render :partial => 'path/to/partial', :locals => {:param_1 => 'param1'} %>", tag.render
-
- tag = ComfortableMexicanSofa::Tag::Partial.initialize_tag(
- cms_pages(:default), '{{cms:partial:path/to/partial:param1:param2}}'
- )
- assert_equal "<%= render :partial => 'path/to/partial', :locals => {:param_1 => 'param1', :param_2 => 'param2'} %>", tag.content
- assert_equal "<%= render :partial => 'path/to/partial', :locals => {:param_1 => 'param1', :param_2 => 'param2'} %>", tag.render
- end
-
- end
\ No newline at end of file
test/unit/cms_tags/snippet_test.rb +0 -45
@@ @@ -1,45 +0,0 @@
- require File.expand_path('../../test_helper', File.dirname(__FILE__))
-
- class SnippetTest < ActiveSupport::TestCase
-
- def test_initialize_tag
- assert tag = ComfortableMexicanSofa::Tag::Snippet.initialize_tag(
- cms_pages(:default), '{{ cms:snippet:label }}'
- )
- assert_equal 'label', tag.slug
- assert tag = ComfortableMexicanSofa::Tag::Snippet.initialize_tag(
- cms_pages(:default), '{{cms:snippet:label}}'
- )
- assert_equal 'label', tag.slug
- assert tag = ComfortableMexicanSofa::Tag::Snippet.initialize_tag(
- cms_pages(:default), '{{cms:snippet:dash-label}}'
- )
- assert_equal 'dash-label', tag.slug
- end
-
- def test_initialize_tag_failure
- [
- '{{cms:snippet}}',
- '{{cms:not_snippet:label}}',
- '{not_a_tag}'
- ].each do |tag_signature|
- assert_nil ComfortableMexicanSofa::Tag::Snippet.initialize_tag(
- cms_pages(:default), tag_signature
- )
- end
- end
-
- def test_content_and_render
- tag = ComfortableMexicanSofa::Tag::Snippet.initialize_tag(
- cms_pages(:default), '{{cms:snippet:default}}'
- )
- assert_equal 'default_snippet_content', tag.content
- assert_equal 'default_snippet_content', tag.render
-
- tag = ComfortableMexicanSofa::Tag::Snippet.initialize_tag(
- cms_pages(:default), "{{cms:snippet:doesnot_exist}}"
- )
- assert_equal nil, tag.content
- assert_equal '', tag.render
- end
- end
\ No newline at end of file
test/unit/configuration_test.rb +23 -0
@@ @@ -0,0 +1,23 @@
+ require File.expand_path('../test_helper', File.dirname(__FILE__))
+
+ class ConfigurationTest < ActiveSupport::TestCase
+
+ def test_configuration_presense
+ assert config = ComfortableMexicanSofa.configuration
+ assert_equal 'ComfortableMexicanSofa MicroCMS', config.cms_title
+ assert_equal 'ComfortableMexicanSofa::HttpAuth', config.authentication
+ assert_equal 'cms-admin', config.admin_route_prefix
+ assert_equal '/cms-admin/pages', config.admin_route_redirect
+ assert_equal false, config.enable_multiple_sites
+ assert_equal false, config.allow_irb
+ assert_equal true, config.enable_caching
+ assert_equal false, config.enable_fixtures
+ assert_equal File.expand_path('db/cms_fixtures', Rails.root), config.fixtures_path
+ end
+
+ def test_initialization_overrides
+ ComfortableMexicanSofa.configuration.cms_title = 'New Title'
+ assert_equal 'New Title', ComfortableMexicanSofa.configuration.cms_title
+ end
+
+ end
\ No newline at end of file
test/unit/fixtures_test.rb +101 -0
@@ @@ -0,0 +1,101 @@
+ require File.expand_path('../test_helper', File.dirname(__FILE__))
+
+ class ViewMethodsTest < ActiveSupport::TestCase
+
+ def setup
+ @site = cms_sites(:default)
+ @site.update_attribute(:hostname, 'example.com')
+ end
+
+ def test_sync_layouts_creating
+ ComfortableMexicanSofa::Fixtures.sync_layouts(@site)
+ end
+
+ def test_sync_layouts_updating
+ flunk
+ end
+
+ def test_sync_layouts_deleting
+ flunk
+ end
+
+ def test_sync_layouts_ignoring
+ flunk
+ end
+
+ def test_sync_pages_creating
+ flunk
+ end
+
+ def test_sync_pages_updating
+ flunk
+ end
+
+ def test_sync_pages_deleting
+ flunk
+ end
+
+ def test_sync_pages_ignoring
+ flunk
+ end
+
+ def test_sync_snippets_creating
+ Cms::Snippet.delete_all
+
+ assert_difference 'Cms::Snippet.count' do
+ ComfortableMexicanSofa::Fixtures.sync_snippets(@site)
+ assert snippet = Cms::Snippet.last
+ assert_equal 'default', snippet.slug
+ assert_equal 'Default Fixture Snippet', snippet.label
+ assert_equal 'Fixture Content for Default Snippet', snippet.content
+ end
+ end
+
+ def test_sync_snippets_updating
+ snippet = cms_snippets(:default)
+ snippet.update_attribute(:updated_at, 10.years.ago)
+ assert_equal 'default', snippet.slug
+ assert_equal 'Default Snippet', snippet.label
+ assert_equal 'default_snippet_content', snippet.content
+
+ assert_no_difference 'Cms::Snippet.count' do
+ ComfortableMexicanSofa::Fixtures.sync_snippets(@site)
+ snippet.reload
+ assert_equal 'default', snippet.slug
+ assert_equal 'Default Fixture Snippet', snippet.label
+ assert_equal 'Fixture Content for Default Snippet', snippet.content
+ end
+ end
+
+ def test_sync_snippets_deleting
+ snippet = cms_snippets(:default)
+ snippet.update_attribute(:slug, 'old')
+
+ assert_no_difference 'Cms::Snippet.count' do
+ ComfortableMexicanSofa::Fixtures.sync_snippets(@site)
+ assert snippet = Cms::Snippet.last
+ assert_equal 'default', snippet.slug
+ assert_equal 'Default Fixture Snippet', snippet.label
+ assert_equal 'Fixture Content for Default Snippet', snippet.content
+
+ assert_nil Cms::Snippet.find_by_slug('old')
+ end
+ end
+
+ def test_sync_snippets_ignoring
+ snippet = cms_snippets(:default)
+ snippet_path = File.join(ComfortableMexicanSofa.config.fixtures_path, @site.hostname, 'snippets', 'default')
+ attr_file_path = File.join(snippet_path, '_default.yml')
+ content_file_path = File.join(snippet_path, 'content.html')
+
+ assert snippet.updated_at >= File.mtime(attr_file_path)
+ assert snippet.updated_at >= File.mtime(content_file_path)
+
+ ComfortableMexicanSofa::Fixtures.sync_snippets(@site)
+ snippet.reload
+ assert_equal 'default', snippet.slug
+ assert_equal 'Default Snippet', snippet.label
+ assert_equal 'default_snippet_content', snippet.content
+ end
+
+ end
\ No newline at end of file
test/unit/tag_test.rb +206 -0
@@ @@ -0,0 +1,206 @@
+ require File.expand_path('../test_helper', File.dirname(__FILE__))
+
+ class TagTest < ActiveSupport::TestCase
+
+ def test_tokenizer_regex
+ regex = ComfortableMexicanSofa::Tag::TOKENIZER_REGEX
+
+ tokens = 'text { text } text'.scan(regex)
+ assert_equal nil, tokens[0][0]
+ assert_equal 'text { text } text', tokens[0][1]
+
+ tokens = 'content<{{cms:some_tag content'.scan(regex)
+ assert_equal nil, tokens[0][0]
+ assert_equal 'content<', tokens[0][1]
+ assert_equal nil, tokens[1][0]
+ assert_equal '{{', tokens[1][1]
+ assert_equal nil, tokens[2][0]
+ assert_equal 'cms:some_tag content', tokens[2][1]
+
+ tokens = 'content<{{cms some_tag}}>content'.scan(regex)
+ assert_equal nil, tokens[0][0]
+ assert_equal 'content<', tokens[0][1]
+ assert_equal nil, tokens[1][0]
+ assert_equal '{{', tokens[1][1]
+ assert_equal nil, tokens[2][0]
+ assert_equal 'cms some_tag}}>content',tokens[2][1]
+
+ tokens = 'content<{{cms:some_tag}}>content'.scan(regex)
+ assert_equal nil, tokens[0][0]
+ assert_equal 'content<', tokens[0][1]
+ assert_equal '{{cms:some_tag}}', tokens[1][0]
+ assert_equal nil, tokens[1][1]
+ assert_equal nil, tokens[2][0]
+ assert_equal '>content', tokens[2][1]
+
+ tokens = 'content<{{cms:type:label}}>content'.scan(regex)
+ assert_equal nil, tokens[0][0]
+ assert_equal 'content<', tokens[0][1]
+ assert_equal '{{cms:type:label}}', tokens[1][0]
+ assert_equal nil, tokens[1][1]
+ assert_equal nil, tokens[2][0]
+ assert_equal '>content', tokens[2][1]
+
+ tokens = 'content<{{cms:type:label }}>content'.scan(regex)
+ assert_equal nil, tokens[0][0]
+ assert_equal 'content<', tokens[0][1]
+ assert_equal '{{cms:type:label }}', tokens[1][0]
+ assert_equal nil, tokens[1][1]
+ assert_equal nil, tokens[2][0]
+ assert_equal '>content', tokens[2][1]
+
+ tokens = 'content<{{ cms:type:la/b el }}>content'.scan(regex)
+ assert_equal nil, tokens[0][0]
+ assert_equal 'content<', tokens[0][1]
+ assert_equal '{{ cms:type:la/b el }}',tokens[1][0]
+ assert_equal nil, tokens[1][1]
+ assert_equal nil, tokens[2][0]
+ assert_equal '>content', tokens[2][1]
+ end
+
+ def test_tokenizer_regex_limit
+ string = '<p>text</p>' * 400
+ tokens = string.scan(ComfortableMexicanSofa::Tag::TOKENIZER_REGEX)
+ assert_equal 1, tokens.count
+ assert_equal nil, tokens[0][0]
+ assert_equal string, tokens[0][1]
+ end
+
+ def test_content_for_existing_page
+ page = cms_pages(:default)
+ assert page.tags.blank?
+ assert_equal rendered_content_formatter(
+ '
+ layout_content_a
+ default_page_text_content_a
+ default_snippet_content
+ default_page_text_content_b
+ layout_content_b
+ default_snippet_content
+ layout_content_c'
+ ), page.content(true)
+
+ assert_equal 4, page.tags.size
+ assert_equal 'field_text_default_field_text', page.tags[0].identifier
+ assert_equal 'page_text_default_page_text', page.tags[1].identifier
+ assert_equal 'snippet_default', page.tags[2].identifier
+ assert_equal page.tags[1], page.tags[2].parent
+ assert_equal 'snippet_default', page.tags[3].identifier
+ end
+
+ def test_content_for_new_page
+ page = Cms::Page.new
+ assert page.blocks.blank?
+ assert page.tags.blank?
+ assert_equal '', page.content
+ assert page.tags.blank?
+ end
+
+ def test_content_for_new_page_with_layout
+ page = cms_sites(:default).pages.new(:layout => cms_layouts(:default))
+ assert page.blocks.blank?
+ assert page.tags.blank?
+ assert_equal rendered_content_formatter(
+ '
+ layout_content_a
+
+ layout_content_b
+ default_snippet_content
+ layout_content_c'
+ ), page.content
+
+ assert_equal 3, page.tags.size
+ assert_equal 'field_text_default_field_text', page.tags[0].identifier
+ assert_equal 'page_text_default_page_text', page.tags[1].identifier
+ assert_equal 'snippet_default', page.tags[2].identifier
+ end
+
+ def test_content_for_new_page_with_initilized_cms_blocks
+ page = cms_sites(:default).pages.new(:layout => cms_layouts(:default))
+ assert page.blocks.blank?
+ assert page.tags.blank?
+ page.blocks_attributes = [
+ {
+ :label => 'default_field_text',
+ :content => 'new_default_field_content',
+ :type => 'CmsTag::FieldText'
+ },
+ {
+ :label => 'default_page_text',
+ :content => "new_default_page_text_content\n{{cms:snippet:default}}",
+ :type => 'CmsTag::PageText'
+ },
+ {
+ :label => 'bogus_field_that_never_will_get_rendered',
+ :content => 'some_content_that_doesnot_matter',
+ :type => 'CmsTag::PageText'
+ }
+ ]
+ assert_equal 3, page.blocks.size
+
+ assert_equal rendered_content_formatter(
+ '
+ layout_content_a
+ new_default_page_text_content
+ default_snippet_content
+ layout_content_b
+ default_snippet_content
+ layout_content_c'
+ ), page.content
+
+ assert_equal 4, page.tags.size
+ assert_equal 'field_text_default_field_text', page.tags[0].identifier
+ assert_equal 'page_text_default_page_text', page.tags[1].identifier
+ assert_equal 'snippet_default', page.tags[2].identifier
+ assert_equal page.tags[1], page.tags[2].parent
+ assert_equal 'snippet_default', page.tags[3].identifier
+ end
+
+ def test_content_with_repeated_tags
+ page = cms_pages(:default)
+ page.layout.content << "\n{{cms:page:default_page_text:text}}"
+ page.layout.save!
+
+ assert_equal rendered_content_formatter(
+ '
+ layout_content_a
+ default_page_text_content_a
+ default_snippet_content
+ default_page_text_content_b
+ layout_content_b
+ default_snippet_content
+ layout_content_c
+ default_page_text_content_a
+ default_snippet_content
+ default_page_text_content_b'
+ ), page.content(true)
+
+ assert_equal 6, page.tags.size
+ assert_equal 'field_text_default_field_text', page.tags[0].identifier
+ assert_equal 'page_text_default_page_text', page.tags[1].identifier
+ assert_equal 'snippet_default', page.tags[2].identifier
+ assert_equal page.tags[1], page.tags[2].parent
+ assert_equal 'snippet_default', page.tags[3].identifier
+ assert_equal 'page_text_default_page_text', page.tags[4].identifier
+ assert_equal 'snippet_default', page.tags[5].identifier
+ assert_equal page.tags[4], page.tags[5].parent
+ end
+
+ def test_content_with_cyclical_tags
+ page = cms_pages(:default)
+ snippet = cms_snippets(:default)
+ snippet.update_attribute(:content, "infinite {{cms:page:default}} loop")
+ assert_equal rendered_content_formatter(
+ '
+ layout_content_a
+ default_page_text_content_a
+ infinite loop
+ default_page_text_content_b
+ layout_content_b
+ infinite loop
+ layout_content_c'
+ ), page.content(true)
+ assert_equal 6, page.tags.size
+ end
+
+ end