radiant-templates-extension 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/HELP_designer.textile +79 -0
  2. data/README.textile +123 -0
  3. data/Rakefile +136 -0
  4. data/VERSION +1 -0
  5. data/app/controllers/admin/part_types_controller.rb +8 -0
  6. data/app/controllers/admin/templates_controller.rb +38 -0
  7. data/app/helpers/admin/part_types_helper.rb +26 -0
  8. data/app/helpers/admin/templates_helper.rb +108 -0
  9. data/app/models/part_type.rb +14 -0
  10. data/app/models/template.rb +80 -0
  11. data/app/models/template_part.rb +21 -0
  12. data/app/views/admin/pages/_edit_template.html.haml +32 -0
  13. data/app/views/admin/pages/_edit_template_part.html.haml +20 -0
  14. data/app/views/admin/pages/_switch_templates.html.haml +23 -0
  15. data/app/views/admin/pages/_template_column.html.haml +3 -0
  16. data/app/views/admin/pages/_template_column_header.html.haml +1 -0
  17. data/app/views/admin/part_types/_form.html.haml +36 -0
  18. data/app/views/admin/part_types/_list.html.haml +23 -0
  19. data/app/views/admin/part_types/edit.html.haml +5 -0
  20. data/app/views/admin/part_types/index.html.haml +7 -0
  21. data/app/views/admin/part_types/new.html.haml +2 -0
  22. data/app/views/admin/part_types/remove.html.haml +15 -0
  23. data/app/views/admin/templates/_form.html.haml +65 -0
  24. data/app/views/admin/templates/_template_part.html.haml +21 -0
  25. data/app/views/admin/templates/_templates_css.html.haml +12 -0
  26. data/app/views/admin/templates/edit.html.haml +10 -0
  27. data/app/views/admin/templates/index.html.haml +47 -0
  28. data/app/views/admin/templates/new.html.haml +9 -0
  29. data/app/views/admin/templates/remove.html.haml +15 -0
  30. data/config/initializers/radiant_config.rb +3 -0
  31. data/config/locales/en.yml +32 -0
  32. data/config/routes.rb +7 -0
  33. data/db/migrate/001_create_templates.rb +17 -0
  34. data/db/migrate/002_create_template_parts.rb +15 -0
  35. data/db/migrate/003_rename_sublayout_column.rb +9 -0
  36. data/db/migrate/004_add_position_to_templates.rb +13 -0
  37. data/db/migrate/005_create_part_types.rb +17 -0
  38. data/db/migrate/006_add_description_to_template_parts.rb +9 -0
  39. data/db/migrate/007_add_page_class_name_to_templates.rb +9 -0
  40. data/db/migrate/008_add_index_to_templates.rb +9 -0
  41. data/db/migrate/009_create_default_part_types.rb +23 -0
  42. data/db/migrate/010_update_boolean_part_type.rb +9 -0
  43. data/db/migrate/011_add_timestamps.rb +19 -0
  44. data/lib/file_system/model/part_type_extensions.rb +19 -0
  45. data/lib/file_system/model/template_extensions.rb +52 -0
  46. data/lib/tasks/templates_extension_tasks.rake +28 -0
  47. data/lib/templates/associations.rb +7 -0
  48. data/lib/templates/controller_extensions.rb +20 -0
  49. data/lib/templates/helper.rb +75 -0
  50. data/lib/templates/page_extensions.rb +43 -0
  51. data/lib/templates/tags.rb +43 -0
  52. data/public/images/admin/menu_arrow.png +0 -0
  53. data/public/images/admin/move_higher.png +0 -0
  54. data/public/images/admin/move_lower.png +0 -0
  55. data/public/images/admin/move_to_bottom.png +0 -0
  56. data/public/images/admin/move_to_top.png +0 -0
  57. data/public/images/admin/part_type.png +0 -0
  58. data/public/images/admin/template.png +0 -0
  59. data/spec/controllers/admin_page_controller_extensions_spec.rb +61 -0
  60. data/spec/controllers/part_types_controller_spec.rb +89 -0
  61. data/spec/controllers/templates_controller_spec.rb +322 -0
  62. data/spec/datasets/part_types_dataset.rb +15 -0
  63. data/spec/datasets/templates_dataset.rb +34 -0
  64. data/spec/helpers/templates_helper_spec.rb +56 -0
  65. data/spec/models/page_extensions_spec.rb +9 -0
  66. data/spec/models/part_type_spec.rb +28 -0
  67. data/spec/models/tags_spec.rb +44 -0
  68. data/spec/models/template_part_spec.rb +37 -0
  69. data/spec/models/template_spec.rb +88 -0
  70. data/spec/spec.opts +6 -0
  71. data/spec/spec_helper.rb +39 -0
  72. data/templates_extension.rb +83 -0
  73. data/vendor/plugins/acts_as_list/README +23 -0
  74. data/vendor/plugins/acts_as_list/init.rb +3 -0
  75. data/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +256 -0
  76. data/vendor/plugins/acts_as_list/test/list_test.rb +332 -0
  77. data/vendor/plugins/make_resourceful/DEFAULTS +148 -0
  78. data/vendor/plugins/make_resourceful/LICENSE +7 -0
  79. data/vendor/plugins/make_resourceful/README +239 -0
  80. data/vendor/plugins/make_resourceful/Rakefile +42 -0
  81. data/vendor/plugins/make_resourceful/VERSION +1 -0
  82. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/resourceful_scaffold_generator.rb +87 -0
  83. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/controller.rb +5 -0
  84. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/fixtures.yml +10 -0
  85. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/functional_test.rb +57 -0
  86. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/helper.rb +2 -0
  87. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/migration.rb +13 -0
  88. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/model.rb +2 -0
  89. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/unit_test.rb +7 -0
  90. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view__form.haml +5 -0
  91. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_edit.haml +11 -0
  92. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_index.haml +5 -0
  93. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_new.haml +9 -0
  94. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_partial.haml +12 -0
  95. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_show.haml +14 -0
  96. data/vendor/plugins/make_resourceful/init.rb +3 -0
  97. data/vendor/plugins/make_resourceful/lib/resourceful/base.rb +52 -0
  98. data/vendor/plugins/make_resourceful/lib/resourceful/builder.rb +354 -0
  99. data/vendor/plugins/make_resourceful/lib/resourceful/default/accessors.rb +346 -0
  100. data/vendor/plugins/make_resourceful/lib/resourceful/default/actions.rb +92 -0
  101. data/vendor/plugins/make_resourceful/lib/resourceful/default/callbacks.rb +51 -0
  102. data/vendor/plugins/make_resourceful/lib/resourceful/default/responses.rb +118 -0
  103. data/vendor/plugins/make_resourceful/lib/resourceful/default/urls.rb +137 -0
  104. data/vendor/plugins/make_resourceful/lib/resourceful/maker.rb +83 -0
  105. data/vendor/plugins/make_resourceful/lib/resourceful/response.rb +33 -0
  106. data/vendor/plugins/make_resourceful/lib/resourceful/serialize.rb +181 -0
  107. data/vendor/plugins/make_resourceful/spec/accessors_spec.rb +473 -0
  108. data/vendor/plugins/make_resourceful/spec/actions_spec.rb +283 -0
  109. data/vendor/plugins/make_resourceful/spec/base_spec.rb +12 -0
  110. data/vendor/plugins/make_resourceful/spec/builder_spec.rb +332 -0
  111. data/vendor/plugins/make_resourceful/spec/callbacks_spec.rb +71 -0
  112. data/vendor/plugins/make_resourceful/spec/integration_spec.rb +396 -0
  113. data/vendor/plugins/make_resourceful/spec/maker_spec.rb +91 -0
  114. data/vendor/plugins/make_resourceful/spec/response_spec.rb +37 -0
  115. data/vendor/plugins/make_resourceful/spec/responses_spec.rb +314 -0
  116. data/vendor/plugins/make_resourceful/spec/rspec_on_rails/LICENSE +35 -0
  117. data/vendor/plugins/make_resourceful/spec/rspec_on_rails/redirect_to.rb +81 -0
  118. data/vendor/plugins/make_resourceful/spec/rspec_on_rails/render_template.rb +28 -0
  119. data/vendor/plugins/make_resourceful/spec/serialize_spec.rb +133 -0
  120. data/vendor/plugins/make_resourceful/spec/spec_helper.rb +279 -0
  121. data/vendor/plugins/make_resourceful/spec/urls_spec.rb +276 -0
  122. metadata +214 -0
