dead_simple_cms 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -136,6 +136,13 @@ DeadSimpleCMS.configure do
136
136
  :default => "books"
137
137
 
138
138
  string :href, :hint => link_hint
139
+
140
+ # In case you need to include customer helpers to a group. You can also extend the top-level section as well.
141
+ extend(SomeModule) do
142
+ def even_more_methods
143
+ href + "?books=true" if product_scope=="books"
144
+ end
145
+ end
139
146
  end
140
147
  end
141
148
  end
@@ -22,6 +22,12 @@ module DeadSimpleCMS
22
22
  @render_proc = block
23
23
  end
24
24
 
25
+ # Public: Exend functionality for the current group.
26
+ def extend(*modules, &block)
27
+ modules << Module.new(&block) if block_given?
28
+ super(*modules)
29
+ end
30
+
25
31
  # Public: If a presenter class was specified, returns an instance of the presenter.
26
32
  def presenter(view_context, *args)
27
33
  @presenter_class.new(view_context, *args) if @presenter_class
@@ -1,5 +1,5 @@
1
1
  module DeadSimpleCMS
2
- # Public: Represents a section in the website a user wants to be able to modify the data in an immediate-simple way.
2
+ # Public: Represents a section in the website a user wants to be able to modify the data in an immediate-simple way.
3
3
  class Section < Group
4
4
 
5
5
  include Util::Identifier
@@ -18,6 +18,8 @@ module DeadSimpleCMS
18
18
 
19
19
  before_save :upload_file_attributes
20
20
 
21
+ delegate :to_param, :to => :storage
22
+
21
23
  def initialize(identifier, options={}, &block)
22
24
  super(identifier, options)
23
25
  @path = options[:path]
@@ -43,7 +45,7 @@ module DeadSimpleCMS
43
45
  end
44
46
 
45
47
  def fragments
46
- @fragments.map { |f| f.is_a?(Proc) ? f.call(self) : f }
48
+ @fragments.map { |f| f.is_a?(Proc) ? f.call(self) : f }.flatten.uniq
47
49
  end
48
50
 
49
51
  def storage
@@ -72,10 +74,6 @@ module DeadSimpleCMS
72
74
  Builder.new(self, &block)
73
75
  end
74
76
 
75
- def to_param
76
- identifier.to_s
77
- end
78
-
79
77
  def cache_key
80
78
  "cms/#{identifier}"
81
79
  end
@@ -7,6 +7,8 @@ module DeadSimpleCMS
7
7
  attr_accessor :group_hierarchy
8
8
  attr_reader :section
9
9
 
10
+ delegate :display, :extend, :to => :current_group
11
+
10
12
  def self.define_attribute_builder_method(klass)
11
13
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
12
14
  def #{klass.builder_method_name}(identifier, options={})
@@ -24,10 +26,6 @@ module DeadSimpleCMS
24
26
  instance_eval(&block)
25
27
  end
26
28
 
27
- def display(*args, &block)
28
- (current_group || section).display(*args, &block)
29
- end
30
-
31
29
  def group(*args, &block)
32
30
  options = args.extract_options!
33
31
  attribute_options_by_identifier = options.delete(:attribute_options) || {}
@@ -55,13 +53,14 @@ module DeadSimpleCMS
55
53
 
56
54
  private
57
55
 
56
+ # Public: Returns the current group. Since Section inherits from Group, it is also considered a group as well.
58
57
  def current_group
59
- group_hierarchy.last
58
+ group_hierarchy.last || section
60
59
  end
61
60
 
62
61
  def nest_group(group)
63
62
  tmp = group_hierarchy
64
- (group_hierarchy.last || section).add_group(group) # chain it with the last group or section if its top-level.
63
+ current_group.add_group(group) # chain it with the last group or section if its top-level.
65
64
  self.group_hierarchy += [group]
66
65
  yield
67
66
  ensure
@@ -1,3 +1,4 @@
1
+ require 'digest/md5'
1
2
  module DeadSimpleCMS
2
3
  module Storage
3
4
  class Base
@@ -28,6 +29,11 @@ module DeadSimpleCMS
28
29
  @unique_key ||= section.identifier
29
30
  end
30
31
 
32
+ # Creates a unique string to identify this data.
33
+ def to_param
34
+ (value = read_value) ? Digest::MD5.hexdigest(value) : nil
35
+ end
36
+
31
37
  private
32
38
 
33
39
  # Public: Values to store.
@@ -1,3 +1,3 @@
1
1
  module DeadSimpleCMS
2
- VERSION = "0.9.2"
2
+ VERSION = "0.9.3"
3
3
  end
@@ -19,6 +19,7 @@ describe DeadSimpleCMS::Group::Configuration do
19
19
  it "should add to the attribute_arguments" do
