radiant-children_config-extension 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Children Config
2
+
3
+ Allows you to define new default page parts on every page.
4
+ Based on the [default\_page\_parts extension](https://github.com/santry/radiant-default-page-parts-extension), originally created by Sean Santry.
5
+
6
+ ## How to use
7
+
8
+ Let's say you want all pages under "Events" to have the page parts "location", "description" and "date" by default.
9
+ Simply add a "children_config" page part to the "Events" page. In the content of that page part, put:
10
+
11
+ ---
12
+ - parts
13
+ - name: location
14
+ filter: none
15
+ - name: description
16
+ filter: markdown
17
+ - name: date
18
+ filter: none
19
+
20
+ If you are using the [page_parts extension](https://github.com/digitalpulp/radiant-page_parts-extension), you can also pass the desired page part type like so:
21
+
22
+ ---
23
+ - parts
24
+ - name: location
25
+ filter: none
26
+ page_part_type: location_page_part
27
+ - name: description
28
+ filter: markdown
29
+ - name: date
30
+ filter: none
31
+ page_part_type: date_page_part
32
+
33
+ Another feature is to automatically create children for every new event page:
34
+
35
+ ---
36
+ - parts
37
+ - name: location
38
+ filter: none
39
+ page_part_type: location_page_part
40
+ - name: description
41
+ filter: markdown
42
+ - name: date
43
+ filter: none
44
+ page_part_type: date_page_part
45
+ - children
46
+ - title: News
47
+ status: published
48
+ parts:
49
+ - name: body
50
+ content: "<r:children:each><div><r:content /></div></r:children:each>"
data/Rakefile ADDED
@@ -0,0 +1,109 @@
1
+ # Determine where the RSpec plugin is by loading the boot
2
+ unless defined? RADIANT_ROOT
3
+ ENV["RAILS_ENV"] = "test"
4
+ case
5
+ when ENV["RADIANT_ENV_FILE"]
6
+ require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
7
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
8
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
9
+ else
10
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
11
+ end
12
+ end
13
+
14
+ require 'rake'
15
+ require 'rake/rdoctask'
16
+ require 'rake/testtask'
17
+
18
+ rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
19
+ $LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
20
+ require 'spec/rake/spectask'
21
+ require 'cucumber'
22
+ require 'cucumber/rake/task'
23
+
24
+ # Cleanup the RADIANT_ROOT constant so specs will load the environment
25
+ Object.send(:remove_const, :RADIANT_ROOT)
26
+
27
+ extension_root = File.expand_path(File.dirname(__FILE__))
28
+
29
+ task :default => [:spec, :features]
30
+ task :stats => "spec:statsetup"
31
+
32
+ desc "Run all specs in spec directory"
33
+ Spec::Rake::SpecTask.new(:spec) do |t|
34
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
35
+ t.spec_files = FileList['spec/**/*_spec.rb']
36
+ end
37
+
38
+ task :features => 'spec:integration'
39
+
40
+ namespace :spec do
41
+ desc "Run all specs in spec directory with RCov"
42
+ Spec::Rake::SpecTask.new(:rcov) do |t|
43
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
44
+ t.spec_files = FileList['spec/**/*_spec.rb']
45
+ t.rcov = true
46
+ t.rcov_opts = ['--exclude', 'spec', '--rails']
47
+ end
48
+
49
+ desc "Print Specdoc for all specs"
50
+ Spec::Rake::SpecTask.new(:doc) do |t|
51
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
52
+ t.spec_files = FileList['spec/**/*_spec.rb']
53
+ end
54
+
55
+ [:models, :controllers, :views, :helpers].each do |sub|
56
+ desc "Run the specs under spec/#{sub}"
57
+ Spec::Rake::SpecTask.new(sub) do |t|
58
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
59
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
60
+ end
61
+ end
62
+
63
+ desc "Run the Cucumber features"
64
+ Cucumber::Rake::Task.new(:integration) do |t|
65
+ t.fork = true
66
+ t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')]
67
+ # t.feature_pattern = "#{extension_root}/features/**/*.feature"
68
+ t.profile = "default"
69
+ end
70
+
71
+ # Setup specs for stats
72
+ task :statsetup do
73
+ require 'code_statistics'
74
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models)
75
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views)
76
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
77
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
78
+ ::CodeStatistics::TEST_TYPES << "Model specs"
79
+ ::CodeStatistics::TEST_TYPES << "View specs"
80
+ ::CodeStatistics::TEST_TYPES << "Controller specs"
81
+ ::CodeStatistics::TEST_TYPES << "Helper specs"
82
+ ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
83
+ end
84
+
85
+ namespace :db do
86
+ namespace :fixtures do
87
+ desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
88
+ task :load => :environment do
89
+ require 'active_record/fixtures'
90
+ ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
91
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
92
+ Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+
99
+ desc 'Generate documentation for the children_config extension.'
100
+ Rake::RDocTask.new(:rdoc) do |rdoc|
101
+ rdoc.rdoc_dir = 'rdoc'
102
+ rdoc.title = 'ChildrenConfigExtension'
103
+ rdoc.options << '--line-numbers' << '--inline-source'
104
+ rdoc.rdoc_files.include('README')
105
+ rdoc.rdoc_files.include('lib/**/*.rb')
106
+ end
107
+
108
+ # Load any custom rakefiles for extension
109
+ Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
@@ -0,0 +1,13 @@
1
+ # Uncomment this if you reference any of your controllers in activate
2
+ # require_dependency 'application_controller'
3
+ require 'radiant-children_config-extension/version'
4
+ class ChildrenConfigExtension < Radiant::Extension
5
+ version RadiantChildrenConfigExtension::VERSION
6
+ description "Allows you to override the configuration of page parts for new children under a given page."
7
+ url "https://github.com/jomz/radiant-children_config-extension"
8
+
9
+ def activate
10
+ Page.send :include, ChildrenConfig::PageExtensions
11
+ Admin::PagesController.send :include, ChildrenConfig::PagesControllerExtensions
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ Radiant.config do |config|
2
+ # config.define "setting.name", :default => 'value', :select_from => ['foo', 'bar']
3
+ end
@@ -0,0 +1,3 @@
1
+ ---
2
+ en:
3
+ children config: Children Config
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ # map.namespace :admin, :member => { :remove => :get } do |admin|
3
+ # admin.resources :children_config
4
+ # end
5
+ end
data/cucumber.yml ADDED
@@ -0,0 +1 @@
1
+ default: --format progress features --tags ~@proposed,~@in_progress
@@ -0,0 +1,7 @@
1
+ Feature: Children config
2
+ Scenario: With a children_config part
3
+ Given I am logged in as "existing"
4
+ And there is a homepage
5
+ When I edit the "home" page
6
+ And I press "Foo"
7
+ Then I should see "boo"
@@ -0,0 +1,11 @@
1
+ # Sets up the Rails environment for Cucumber
2
+ ENV["RAILS_ENV"] = "test"
3
+ # Extension root
4
+ extension_env = File.expand_path(File.dirname(__FILE__) + '/../../../../../config/environment')
5
+ require extension_env+'.rb'
6
+
7
+ Dir.glob(File.join(RADIANT_ROOT, "features", "**", "*.rb")).each {|step| require step unless step =~ /datasets_loader\.rb$/}
8
+
9
+ Cucumber::Rails::World.class_eval do
10
+ dataset :children_config
11
+ end
@@ -0,0 +1,22 @@
1
+ module NavigationHelpers
2
+
3
+ # Extend the standard PathMatchers with your own paths
4
+ # to be used in your features.
5
+ #
6
+ # The keys and values here may be used in your standard web steps
7
+ # Using:
8
+ #
9
+ # When I go to the "children_config" admin page
10
+ #
11
+ # would direct the request to the path you provide in the value:
12
+ #
13
+ # admin_children_config_path
14
+ #
15
+ PathMatchers = {} unless defined?(PathMatchers)
16
+ PathMatchers.merge!({
17
+ # /children_config/i => 'admin_children_config_path'
18
+ })
19
+
20
+ end
21
+
22
+ World(NavigationHelpers)
@@ -0,0 +1,64 @@
1
+ module ChildrenConfig::PageExtensions
2
+ def self.included(base)
3
+ base.class_eval do
4
+ after_save :create_children
5
+
6
+ def self.new_with_page_parts(config = Radiant::Config, parts = String)
7
+ begin
8
+ unless parts.empty?
9
+ config = YAML::load(parts)
10
+ if config.is_a?(Array) && config.select{|c| c.has_key? "parts"}.size > 0
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)
23
+ end
24
+ page
25
+ end
26
+ else
27
+ new_with_defaults(config)
28
+ end
29
+ rescue
30
+ new_with_defaults(config)
31
+ end
32
+ end
33
+
34
+
35
+ end
36
+ end
37
+
38
+ def create_children
39
+ if updated_at == created_at and parent and children_config = parent.part(:children_config).try(:content)
40
+ config = YAML::load(children_config)
41
+ if config.is_a?(Array) && config.select{|c| c.has_key? "children"}.size > 0
42
+ config.select{|c| c.has_key? "children"}.first["children"].each do |child|
43
+ options = {}
44
+ options[:parent_id] = self.id
45
+ options[:status_id] = Status[child['status'].downcase.to_sym].id
46
+ page = Page.new(options)
47
+ page.breadcrumb = page.title = child['title']
48
+ page.slug = child['title'].slugify
49
+ if child.has_key? "parts"
50
+ child["parts"].each do |part|
51
+ part["page_part_type"] = part["page_part_type"].to_s.camelize
52
+ page.parts.build(part)
53
+ end
54
+ else
55
+ page.parts.concat default_page_parts(Radiant::Config)
56
+ end
57
+ raise page.errors.full_messages.join ", " unless page.valid?
58
+ page.save
59
+ end
60
+
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,19 @@
1
+ module ChildrenConfig::PagesControllerExtensions
2
+ def self.included(base)
3
+ base.class_eval do
4
+ alias :original_new :new
5
+
6
+ def new
7
+ unless params[:page_id].blank?
8
+ parent_page = Page.find(params[:page_id]);
9
+ child_parts = parent_page.part("children_config").content
10
+ self.model = model_class.new_with_page_parts(config, child_parts)
11
+ else
12
+ self.model = model_class.new_with_defaults(config)
13
+ self.model.slug = '/'
14
+ end
15
+ response_for :singular
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module RadiantChildrenConfigExtension
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,2 @@
1
+ module RadiantChildrenConfigExtension
2
+ end
@@ -0,0 +1,55 @@
1
+ namespace :radiant do
2
+ namespace :extensions do
3
+ namespace :children_config do
4
+
5
+ desc "Runs the migration of the Children Config extension"
6
+ task :migrate => :environment do
7
+ require 'radiant/extension_migrator'
8
+ if ENV["VERSION"]
9
+ ChildrenConfigExtension.migrator.migrate(ENV["VERSION"].to_i)
10
+ Rake::Task['db:schema:dump'].invoke
11
+ else
12
+ ChildrenConfigExtension.migrator.migrate
13
+ Rake::Task['db:schema:dump'].invoke
14
+ end
15
+ end
16
+
17
+ desc "Copies public assets of the Children Config to the instance public/ directory."
18
+ task :update => :environment do
19
+ is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
20
+ puts "Copying assets from ChildrenConfigExtension"
21
+ Dir[ChildrenConfigExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
22
+ path = file.sub(ChildrenConfigExtension.root, '')
23
+ directory = File.dirname(path)
24
+ mkdir_p RAILS_ROOT + directory, :verbose => false
25
+ cp file, RAILS_ROOT + path, :verbose => false
26
+ end
27
+ unless ChildrenConfigExtension.root.starts_with? RAILS_ROOT # don't need to copy vendored tasks
28
+ puts "Copying rake tasks from ChildrenConfigExtension"
29
+ local_tasks_path = File.join(RAILS_ROOT, %w(lib tasks))
30
+ mkdir_p local_tasks_path, :verbose => false
31
+ Dir[File.join ChildrenConfigExtension.root, %w(lib tasks *.rake)].each do |file|
32
+ cp file, local_tasks_path, :verbose => false
33
+ end
34
+ end
35
+ end
36
+
37
+ desc "Syncs all available translations for this ext to the English ext master"
38
+ task :sync => :environment do
39
+ # The main translation root, basically where English is kept
40
+ language_root = ChildrenConfigExtension.root + "/config/locales"
41
+ words = TranslationSupport.get_translation_keys(language_root)
42
+
43
+ Dir["#{language_root}/*.yml"].each do |filename|
44
+ next if filename.match('_available_tags')
45
+ basename = File.basename(filename, '.yml')
46
+ puts "Syncing #{basename}"
47
+ (comments, other) = TranslationSupport.read_file(filename, basename)
48
+ words.each { |k,v| other[k] ||= words[k] } # Initializing hash variable as empty if it does not exist
49
+ other.delete_if { |k,v| !words[k] } # Remove if not defined in en.yml
50
+ TranslationSupport.write_file(filename, basename, comments, other)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "radiant-children_config-extension/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "radiant-children_config-extension"
7
+ s.version = RadiantChildrenConfigExtension::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Your Name"]
10
+ s.email = ["your email"]
11
+ s.homepage = "http://yourwebsite.com/children_config"
12
+ s.summary = %q{Children Config for Radiant CMS}
13
+ s.description = %q{Makes Radiant better by adding children_config!}
14
+
15
+ ignores = if File.exist?('.gitignore')
16
+ File.read('.gitignore').split("\n").inject([]) {|a,p| a + Dir[p] }
17
+ else
18
+ []
19
+ end
20
+ s.files = Dir['**/*'] - ignores
21
+ s.test_files = Dir['test/**/*','spec/**/*','features/**/*'] - ignores
22
+ # s.executables = Dir['bin/*'] - ignores
23
+ s.require_paths = ["lib"]
24
+
25
+ s.post_install_message = %{
26
+ Add this to your radiant project with:
27
+ config.gem 'radiant-children_config-extension', :version => '~>#{RadiantChildrenConfigExtension::VERSION}'
28
+ }
29
+ end
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Admin::PagesController do
4
+ dataset :home_page, :users, :children_config
5
+
6
+ before do
7
+ login_as :admin
8
+ end
9
+
10
+ it "should create the parts defined in children_config instead of the defaults" do
11
+ get :new, :page_id => page_id(:services)
12
+ response.should be_success
13
+ page = assigns(:page)
14
+ page.parts.map(&:name).join(" ").should eql("location description dat")
15
+ end
16
+
17
+ end
@@ -0,0 +1,16 @@
1
+ class ChildrenConfigDataset < Dataset::Base
2
+ uses :home_page
3
+
4
+ def load
5
+ create_page "Services", :slug => "services", :parent_id => page_id(:home) do
6
+ create_page_part "children_config", :content => "---
7
+ - name: location
8
+ filter: none
9
+ - name: description
10
+ filter: markdown
11
+ - name: date
12
+ filter: none"
13
+ end
14
+ end
15
+
16
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,6 @@
1
+ --colour
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
6
+ --reverse
@@ -0,0 +1,36 @@
1
+ unless defined? RADIANT_ROOT
2
+ ENV["RAILS_ENV"] = "test"
3
+ case
4
+ when ENV["RADIANT_ENV_FILE"]
5
+ require ENV["RADIANT_ENV_FILE"]
6
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
7
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
8
+ else
9
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
10
+ end
11
+ end
12
+ require "#{RADIANT_ROOT}/spec/spec_helper"
13
+
14
+ Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets")
15
+
16
+ if File.directory?(File.dirname(__FILE__) + "/matchers")
17
+ Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
18
+ end
19
+
20
+ Spec::Runner.configure do |config|
21
+ # config.use_transactional_fixtures = true
22
+ # config.use_instantiated_fixtures = false
23
+ # config.fixture_path = RAILS_ROOT + '/spec/fixtures'
24
+
25
+ # You can declare fixtures for each behaviour like this:
26
+ # describe "...." do
27
+ # fixtures :table_a, :table_b
28
+ #
29
+ # Alternatively, if you prefer to declare them only once, you can
30
+ # do so here, like so ...
31
+ #
32
+ # config.global_fixtures = :table_a, :table_b
33
+ #
34
+ # If you declare global fixtures, be aware that they will be declared
35
+ # for all of your examples, even those that don't use them.
36
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radiant-children_config-extension
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Your Name
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-07-24 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: Makes Radiant better by adding children_config!
22
+ email:
23
+ - your email
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - children_config_extension.rb
32
+ - config/initializers/radiant_config.rb
33
+ - config/locales/en.yml
34
+ - config/routes.rb
35
+ - cucumber.yml
36
+ - features/admin/children_config.feature
37
+ - features/support/env.rb
38
+ - features/support/paths.rb
39
+ - lib/children_config/page_extensions.rb
40
+ - lib/children_config/pages_controller_extensions.rb
41
+ - lib/radiant-children_config-extension/version.rb
42
+ - lib/radiant-children_config-extension.rb
43
+ - lib/tasks/children_config_extension_tasks.rake
44
+ - radiant-children_config-extension.gemspec
45
+ - Rakefile
46
+ - README.md
47
+ - spec/controllers/admin/pages_controller_spec.rb
48
+ - spec/datasets/children_config_dataset.rb
49
+ - spec/spec.opts
50
+ - spec/spec_helper.rb
51
+ homepage: http://yourwebsite.com/children_config
52
+ licenses: []
53
+
54
+ post_install_message: "\n Add this to your radiant project with:\n config.gem 'radiant-children_config-extension', :version => '~>1.0.0'\n "
55
+ rdoc_options: []
56
+
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.8.5
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Children Config for Radiant CMS
84
+ test_files:
85
+ - spec/controllers/admin/pages_controller_spec.rb
86
+ - spec/datasets/children_config_dataset.rb
87
+ - spec/spec.opts
88
+ - spec/spec_helper.rb
89
+ - features/admin/children_config.feature
90
+ - features/support/env.rb
91
+ - features/support/paths.rb