@@ -0,0 +1,15 @@
1
+ class PartTypesDataset < Dataset::Base
2
+ def load
3
+ create_part_type "One-line", :field_type => "text_field", :field_class => "text", :field_styles => "width: 500px"
4
+ create_part_type "Plaintext", :field_type => "text_area", :field_class => "plain"
5
+ create_part_type "WYSIWYG", :field_type => "text_area", :field_class => "textarea", :field_styles => "width: 100%"
6
+ create_part_type "Boolean", :field_type => "radio_button"
7
+ create_part_type "Asset", :field_type => "hidden", :field_class => "asset"
8
+ end
9
+
10
+ helpers do
11
+ def create_part_type(name, attributes={})
12
+ create_model PartType, name.symbolize, attributes.merge(:name => name)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,34 @@
1
+ class TemplatesDataset < Dataset::Base
2
+ uses :part_types, :layouts
3
+
4
+ def load
5
+ create_template "Sample" do
6
+ create_template_part "Part 1", :part_type_id => part_type_id(:wysiwyg)
7
+ create_template_part "extended", :part_type_id => part_type_id(:plaintext)
8
+ create_template_part "featured?", :part_type_id => part_type_id(:boolean)
9
+ create_template_part "Feature image", :part_type_id => part_type_id(:asset)
10
+ create_template_part "Tagline", :part_type_id => part_type_id(:one_line)
11
+ end
12
+ create_template "Another", :page_class_name => "FileNotFoundPage"
13
+ end
14
+
15
+ helpers do
16
+ def create_template(name, attributes={})
17
+ @current_template = create_model Template, name.symbolize, template_params(attributes.reverse_merge(:name => name))
18
+ yield if block_given?
19
+ @current_template = nil
20
+ end
21
+
22
+ def template_params(attributes={})
23
+ {
24
+ :content => "Content for #{attributes[:name]}.",
25
+ :page_class_name => nil,
26
+ :layout_id => layout_id(:main),
27
+ }.merge(attributes.symbolize_keys)
28
+ end
29
+
30
+ def create_template_part(name, attributes={})
31
+ create_model TemplatePart, name.symbolize, attributes.reverse_merge(:name => name, :template_id => (@current_template ? @current_template.id : nil))
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,56 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Templates::Helper do
4
+ dataset :pages, :templates
5
+
6
+ before :each do
7
+ @page = pages(:home)
8
+ helper.instance_variable_set(:@page, @page)
9
+ end
10
+
11
+ describe "template_part_field" do
12
+ it "should output a text area from a template part with part-type of text_area" do
13
+ helper.should_receive(:text_area_tag).and_return('text_area')
14
+ helper.template_part_field(template_parts(:extended), 0).should == 'text_area'
15
+ end
16
+
17
+ it "should output a text field from a template part with part-type of text_field" do
18
+ helper.should_receive(:text_field_tag).and_return('text_field')
19
+ helper.template_part_field(template_parts(:tagline), 0).should == 'text_field'
20
+ end
21
+
22
+ it "should output a radio_button field from a template part with part-type of radio_button" do
23
+ helper.should_receive(:radio_button_tag).twice.and_return('radio_button')
24
+ helper.template_part_field(template_parts(:featured), 0).should include("radio_button")
25
+ end
26
+
27
+ it "should output a hidden field from a template part with part-type hidden" do
28
+ helper.should_receive(:hidden_field_tag).and_return('hidden')
29
+ helper.template_part_field(template_parts(:feature_image), 0).should == 'hidden'
30
+ end
31
+
32
+ it "should determine the field name from the given index" do
33
+ helper.should_receive(:hidden_field_tag).with("#{helper.page_part_name(1)}[content]", '', :class => 'asset', :id => 'page_parts_1_content')
34
+ helper.template_part_field(template_parts(:feature_image), 1)
35
+ end
36
+
37
+ it "should put blank content in the field if the part doesn't already exist" do
38
+ @page.part('Tagline').should be_nil
39
+ helper.should_receive(:text_field_tag).with("#{helper.page_part_name(1)}[content]", '', :class => 'text', :style => "width: 500px", :id => 'page_parts_1_content')
40
+ helper.template_part_field(template_parts(:tagline), 1)
41
+ end
42
+
43
+ it "should put content from the existing part in the field" do
44
+ helper.should_receive(:text_area_tag).with("#{helper.page_part_name(1)}[content]", 'Just a test.', :class => 'plain', :id => 'page_parts_1_content')
45
+ helper.template_part_field(template_parts(:extended), 1)
46
+ end
47
+
48
+ if defined?(ConcurrentDraftExtension)
49
+ it "should output the draft content and hidden live content if concurrent_draft is enabled" do
50
+ helper.should_receive(:hidden_field_tag).with("#{helper.page_part_name(1)}[content]", 'Just a test.', :id => 'page_parts_1_content')
51
+ helper.should_receive(:text_area_tag).with("#{helper.page_part_name(1)}[draft_content]", '', :class => 'plain', :id => 'page_parts_1_draft_content')
52
+ helper.template_part_field(template_parts(:extended), 1, true)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Page, "extended with templates" do
4
+ it "should be associated to its template" do
5
+ Page.included_modules.should include(Templates::Associations)
6
+ Page.new.should respond_to(:template)
7
+ Page.new.should respond_to(:template=)
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe PartType do
4
+ before :each do
5
+ @part_type = PartType.new :name => "Test type", :field_type => 'text_area'
6
+ end
7
+
8
+ it "should require a name" do
9
+ @part_type.name = nil
10
+ @part_type.should_not be_valid
11
+ @part_type.should have(1).error_on(:name)
12
+ end
13
+
14
+ it "should require a valid field type" do
15
+ @part_type.field_type = 'foobar'
16
+ @part_type.should_not be_valid
17
+ @part_type.should have(1).error_on(:field_type)
18
+ end
19
+
20
+ it "should be valid with correct parameters" do
21
+ @part_type.should be_valid
22
+ end
23
+
24
+ it "should not allow creation of a new part type with a duplicate name" do
25
+ @new_part_type = PartType.create :name => @part_type.name
26
+ @new_part_type.id.should be_nil
27
+ end
28
+ end
@@ -0,0 +1,44 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Templates::Tags" do
4
+ dataset :pages
5
+ before :each do
6
+ @page = pages(:home)
7
+ @page.parts.build(:name => "False", :content => 'false')
8
+ @page.parts.build(:name => "True", :content => 'true')
9
+ end
10
+
11
+ describe "<r:boolean_part>" do
12
+ it "should expand its contents" do
13
+ @page.should render('<r:boolean_part>true</r:boolean_part>').as('true')
14
+ end
15
+ end
16
+
17
+ describe "<r:boolean_part:if>" do
18
+ it "should expand its contents if the selected part evaluates to true" do
19
+ @page.should render('<r:boolean_part:if part="True">yes!</r:boolean_part:if>').as('yes!')
20
+ end
21
+
22
+ it "should not expand its contents if the selected part does not evaluate to true" do
23
+ @page.should render('<r:boolean_part:if part="False">yes!</r:boolean_part:if>').as('')
24
+ end
25
+
26
+ it "should raise an error if the part attribute is missing" do
27
+ @page.should render('<r:boolean_part:if>yes!</r:boolean_part:if>').with_error("`boolean_part:if' tag requires a 'part' attribute")
28
+ end
29
+ end
30
+
31
+ describe "<r:boolean_part:unless>" do
32
+ it "should not expand its contents if the selected part evaluates to true" do
33
+ @page.should render('<r:boolean_part:unless part="True">yes!</r:boolean_part:unless>').as('')
34
+ end
35
+
36
+ it "should expand its contents if the selected part does not evaluate to true" do
37
+ @page.should render('<r:boolean_part:unless part="False">yes!</r:boolean_part:unless>').as('yes!')
38
+ end
39
+
40
+ it "should raise an error if the part attribute is missing" do
41
+ @page.should render('<r:boolean_part:unless>yes!</r:boolean_part:unless>').with_error("`boolean_part:unless' tag requires a 'part' attribute")
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,37 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe TemplatePart do
4
+ dataset :part_types
5
+
6
+ before :each do
7
+ @template_part = TemplatePart.new :template_id => 1, :name => "extended",
8
+ :filter_id => nil, :part_type_id => 1
9
+ end
10
+
11
+ it "should be valid with correct parameters" do
12
+ @template_part.should be_valid
13
+ end
14
+
15
+ it "should require a name" do
16
+ @template_part.name = nil
17
+ @template_part.should_not be_valid
18
+ @template_part.should have(1).error_on(:name)
19
+ end
20
+
21
+ it "should require a part type" do
22
+ @template_part.part_type_id = nil
23
+ @template_part.should_not be_valid
24
+ @template_part.should have(1).error_on(:part_type_id)
25
+ end
26
+
27
+ it "should disallow 'body' for name" do
28
+ @template_part.name = 'body'
29
+ @template_part.should_not be_valid
30
+ @template_part.should have(1).error_on(:name)
31
+ end
32
+
33
+ it "should assign a part type by name" do
34
+ @template_part.part_type_name = "Boolean"
35
+ @template_part.part_type.should == part_types(:boolean)
36
+ end
37
+ end
@@ -0,0 +1,88 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe ::Template do
4
+ dataset :templates, :pages
5
+
6
+ before :each do
7
+ @template = Template.new :name => "Article", :layout_id => layout_id(:main)
8
+ end
9
+
10
+ it "should be valid with correct parameters" do
11
+ @template.should be_valid
12
+ end
13
+
14
+ it "should require a name" do
15
+ @template.name = nil
16
+ @template.should_not be_valid
17
+ @template.should have(1).error_on(:name)
18
+ end
19
+
20
+ it "should require a layout" do
21
+ @template.layout = nil
22
+ @template.should_not be_valid
23
+ @template.should have(1).error_on(:layout_id)
24
+ end
25
+
26
+ it "should require a valid or empty page class name" do
27
+ @template.page_class_name = nil
28
+ @template.should be_valid
29
+
30
+ @template.page_class_name = "blah"
31
+ @template.should_not be_valid
32
+
33
+ @template.page_class_name = "FileNotFoundPage"
34
+ @template.should be_valid
35
+ end
36
+
37
+ it "should create template parts from a hash" do
38
+ @template.template_parts = {'1' => {:name => "extended", :filter_id => nil, :part_type_id => 1}, '2' => {:name => "more", :filter_id => "Textile", :part_type_id => 3}}
39
+ @template.should be_valid
40
+ @template.should have(2).template_parts
41
+ end
42
+
43
+ describe "updating associated pages after update" do
44
+ before :each do
45
+ @template = templates(:sample)
46
+ @page = pages(:home)
47
+ @template.should_receive(:pages).and_return([@page])
48
+ @template.update_attributes!(:layout_id => layout_id(:utf8), :page_class_name => "FileNotFoundPage")
49
+ @page.reload
50
+ @page.parts.reload
51
+ end
52
+
53
+ it "should update the layout" do
54
+ @page.layout_id.should == layout_id(:utf8)
55
+ end
56
+
57
+ it "should delete page parts that do not match the template parts" do
58
+ @page.part(:sidebar).should be_nil
59
+ @page.part(:titles).should be_nil
60
+ end
61
+
62
+ it "should update the class name" do
63
+ @page.class_name.should == 'FileNotFoundPage'
64
+ end
65
+
66
+ it "should update the content of the body part" do
67
+ @page.part(:body).content.should == 'Content for Sample.'
68
+ end
69
+
70
+ if defined?(ConcurrentDraftExtension)
71
+ it "should update the draft_content of the body part" do
72
+ @page.part(:body).draft_content.should == 'Content for Sample.'
73
+ end
74
+ end
75
+ end
76
+
77
+ it "should return templates in default order by position" do
78
+ Template.find(:all, :order => :position).should == Template.find(:all)
79
+ end
80
+
81
+ it "should not update associated pages when reordering" do
82
+ @template = templates(:sample)
83
+ Template.reordering do
84
+ @template.should_not_receive(:pages)
85
+ @template.move_to_bottom
86
+ end
87
+ end
88
+ 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,39 @@
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
+ # if File.directory?(File.dirname(__FILE__) + "/scenarios")
15
+ # Scenario.load_paths.unshift File.dirname(__FILE__) + "/scenarios"
16
+ # end
17
+ Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets")
18
+
19
+ if File.directory?(File.dirname(__FILE__) + "/matchers")
20
+ Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
21
+ end
22
+
23
+ Spec::Runner.configure do |config|
24
+ # config.use_transactional_fixtures = true
25
+ # config.use_instantiated_fixtures = false
26
+ # config.fixture_path = RAILS_ROOT + '/spec/fixtures'
27
+
28
+ # You can declare fixtures for each behaviour like this:
29
+ # describe "...." do
30
+ # fixtures :table_a, :table_b
31
+ #
32
+ # Alternatively, if you prefer to declare them only once, you can
33
+ # do so here, like so ...
34
+ #
35
+ # config.global_fixtures = :table_a, :table_b
36
+ #
37
+ # If you declare global fixtures, be aware that they will be declared
38
+ # for all of your examples, even those that don't use them.
39
+ end
@@ -0,0 +1,83 @@
1
+ # Uncomment this if you reference any of your controllers in activate
2
+ require_dependency 'application_controller'
3
+
4
+ class TemplatesExtension < Radiant::Extension
5
+ version "#{File.read(File.expand_path(File.dirname(__FILE__)) + '/VERSION')}"
6
+ description "Imposes structure on pages via content templates"
7
+ url "https://github.com/avonderluft/radiant-templates-extension/tree/master"
8
+
9
+ def activate
10
+ begin
11
+ FileSystem::MODELS << "PartType" << "Template"
12
+ rescue NameError, LoadError
13
+ end
14
+ Page.class_eval do
15
+ include Templates::Associations
16
+ include Templates::Tags
17
+ include Templates::PageExtensions
18
+ end
19
+ Admin::PagesController.class_eval do
20
+ include Templates::ControllerExtensions
21
+ helper Templates::Helper
22
+ end
23
+ tab "Design" do
24
+ add_item "Templates", "/admin/templates", :before => "Layouts"
25
+ add_item "Template Part Types", "/admin/part_types", :after => "Templates"
26
+ end
27
+ # Admin UI customization
28
+ admin.page.index.add :node, 'template_column', :after => 'title_column'
29
+ admin.page.index.add :sitemap_head, 'template_column_header', :after => 'title_column_header'
30
+ admin.page.edit.add :extended_metadata, 'switch_templates', :after => 'breadcrumb'
31
+ admin.page.edit.add :form, 'edit_template', :before => 'edit_page_parts'
32
+ admin.page.edit.form.delete 'edit_page_parts'
33
+ admin.page.edit.parts_bottom.delete 'edit_layout_and_type'
34
+
35
+ Radiant::AdminUI.class_eval do
36
+ attr_accessor :template
37
+ attr_accessor :part_type
38
+ alias_method "templates", :template
39
+ alias_method "part_types", :part_type
40
+ end
41
+ admin.template = load_default_template_regions
42
+ admin.part_type = load_default_part_type_regions
43
+ end
44
+
45
+ def load_default_template_regions
46
+ returning OpenStruct.new do |template|
47
+ template.edit = Radiant::AdminUI::RegionSet.new do |edit|
48
+ edit.main.concat %w{edit_header edit_form}
49
+ edit.form.concat %w{edit_title edit_content}
50
+ edit.layout.concat %w{edit_layout edit_type}
51
+ edit.form_bottom.concat %w{edit_buttons edit_timestamp}
52
+ edit.bottom.concat %w{parts_button}
53
+ end
54
+ template.index = Radiant::AdminUI::RegionSet.new do |index|
55
+ index.top.concat %w{}
56
+ index.thead.concat %w{title_header parts_header actions_header order_header}
57
+ index.tbody.concat %w{title_cell parts_cell actions_cell order_cell}
58
+ index.bottom.concat %w{new_button}
59
+ end
60
+ template.new = template.edit
61
+ end
62
+ end
63
+
64
+ def load_default_part_type_regions
65
+ returning OpenStruct.new do |part_type|
66
+ part_type.edit = Radiant::AdminUI::RegionSet.new do |edit|
67
+ edit.main.concat %w{edit_header edit_form}
68
+ edit.form.concat %w{edit_title edit_content}
69
+ edit.layout.concat %w{edit_layout edit_type}
70
+ edit.form_bottom.concat %w{edit_buttons edit_timestamp}
71
+ edit.bottom.concat %w{parts_button}
72
+ end
73
+ part_type.index = Radiant::AdminUI::RegionSet.new do |index|
74
+ index.top.concat %w{}
75
+ index.thead.concat %w{title_header type_header class_header styles_header actions_header}
76
+ index.tbody.concat %w{title_cell type_cell class_cell styles_cell actions_cell}
77
+ index.bottom.concat %w{new_button}
78
+ end
79
+ part_type.new = part_type.edit
80
+ end
81
+ end
82
+
83
+ end