20
20
  subject.attribute_arguments[:string_var].should == ["string", {:default => true}]
21
21
  end
22
+
22
23
  end
23
24
 
24
25
  end
@@ -11,10 +11,15 @@ describe DeadSimpleCMS::Section::Builder do
11
11
  end
12
12
 
13
13
  context "when a group_configuration is specified" do
14
+
14
15
  it "should inherit options from a group configuration" do
15
16
  section.banners.small.attributes[:url].required.should be true
16
17
  section.banners.small.attributes[:alt].default.should == "Design Beautiful Books"
17
18
  end
19
+
20
+ it "should keep attributes defined on the group" do
21
+ section.banners.small.attributes[:url].width.should == 715
22
+ end
18
23
  end
19
24
  end
20
25
 
@@ -24,5 +29,11 @@ describe DeadSimpleCMS::Section::Builder do
24
29
  end
25
30
  end
26
31
 
32
+ describe "#extend" do
33
+ it "should add the methods to the section" do
34
+ section.should respond_to :test_function
35
+ end
36
+ end
37
+
27
38
  end
28
39
 
@@ -7,7 +7,6 @@ describe DeadSimpleCMS::Section do
7
7
  end
8
8
 
9
9
  its(:cache_key) { should == "cms/section_identifier" }
10
- its(:to_param) { should == "section_identifier" }
11
10
  its(:path) { should == "/path" }
12
11
 
13
12
  describe "#root_group" do
@@ -17,6 +16,13 @@ describe DeadSimpleCMS::Section do
17
16
  end
18
17
  end
19
18
 
19
+ describe "#to_param" do
20
+ it "should delegate to the storage" do
21
+ subject.storage.should_receive(:to_param).and_return(:result)
22
+ subject.to_param.should == :result
23
+ end
24
+ end
25
+
20
26
  describe "#add_attribute" do
21
27
  let(:attribute) { DeadSimpleCMS::Attribute::Type::String.new(:attribute_identifier) }
22
28
  before(:each) { subject.add_attribute(attribute) }
@@ -38,6 +38,13 @@ describe DeadSimpleCMS::Storage::Base do
38
38
  end
39
39
  end
40
40
 
41
+ describe "#to_param" do
42
+ it "should return an md5 hash" do
43
+ subject.stub(:read_value).and_return("here is a bunch of crazy data in yaml format")
44
+ subject.to_param.should == "747f7947ee62bfdf2790b91252f862e2"
45
+ end
46
+ end
47
+
41
48
  describe "#write" do
42
49
 
43
50
  it "should write_value with dump of attributes_hash" do
data/spec/setup/shared.rb CHANGED
@@ -15,13 +15,19 @@ shared_context :sample_section do
15
15
  end
16
16
  group(:banners) do
17
17
  [[:small, 715, 85], [:large, 890, 123]].each do |size, width, height|
18
- group size => :image_tag, :width => width, :height => height do
18
+ group size => :image_tag, :attribute_options => {:url => {:width => width, :height => height}} do
19
19
  boolean :show
20
20
  string :promotional_href, :hint => "Used for all custom coupon banners not from the site announcement."
21
21
  display DeadSimpleCMS::BannerPresenter
22
22
  end
23
23
  end
24
24
  end
25
+
26
+ extend do
27
+ def test_function
28
+
29
+ end
30
+ end
25
31
  end
26
32
  end
27
33
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dead_simple_cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
- requirement: &2161734560 !ruby/object:Gem::Requirement
17
+ requirement: &2165934160 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '3.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2161734560
25
+ version_requirements: *2165934160
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activemodel
28
- requirement: &2161734040 !ruby/object:Gem::Requirement
28
+ requirement: &2165933640 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '3.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2161734040
36
+ version_requirements: *2165933640
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: simple_form
39
- requirement: &2161733660 !ruby/object:Gem::Requirement
39
+ requirement: &2165933240 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2161733660
47
+ version_requirements: *2165933240
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rails
50
- requirement: &2161733120 !ruby/object:Gem::Requirement
50
+ requirement: &2165932700 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '3.0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *2161733120
58
+ version_requirements: *2165932700
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: rspec
61
- requirement: &2161732700 !ruby/object:Gem::Requirement
61
+ requirement: &2165932280 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *2161732700
69
+ version_requirements: *2165932280
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: sqlite3
72
- requirement: &2161732240 !ruby/object:Gem::Requirement
72
+ requirement: &2165931820 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,7 +77,7 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *2161732240
80
+ version_requirements: *2165931820
81
81
  description: ! "Dead Simple CMS is a library for modifying different parts of your
82
82
  website without the overhead of having a\nfullblown CMS. The idea with this library
83
83
  is simple: provide an easy way to hook into different parts of your\napplication