radiant-children_config-extension 1.0.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -30,6 +30,22 @@ If you are using the [page_parts extension](https://github.com/digitalpulp/radia
30
30
  filter: none
31
31
  page_part_type: date_page_part
32
32
 
33
+ You can also specify a new default class:
34
+
35
+ ---
36
+ - class_name: archive_page
37
+ - parts:
38
+ ...
39
+
40
+ Or default fields:
41
+
42
+ ---
43
+ - parts:
44
+ ...
45
+ - fields:
46
+ - name: foo
47
+ content: bar
48
+
33
49
  Another feature is to automatically create children for every new event page:
34
50
 
35
51
  ---
@@ -48,3 +64,20 @@ Another feature is to automatically create children for every new event page:
48
64
  parts:
49
65
  - name: body
50
66
  content: "<r:children:each><div><r:content /></div></r:children:each>"
67
+
68
+ It is possible to pass YAML to the content of a generated child, for example to set up a children\_config part again, you can use the '+' indicator for that. For example:
69
+
70
+ ---
71
+ - children:
72
+ - title: News
73
+ status: published
74
+ parts:
75
+ - name: body
76
+ content: "<r:children:each><div><r:content /></div></r:children:each>"
77
+ - name: children_config
78
+ content: |+
79
+ ---
80
+ - parts:
81
+ - name: body
82
+ ...
83
+
@@ -7,23 +7,19 @@ module ChildrenConfig::PageExtensions
7
7
  begin
8
8
  unless parts.empty?
9
9
  config = YAML::load(parts)
10
- if config.is_a?(Array) && config.select{|c| c.has_key? "parts"}.size > 0
10
+ if config.is_a?(Array)
11
11
  page = new
12
- options = {}
13
- config.select{|c| c.has_key? "parts"}.first["parts"].each do |part|
14
- options[:name] = part['name']
15
- options[:content] = part['content']
16
- default_filter = part['filter'].to_s.camelize
17
- options[:filter_id] = ["SmartyPants", "Markdown", "Textile", "WymEditor", "CKEditor"].include?(default_filter) ? "#{default_filter}" : ""
18
- # Consider page part type if page_parts extension is present
19
- if PagePart.column_names.include? "page_part_type"
20
- options[:page_part_type] = part['page_part_type'].to_s.camelize
21
- end
22
- page.parts << PagePart.new(options)
12
+ if config.select{|c| c.has_key? "parts"}.size > 0
13
+ page.parts << page.parts_from_config(config)
23
14
  end
24
15
  if config.select{|c| c.has_key? "class_name"}.size > 0
25
16
  page.class_name = config.select{|c| c.has_key? "class_name"}.first["class_name"].camelize
26
17
  end
18
+ if config.select{|c| c.has_key? "fields"}.size > 0
19
+ config.select{|c| c.has_key? "fields"}.first["fields"].each do |field|
20
+ page.fields << PageField.new(field)
21
+ end
22
+ end
27
23
  page
28
24
  end
29
25
  else
@@ -50,18 +46,18 @@ module ChildrenConfig::PageExtensions
50
46
  page.breadcrumb = page.title = child['title']
51
47
  page.slug = child['title'].slugify
52
48
  if child.has_key? "parts"
53
- child["parts"].each do |part|
54
- part["page_part_type"] = part["page_part_type"].to_s.camelize
55
- part["filter_id"] = ["SmartyPants", "Markdown", "Textile", "WymEditor", "CKEditor"].include?(part["filter"]) ? "#{default_filter}" : ""
56
- page.parts.build(part)
57
- end
49
+ page.parts << page.parts_from_config([child])
58
50
  else
59
51
  config = Radiant::Config
60
52
  default_parts = config['defaults.page.parts'].to_s.strip.split(/\s*,\s*/)
61
53
  default_parts.map do |name|
62
54
  page.parts << PagePart.new(:name => name, :filter_id => config['defaults.page.filter'])
63
55
  end
64
-
56
+ end
57
+ if child.has_key? "fields"
58
+ child["fields"].each do |field|
59
+ page.fields << PageField.new(field)
60
+ end
65
61
  end
66
62
  raise page.errors.full_messages.join ", " unless page.valid?
67
63
  page.save
@@ -70,4 +66,21 @@ module ChildrenConfig::PageExtensions
70
66
  end
71
67
  end
72
68
  end
69
+
70
+ def parts_from_config(config)
71
+ result, options = [], {}
72
+ config.select{|c| c.has_key? "parts"}.first["parts"].each do |part|
73
+ options[:name] = part['name']
74
+ options[:content] = part['content']
75
+ default_filter = part['filter'].to_s.camelize
76
+ options[:filter_id] = ["SmartyPants", "Markdown", "Textile", "WymEditor", "CKEditor"].include?(default_filter) ? "#{default_filter}" : ""
77
+ # Consider page part type if page_parts extension is present
78
+ if PagePart.column_names.include? "page_part_type"
79
+ options[:page_part_type] = part['page_part_type'].to_s.camelize
80
+ end
81
+ result << PagePart.new(options)
82
+ end
83
+ result
84
+ end
85
+
73
86
  end
@@ -1,3 +1,3 @@
1
1
  module RadiantChildrenConfigExtension
2
- VERSION = '1.0.5'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -11,7 +11,7 @@ describe Admin::PagesController do
11
11
  get :new, :page_id => page_id(:services)
12
12
  response.should be_success
13
13
  page = assigns(:page)
14
- page.parts.map(&:name).join(" ").should eql("location description dat")
14
+ page.parts.map(&:name).join(" ").should eql("location description date")
15
15
  end
16
16
 
17
17
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radiant-children_config-extension
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 5
10
- version: 1.0.5
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Your Name
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-27 00:00:00 Z
18
+ date: 2012-09-25 00:00:00 +02:00
19
+ default_executable:
19
20
  dependencies: []
20
21
 
21
22
  description: Makes Radiant better by adding children_config!
@@ -41,11 +42,6 @@ files:
41
42
  - lib/radiant-children_config-extension/version.rb
42
43
  - lib/radiant-children_config-extension.rb
43
44
  - lib/tasks/children_config_extension_tasks.rake
44
- - radiant-children_config-extension-1.0.0.gem
45
- - radiant-children_config-extension-1.0.1.gem
46
- - radiant-children_config-extension-1.0.2.gem
47
- - radiant-children_config-extension-1.0.3.gem
48
- - radiant-children_config-extension-1.0.4.gem
49
45
  - radiant-children_config-extension.gemspec
50
46
  - Rakefile
51
47
  - README.md
@@ -53,10 +49,11 @@ files:
53
49
  - spec/datasets/children_config_dataset.rb
54
50
  - spec/spec.opts
55
51
  - spec/spec_helper.rb
52
+ has_rdoc: true
56
53
  homepage: http://yourwebsite.com/children_config
57
54
  licenses: []
58
55
 
59
- post_install_message: "\n Add this to your radiant project with:\n config.gem 'radiant-children_config-extension', :version => '~>1.0.5'\n "
56
+ post_install_message: "\n Add this to your radiant project with:\n config.gem 'radiant-children_config-extension', :version => '~>1.1.0'\n "
60
57
  rdoc_options: []
61
58
 
62
59
  require_paths:
@@ -82,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
79
  requirements: []
83
80
 
84
81
  rubyforge_project:
85
- rubygems_version: 1.8.5
82
+ rubygems_version: 1.5.3
86
83
  signing_key:
87
84
  specification_version: 3
88
85
  summary: Children Config for Radiant CMS