shuffled files around
Oleg
committed Aug 24, 2010
commit 164c71f9a8dcc32b127c73235887d82546fbf8c2
Showing 19
changed files with
140 additions
and 100 deletions
app/models/cms_asset.rb
+1
-1
| @@ | @@ -1,2 +1,2 @@ |
| class CmsAsset < ActiveRecord::Base | |
| - | end |
| + | end |
| \ No newline at end of file | |
app/models/cms_block.rb
+0
-18
| @@ | @@ -8,22 +8,4 @@ class CmsBlock < ActiveRecord::Base |
| :presence => true, | |
| :uniqueness => true | |
| - | # -- Class Methods -------------------------------------------------------- |
| - | def self.initialize_subclass_content_blocks(content = '') |
| - | # todo |
| - | end |
| - | |
| - | # method called by the subclasses |
| - | def self.initialize_content_blocks(content = '') |
| - | content.scan(regex_tag_signature).flatten.collect do |label| |
| - | # todo, grab from db if exist |
| - | self.new(:label => label) |
| - | end |
| - | end |
| - | |
| - | # -- Instance Methods ----------------------------------------------------- |
| - | def regex_tag_signature |
| - | self.class.regex_tag_signature(label) |
| - | end |
| - | |
| end | |
app/models/cms_page_string.rb
+0
-20
| @@ | @@ -1,20 +0,0 @@ |
| - | class CmsPageString < CmsBlock |
| - | |
| - | # -- Class Methods -------------------------------------------------------- |
| - | # will match tags with this format: |
| - | # <cms:page:label:string /> |
| - | def self.regex_tag_signature(label = nil) |
| - | label ||= /\w+/ |
| - | /<\s*?cms:page:(#{label}):?(?:string)\s*?\/?>/ |
| - | end |
| - | |
| - | # -- Instance Methods ----------------------------------------------------- |
| - | def content |
| - | read_attribute(:content_string) |
| - | end |
| - | |
| - | def render |
| - | content |
| - | end |
| - | |
| - | end |
| \ No newline at end of file | |
app/models/cms_page_text.rb
+0
-25
| @@ | @@ -1,25 +0,0 @@ |
| - | class CmsPageText < CmsBlock |
| - | |
| - | # -- Class Methods -------------------------------------------------------- |
| - | # will match tags with this format: |
| - | # <cms:page:label:text /> |
| - | # <cms:page:label /> |
| - | def self.regex_tag_signature(label = nil) |
| - | label ||= /\w+/ |
| - | /<\s*?cms:page:(#{label}):?(?:text)?\s*?\/?>/ |
| - | end |
| - | |
| - | # -- Instance Methods ----------------------------------------------------- |
| - | def regex_tag_signature |
| - | self.class.regex_tag_signature(label) |
| - | end |
| - | |
| - | def content |
| - | read_attribute(:content_text) |
| - | end |
| - | |
| - | def render |
| - | content |
| - | end |
| - | |
| - | end |
| \ No newline at end of file | |
app/models/cms_snippet.rb
+0
-17
| @@ | @@ -1,17 +0,0 @@ |
| - | class CmsSnippet < ActiveRecord::Base |
| - | |
| - | # -- Scopes --------------------------------------------------------------- |
| - | default_scope :order => 'label' |
| - | |
| - | # -- Validations ---------------------------------------------------------- |
| - | validates :label, |
| - | :presence => true, |
| - | :uniqueness => true, |
| - | :format => { :with => /^\w[a-z0-9_-]*$/i } |
| - | |
| - | # -- Class Methods -------------------------------------------------------- |
| - | def self.content_for(label) |
| - | (s = find_by_label(label)) ? s.content : '' |
| - | end |
| - | |
| - | end |
app/models/cms_tag.rb
+27
-3
| @@ | @@ -1,11 +1,35 @@ |
| module CmsTag | |
| - | |
| + | |
| + | class Error < StandardError; end |
| + | |
| module ClassMethods | |
| - | # TODO |
| + | def regex_tag_signature |
| + | raise Error, 'method not defined' |
| + | end |
| end | |
| module InstanceMethods | |
| - | # TODO |
| + | def regex_tag_signature |
| + | raise Error, 'method not defined' |
| + | end |
| end | |
| + | |
| + | private |
| + | |
| + | def self.included(tag) |
| + | tag.send(:include, CmsTag::InstanceMethods) |
| + | tag.send(:extend, CmsTag::ClassMethods) |
| + | @@tag_instances ||= [] |
| + | @@tag_instances << tag |
| + | end |
| + | |
| + | def self.tag_instances |
| + | @@tag_instances |
| + | end |
| + | |
| + | end |
| + | # Loading all cms_tags |
| + | Dir.glob(File.join(File.dirname(__FILE__), 'cms_tags', '*.rb')).each do |tag| |
| + | require tag |
| end | |
| \ No newline at end of file | |
app/models/cms_tags/field_datetime.rb
+3
-0
| @@ | @@ -0,0 +1,3 @@ |
| + | class CmsTag::FieldDateTime |
| + | |
| + | end |
| \ No newline at end of file | |
app/models/cms_tags/field_integer.rb
+3
-0
| @@ | @@ -0,0 +1,3 @@ |
| + | class CmsTag::FieldInteger |
| + | |
| + | end |
| \ No newline at end of file | |
app/models/cms_tags/field_string.rb
+3
-0
| @@ | @@ -0,0 +1,3 @@ |
| + | class CmsTag::FieldString |
| + | |
| + | end |
| \ No newline at end of file | |
app/models/cms_tags/field_text.rb
+3
-0
| @@ | @@ -0,0 +1,3 @@ |
| + | class CmsTag::FieldText |
| + | |
| + | end |
| \ No newline at end of file | |
app/models/cms_tags/page_datetime.rb
+3
-0
| @@ | @@ -0,0 +1,3 @@ |
| + | class CmsTag::PageDateTime |
| + | |
| + | end |
| \ No newline at end of file | |
app/models/cms_tags/page_integer.rb
+3
-0
| @@ | @@ -0,0 +1,3 @@ |
| + | class CmsTag::PageInteger |
| + | |
| + | end |
| \ No newline at end of file | |
app/models/cms_tags/page_string.rb
+14
-0
| @@ | @@ -0,0 +1,14 @@ |
| + | class CmsTag::PageString |
| + | |
| + | include CmsTag |
| + | |
| + | def self.regex_tag_signature(label = nil) |
| + | label ||= /\w+/ |
| + | /<\s*?cms:page:(#{label}):string\s*?\/?>/ |
| + | end |
| + | |
| + | def regex_tag_signature |
| + | self.class.regex_tag_signature(label) |
| + | end |
| + | |
| + | end |
| \ No newline at end of file | |
app/models/cms_tags/page_text.rb
+14
-0
| @@ | @@ -0,0 +1,14 @@ |
| + | class CmsTag::PageText < CmsBlock |
| + | |
| + | include CmsTag |
| + | |
| + | def self.regex_tag_signature(label = nil) |
| + | label ||= /\w+/ |
| + | /<\s*?cms:page:(#{label}):?(?:text)?\s*?\/?>/ |
| + | end |
| + | |
| + | def regex_tag_signature |
| + | self.class.regex_tag_signature(label) |
| + | end |
| + | |
| + | end |
| \ No newline at end of file | |
app/models/cms_tags/partial.rb
+3
-0
| @@ | @@ -0,0 +1,3 @@ |
| + | class CmsTag::Partial |
| + | |
| + | end |
| \ No newline at end of file | |
app/models/cms_tags/snippet.rb
+3
-0
| @@ | @@ -0,0 +1,3 @@ |
| + | class CmsTag::Snippet |
| + | |
| + | end |
| \ No newline at end of file | |
migrate/01_create_cms.rb b/db/migrate/01_create_cms.rb
+8
-6
| @@ | @@ -21,15 +21,17 @@ class CreateCms < ActiveRecord::Migration |
| # -- Page Blocks -------------------------------------------------------- | |
| create_table :cms_blocks do |t| | |
| - | t.string :type |
| - | t.integer :cms_page_id |
| - | t.string :label |
| - | t.string :content_string |
| - | t.text :content_text |
| - | t.integer :content_integer |
| + | t.string :type |
| + | t.integer :cms_page_id |
| + | t.string :label |
| + | t.string :content_string |
| + | t.text :content_text |
| + | t.integer :content_integer |
| + | t.datetime :content_datetime |
| t.timestamps | |
| end | |
| add_index :cms_blocks, [:cms_page_id, :type, :label] | |
| + | # TODO: index this |
| # -- Snippets ----------------------------------------------------------- | |
| create_table :cms_snippets do |t| | |
test/fixtures/cms_blocks.yml
+19
-10
| @@ | @@ -1,14 +1,23 @@ |
| - | default: &page_block |
| + | default_page_text: |
| cms_page: default | |
| - | type: CmsPageText |
| + | type: CmsBlockPageText |
| label: content | |
| - | content_text: Text Content |
| - | content_string: |
| - | content_integer: |
| + | content_text: page_text_content |
| - | string: |
| - | <<: *page_block |
| - | type: CmsPageString |
| + | default_page_string: |
| + | cms_page: default |
| + | type: CmsBlockPageString |
| label: title | |
| - | content_text: |
| - | content_string: String Content |
| + | content_string: page_string_content |
| + | |
| + | default_field_text: |
| + | cms_page: default |
| + | type: CmsBlockFieldText |
| + | label: keywords |
| + | content_text: field_text_content |
| + | |
| + | default_field_string: |
| + | cms_page: default |
| + | type: CmsBlockFieldString |
| + | label: meta |
| + | content_string: field_text_content |
test/unit/cms_field_text_test.rb
+33
-0
| @@ | @@ -0,0 +1,33 @@ |
| + | require File.dirname(__FILE__) + '/../test_helper' |
| + | |
| + | class CmsFieldTextTest < ActiveSupport::TestCase |
| + | |
| + | def test_regex_tag_signature |
| + | %w( |
| + | <cms:field:keywords:text/> |
| + | <cms:field:keywords:text> |
| + | ).each do |tag| |
| + | assert_match CmsPageText.regex_tag_signature, tag |
| + | assert_match CmsPageText.regex_tag_signature('keywords'), tag |
| + | assert_match cms_blocks(:default).regex_tag_signature, tag |
| + | end |
| + | |
| + | assert_no_match CmsPageText.regex_tag_signature, '<cms:page:header:string>' |
| + | assert_no_match CmsPageText.regex_tag_signature('something'), '<cms:page:header:text/>' |
| + | assert_no_match CmsPageText.regex_tag_signature, '<cms_page:header>' |
| + | end |
| + | |
| + | def test_initialization_of_content_objects |
| + | content = cms_layouts(:default).content |
| + | block = CmsPageText.initialize_content_blocks(content).first |
| + | assert_equal CmsPageText, block.class |
| + | end |
| + | |
| + | def test_method_content |
| + | block = cms_blocks(:default) |
| + | assert_equal CmsPageText, block.class |
| + | assert_equal block.read_attribute(:content_text), block.content |
| + | assert_equal block.content, block.render |
| + | end |
| + | |
| + | end |