ecm_cms2 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +66 -0
- data/Rakefile +25 -0
- data/app/assets/javascripts/ecm_cms.js.coffee +0 -0
- data/app/assets/stylesheets/ecm_cms.css.less +11 -0
- data/app/controllers/ecm/cms/page_controller.rb +24 -0
- data/app/helpers/ecm/cms_helper.rb +46 -0
- data/app/models/concerns/ecm/cms/navigation_item/properties.rb +29 -0
- data/app/models/ecm/cms/content_box.rb +16 -0
- data/app/models/ecm/cms/folder.rb +20 -0
- data/app/models/ecm/cms/navigation.rb +18 -0
- data/app/models/ecm/cms/navigation_item.rb +88 -0
- data/app/models/ecm/cms/page/content_block.rb +24 -0
- data/app/models/ecm/cms/page.rb +33 -0
- data/app/models/ecm/cms/partial.rb +16 -0
- data/app/models/ecm/cms/template.rb +19 -0
- data/config/locales/ecm.cms.content_box.de.yml +15 -0
- data/config/locales/ecm.cms.content_box.en.yml +15 -0
- data/config/locales/ecm.cms.de.yml +17 -0
- data/config/locales/ecm.cms.en.yml +17 -0
- data/config/locales/ecm.cms.navigation.de.yml +15 -0
- data/config/locales/ecm.cms.navigation.en.yml +15 -0
- data/config/locales/ecm.cms.navigation_item.de.yml +25 -0
- data/config/locales/ecm.cms.navigation_item.en.yml +25 -0
- data/config/locales/ecm.cms.page.content_block.de.yml +14 -0
- data/config/locales/ecm.cms.page.content_block.en.yml +14 -0
- data/config/locales/ecm.cms.page.de.yml +25 -0
- data/config/locales/ecm.cms.page.en.yml +25 -0
- data/config/locales/ecm.cms.partial.de.yml +21 -0
- data/config/locales/ecm.cms.partial.en.yml +21 -0
- data/config/locales/ecm.cms.template.de.yml +21 -0
- data/config/locales/ecm.cms.template.en.yml +21 -0
- data/config/routes.rb +2 -0
- data/db/migrate/001_create_ecm_cms_folders.rb +21 -0
- data/db/migrate/002_create_ecm_cms_pages.rb +19 -0
- data/db/migrate/003_create_ecm_cms_templates.rb +18 -0
- data/db/migrate/004_create_ecm_cms_partials.rb +19 -0
- data/db/migrate/005_create_ecm_cms_navigations.rb +13 -0
- data/db/migrate/006_create_ecm_cms_navigation_items.rb +29 -0
- data/db/migrate/007_create_ecm_cms_content_boxes.rb +9 -0
- data/db/migrate/008_create_ecm_cms_page_content_blocks.rb +15 -0
- data/lib/ecm/cms/action_view/template/handlers/textile.rb +18 -0
- data/lib/ecm/cms/action_view/template_patch.rb +19 -0
- data/lib/ecm/cms/action_view/template_renderer_patch.rb +47 -0
- data/lib/ecm/cms/active_admin/ecm_cms_content_box.rb +33 -0
- data/lib/ecm/cms/active_admin/ecm_cms_navigation_items.rb +68 -0
- data/lib/ecm/cms/active_admin/ecm_cms_navigations.rb +65 -0
- data/lib/ecm/cms/active_admin/ecm_cms_pages.rb +110 -0
- data/lib/ecm/cms/active_admin/ecm_cms_partials.rb +53 -0
- data/lib/ecm/cms/active_admin/ecm_cms_templates.rb +55 -0
- data/lib/ecm/cms/configuration.rb +33 -0
- data/lib/ecm/cms/controller_extensions/page_resolver.rb +13 -0
- data/lib/ecm/cms/controller_extensions/partial_resolver.rb +13 -0
- data/lib/ecm/cms/controller_extensions/template_resolver.rb +13 -0
- data/lib/ecm/cms/database_resolver.rb +101 -0
- data/lib/ecm/cms/database_template.rb +61 -0
- data/lib/ecm/cms/engine.rb +28 -0
- data/lib/ecm/cms/importers/navigation.rb +30 -0
- data/lib/ecm/cms/importers/navigation_item.rb +64 -0
- data/lib/ecm/cms/importers/page.rb +41 -0
- data/lib/ecm/cms/resolvers/ecm/cms/page_resolver.rb +45 -0
- data/lib/ecm/cms/resolvers/ecm/cms/partial_resolver.rb +30 -0
- data/lib/ecm/cms/resolvers/ecm/cms/template_resolver.rb +30 -0
- data/lib/ecm/cms/routing.rb +13 -0
- data/lib/ecm/cms/version.rb +5 -0
- data/lib/ecm_cms2.rb +36 -0
- data/lib/generators/ecm/cms/install/install_generator.rb +15 -0
- data/lib/generators/ecm/cms/install/templates/ecm_cms.rb +37 -0
- data/lib/generators/ecm/cms/locales/locales_generator.rb +38 -0
- data/lib/tasks/ecm_cms_tasks.rake +5 -0
- metadata +498 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
ActiveAdmin.register Ecm::Cms::Partial do
|
|
2
|
+
permit_params(:basename,
|
|
3
|
+
:body,
|
|
4
|
+
:ecm_cms_folder_id,
|
|
5
|
+
:format,
|
|
6
|
+
:handler,
|
|
7
|
+
:layout,
|
|
8
|
+
:locale,
|
|
9
|
+
:pathname) if Rails.version >= '4.0.0'
|
|
10
|
+
# Menu
|
|
11
|
+
menu :parent => Proc.new { I18n.t('ecm.cms.active_admin.menu') }.call
|
|
12
|
+
|
|
13
|
+
form do |f|
|
|
14
|
+
f.inputs do
|
|
15
|
+
f.input :body
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
f.inputs do
|
|
19
|
+
f.input :pathname
|
|
20
|
+
f.input :basename
|
|
21
|
+
f.input :locale, :as => :select, :collection => I18n.available_locales.map(&:to_s)
|
|
22
|
+
f.input :format, :as => :select, :collection => Mime::SET.symbols.map(&:to_s)
|
|
23
|
+
f.input :handler, :as => :select, :collection => ActionView::Template::Handlers.extensions.map(&:to_s)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
f.actions
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
index do
|
|
30
|
+
selectable_column
|
|
31
|
+
column :pathname
|
|
32
|
+
column :filename
|
|
33
|
+
column :created_at
|
|
34
|
+
column :updated_at
|
|
35
|
+
ActiveAdmin::VERSION[0] < '1' ? default_actions : actions
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
show do
|
|
39
|
+
panel Ecm::Cms::Partial.human_attribute_name(:body) do
|
|
40
|
+
pre { ecm_cms_partial.body }
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
sidebar Ecm::Cms::Partial.human_attribute_name(:details), :only => :show do
|
|
45
|
+
attributes_table_for ecm_cms_partial do
|
|
46
|
+
row :pathname
|
|
47
|
+
row :filename
|
|
48
|
+
row :created_at
|
|
49
|
+
row :updated_at
|
|
50
|
+
end
|
|
51
|
+
end # sidebar
|
|
52
|
+
end
|
|
53
|
+
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
ActiveAdmin.register Ecm::Cms::Template do
|
|
2
|
+
permit_params(:basename,
|
|
3
|
+
:body,
|
|
4
|
+
:ecm_cms_folder_id,
|
|
5
|
+
:format,
|
|
6
|
+
:handler,
|
|
7
|
+
:layout,
|
|
8
|
+
:locale,
|
|
9
|
+
:pathname) if Rails.version >= '4.0.0'
|
|
10
|
+
|
|
11
|
+
# Menu
|
|
12
|
+
menu :parent => Proc.new { I18n.t('ecm.cms.active_admin.menu') }.call
|
|
13
|
+
|
|
14
|
+
form do |f|
|
|
15
|
+
f.inputs do
|
|
16
|
+
f.input :body
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
f.inputs do
|
|
20
|
+
f.input :pathname
|
|
21
|
+
f.input :basename
|
|
22
|
+
f.input :locale, :as => :select, :collection => I18n.available_locales.map(&:to_s)
|
|
23
|
+
f.input :format, :as => :select, :collection => Mime::SET.symbols.map(&:to_s)
|
|
24
|
+
f.input :handler, :as => :select, :collection => ActionView::Template::Handlers.extensions.map(&:to_s)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
f.actions
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
index do
|
|
31
|
+
selectable_column
|
|
32
|
+
column :pathname
|
|
33
|
+
column :filename
|
|
34
|
+
column :created_at
|
|
35
|
+
column :updated_at
|
|
36
|
+
ActiveAdmin::VERSION[0] < '1' ? default_actions : actions
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
show do
|
|
40
|
+
panel Ecm::Cms::Template.human_attribute_name(:body) do
|
|
41
|
+
pre { ecm_cms_template.body }
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
sidebar Ecm::Cms::Template.human_attribute_name(:details), :only => :show do
|
|
46
|
+
attributes_table_for ecm_cms_template do
|
|
47
|
+
# row :folder
|
|
48
|
+
row :pathname
|
|
49
|
+
row :filename
|
|
50
|
+
row :created_at
|
|
51
|
+
row :updated_at
|
|
52
|
+
end
|
|
53
|
+
end # sidebar
|
|
54
|
+
end
|
|
55
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'active_support/core_ext/module/delegation'
|
|
2
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
|
3
|
+
require 'active_support/hash_with_indifferent_access'
|
|
4
|
+
|
|
5
|
+
module Ecm
|
|
6
|
+
module Cms
|
|
7
|
+
module Configuration
|
|
8
|
+
def configure
|
|
9
|
+
yield self
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
mattr_accessor :base_controller do
|
|
13
|
+
'ApplicationController'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
mattr_accessor :default_handlers do
|
|
17
|
+
HashWithIndifferentAccess.new()
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
mattr_accessor :site_title do
|
|
21
|
+
''
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
mattr_accessor :navigation_item_properties do
|
|
25
|
+
[]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def default_handlers=(default_handlers)
|
|
29
|
+
@@default_handlers = HashWithIndifferentAccess.new(default_handlers)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Ecm
|
|
2
|
+
module Cms
|
|
3
|
+
module ControllerExtensions
|
|
4
|
+
module PageResolver
|
|
5
|
+
def self.included(base)
|
|
6
|
+
# add the page resolver
|
|
7
|
+
base.prepend_view_path ::Ecm::Cms::PageResolver.instance unless base.view_paths.include?(::Ecm::Cms::PageResolver.instance)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Ecm
|
|
2
|
+
module Cms
|
|
3
|
+
module ControllerExtensions
|
|
4
|
+
module PartialResolver
|
|
5
|
+
def self.included(base)
|
|
6
|
+
# add the partial resolver
|
|
7
|
+
base.prepend_view_path ::Ecm::Cms::PartialResolver.instance unless base.view_paths.include?(::Ecm::Cms::PartialResolver.instance)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Ecm
|
|
2
|
+
module Cms
|
|
3
|
+
module ControllerExtensions
|
|
4
|
+
module TemplateResolver
|
|
5
|
+
def self.included(base)
|
|
6
|
+
# add the template resolver
|
|
7
|
+
base.prepend_view_path ::Ecm::Cms::TemplateResolver.instance unless base.view_paths.include?(::Ecm::Cms::TemplateResolver.instance)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
module Ecm
|
|
2
|
+
module Cms
|
|
3
|
+
module DatabaseResolver
|
|
4
|
+
# Include hook for class methods
|
|
5
|
+
def self.included(base)
|
|
6
|
+
base.extend(ClassMethods)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
# class methods go here
|
|
10
|
+
module ClassMethods
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# instance methods go here
|
|
14
|
+
def find_templates(name, prefix, partial, details)
|
|
15
|
+
return [] unless resolve(partial)
|
|
16
|
+
|
|
17
|
+
conditions = {
|
|
18
|
+
:pathname => assert_slashs(prefix.to_s),
|
|
19
|
+
:basename => normalize_basename(name),
|
|
20
|
+
:locale => normalize_array(details[:locale]).first,
|
|
21
|
+
:format => normalize_array(details[:formats]).first,
|
|
22
|
+
:handler => normalize_array(details[:handlers])
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
format = conditions.delete(:format)
|
|
26
|
+
locale = conditions.delete(:locale)
|
|
27
|
+
|
|
28
|
+
query = self.template_class.constantize.where(conditions)
|
|
29
|
+
|
|
30
|
+
# 2) Check for templates with the given format or format is nil
|
|
31
|
+
query = query.where(["format = ? OR format = ''", format])
|
|
32
|
+
|
|
33
|
+
# 3) Ensure templates with format come first
|
|
34
|
+
query = query.order("format DESC")
|
|
35
|
+
|
|
36
|
+
# 4) Check for templates with the given locale or locale is nil
|
|
37
|
+
query = query.where(["locale = ? OR locale = ''", locale])
|
|
38
|
+
|
|
39
|
+
# 5) Ensure templates with locale come first
|
|
40
|
+
query = query.order("locale DESC")
|
|
41
|
+
|
|
42
|
+
# 6) Now trigger the query passing on conditions to initialization
|
|
43
|
+
query.map do |record|
|
|
44
|
+
initialize_template(record, details)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Initialize an ActionView::Template object based on the record found.
|
|
49
|
+
def initialize_template(record, details)
|
|
50
|
+
source = build_source(record)
|
|
51
|
+
identifier = "#{record.class} - #{record.id} - #{record.pathname}#{record.basename}"
|
|
52
|
+
handler = ::ActionView::Template.registered_template_handler(record.handler)
|
|
53
|
+
|
|
54
|
+
# 5) Check for the record.format, if none is given, try the template
|
|
55
|
+
# handler format and fallback to the one given on conditions
|
|
56
|
+
format = record.format && Mime[record.format]
|
|
57
|
+
format ||= handler.default_format if handler.respond_to?(:default_format)
|
|
58
|
+
format ||= details[:formats]
|
|
59
|
+
|
|
60
|
+
details = {
|
|
61
|
+
:format => format,
|
|
62
|
+
:updated_at => record.updated_at,
|
|
63
|
+
:virtual_path => "#{record.pathname}#{record.basename}"
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
details[:layout] = record.layout if record.respond_to?(:layout) && record.layout.present?
|
|
67
|
+
|
|
68
|
+
::ActionView::Template.new(source, identifier, handler, details)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def assert_slashs(prefix)
|
|
72
|
+
output = prefix.dup
|
|
73
|
+
output << '/' unless output.end_with?('/')
|
|
74
|
+
output = '/' << output unless output.start_with?('/')
|
|
75
|
+
return output
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Normalize arrays by converting all symbols to strings.
|
|
79
|
+
def normalize_array(array)
|
|
80
|
+
array.map(&:to_s)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def build_source
|
|
84
|
+
raise "call to abstract method #build_source"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def normalize_basename(basename)
|
|
88
|
+
raise "call to abstract method #normalize_basename"
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def resolve(partial_flag)
|
|
92
|
+
raise "call to abstract method #resolve"
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def template_class
|
|
96
|
+
raise "call to abstract method #template_class"
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
module Ecm
|
|
2
|
+
module Cms
|
|
3
|
+
module DatabaseTemplate
|
|
4
|
+
def self.included(base)
|
|
5
|
+
base.extend(ClassMethods)
|
|
6
|
+
|
|
7
|
+
# associations
|
|
8
|
+
base.belongs_to :ecm_cms_folder,
|
|
9
|
+
:class_name => 'Ecm::Cms::Folder',
|
|
10
|
+
:foreign_key => 'ecm_cms_folder_id'
|
|
11
|
+
|
|
12
|
+
# callbacks
|
|
13
|
+
base.after_initialize :set_defaults
|
|
14
|
+
base.before_validation :assert_trailing_slash_on_pathname
|
|
15
|
+
base.after_save :clear_resolver_cache
|
|
16
|
+
|
|
17
|
+
# validations
|
|
18
|
+
base.validates :basename, :presence => true,
|
|
19
|
+
:uniqueness => { :scope => [ :pathname, :locale, :format, :handler ] }
|
|
20
|
+
base.validates :handler, :inclusion => ActionView::Template::Handlers.extensions.map(&:to_s)
|
|
21
|
+
base.validates :locale, :inclusion => I18n.available_locales.map(&:to_s),
|
|
22
|
+
:allow_nil => true,
|
|
23
|
+
:allow_blank => true
|
|
24
|
+
base.validates :format, :inclusion => Mime::SET.symbols.map(&:to_s),
|
|
25
|
+
:allow_nil => true,
|
|
26
|
+
:allow_blank => true
|
|
27
|
+
base.validates :pathname, :presence => true
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
module ClassMethods
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def filename
|
|
34
|
+
filename = basename.dup
|
|
35
|
+
filename << ".#{locale}" if locale.present?
|
|
36
|
+
filename << ".#{format}" if format.present?
|
|
37
|
+
filename << ".#{handler}" if handler.present?
|
|
38
|
+
filename
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def assert_trailing_slash_on_pathname
|
|
44
|
+
self.pathname = '/' and return if self.pathname.blank?
|
|
45
|
+
self.pathname << '/' unless self.pathname.end_with?('/')
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def clear_resolver_cache
|
|
49
|
+
Ecm::Cms::PageResolver.instance.clear_cache
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def set_defaults
|
|
53
|
+
if self.new_record?
|
|
54
|
+
self.locale ||= I18n.default_locale.to_s
|
|
55
|
+
self.handler ||= Ecm::Cms::Configuration.default_handlers[:page].to_s
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Ecm
|
|
2
|
+
module Cms
|
|
3
|
+
class Engine < ::Rails::Engine
|
|
4
|
+
config.app_generators do |c|
|
|
5
|
+
c.test_framework :rspec, :fixture => true,
|
|
6
|
+
:fixture_replacement => nil
|
|
7
|
+
|
|
8
|
+
c.integration_tool :rspec
|
|
9
|
+
c.performance_tool :rspec
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# active admin
|
|
13
|
+
initializer :ecm_cms_engine do
|
|
14
|
+
::ActiveAdmin.setup do |config|
|
|
15
|
+
config.load_paths += Dir[File.dirname(__FILE__) + '/active_admin']
|
|
16
|
+
config.register_stylesheet 'ecm_cms.css'
|
|
17
|
+
config.register_javascript 'ecm_cms.js'
|
|
18
|
+
end
|
|
19
|
+
end if defined?(::ActiveAdmin)
|
|
20
|
+
|
|
21
|
+
initializer "ecm_cms.asset_pipeline" do |app|
|
|
22
|
+
app.config.assets.precompile << 'ecm_cms.js'
|
|
23
|
+
app.config.assets.precompile << 'ecm_cms.css'
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Ecm
|
|
2
|
+
module Cms
|
|
3
|
+
module Importers
|
|
4
|
+
class Navigation
|
|
5
|
+
def initialize(yaml, option = {})
|
|
6
|
+
@navigations = nil
|
|
7
|
+
@yaml = YAML.load(yaml)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def build_navigations
|
|
11
|
+
navigations = []
|
|
12
|
+
@yaml.each do |navigation_data|
|
|
13
|
+
navigation = Ecm::Cms::Navigation.new(navigation_data)
|
|
14
|
+
navigations << navigation
|
|
15
|
+
end if @yaml.respond_to?(:each)
|
|
16
|
+
navigations
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def navigations
|
|
20
|
+
@navigations ||= build_navigations
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def yaml
|
|
24
|
+
@yaml
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
module Ecm
|
|
2
|
+
module Cms
|
|
3
|
+
module Importers
|
|
4
|
+
class NavigationItem
|
|
5
|
+
def initialize(yaml, option = {})
|
|
6
|
+
@navigation_items = nil
|
|
7
|
+
@yaml = YAML.load(yaml)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def navigation_items
|
|
11
|
+
@navigation_items ||= create_navigation_items
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def create_navigation_items
|
|
17
|
+
built_navigation_items = []
|
|
18
|
+
@yaml.each do |navigation_locale, navigation|
|
|
19
|
+
navigation.each do |navigation_name, navigation_items_attributes|
|
|
20
|
+
n = find_or_create_navigation(navigation_locale, navigation_name)
|
|
21
|
+
built_navigation_items << create_navigation_items_for_navigation(n, navigation_items_attributes)
|
|
22
|
+
end if navigation_locale.respond_to?(:each)
|
|
23
|
+
end if @yaml.respond_to?(:each)
|
|
24
|
+
built_navigation_items.flatten
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def create_navigation_items_for_navigation(navigation, navigation_items_attributes)
|
|
28
|
+
built_navigation_items = []
|
|
29
|
+
navigation_items_attributes.each do |navigation_item_attributes|
|
|
30
|
+
ni = create_navigation_item(navigation_item_attributes, navigation)
|
|
31
|
+
built_navigation_items << ni
|
|
32
|
+
end
|
|
33
|
+
return built_navigation_items
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def create_navigation_item(navigation_item_attributes, navigation)
|
|
37
|
+
subitems = navigation_item_attributes.delete('subitems')
|
|
38
|
+
|
|
39
|
+
ni = Ecm::Cms::NavigationItem.new(navigation_item_attributes)
|
|
40
|
+
ni.ecm_cms_navigation = navigation
|
|
41
|
+
ni.save!
|
|
42
|
+
|
|
43
|
+
subitems.each do |subitem_attributes|
|
|
44
|
+
subitem_attributes['parent'] = ni
|
|
45
|
+
create_navigation_item(subitem_attributes, navigation)
|
|
46
|
+
end if subitems.respond_to?(:each)
|
|
47
|
+
|
|
48
|
+
ni
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def find_or_create_navigation(navigation_locale, navigation_name)
|
|
52
|
+
navigation = Ecm::Cms::Navigation.where(:locale => navigation_locale, :name => navigation_name).first
|
|
53
|
+
navigation = Ecm::Cms::Navigation.create!(:locale => navigation_locale, :name => navigation_name) if navigation.nil?
|
|
54
|
+
navigation
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def yaml
|
|
58
|
+
@yaml
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module Ecm
|
|
2
|
+
module Cms
|
|
3
|
+
module Importers
|
|
4
|
+
class Page
|
|
5
|
+
def initialize(yaml, option = {})
|
|
6
|
+
@pages = nil
|
|
7
|
+
@yaml = YAML.load(yaml)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def build_pages
|
|
11
|
+
pages = []
|
|
12
|
+
@yaml.each do |page_data|
|
|
13
|
+
navigation_items = extract_navigation_items(page_data.delete('navigation_items'))
|
|
14
|
+
page = Ecm::Cms::Page.new(page_data)
|
|
15
|
+
page.ecm_cms_navigation_item_ids = navigation_items.map(&:id)
|
|
16
|
+
pages << page
|
|
17
|
+
end if @yaml.respond_to?(:each)
|
|
18
|
+
pages
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def extract_navigation_items(navigation_item_data)
|
|
22
|
+
navigation_items = []
|
|
23
|
+
navigation_item_data.each do |nid|
|
|
24
|
+
navigation = Ecm::Cms::Navigation.where(:locale => nid['navigation_locale'], :name => nid['navigation_name']).first
|
|
25
|
+
navigation_items << navigation.ecm_cms_navigation_items.where(:name => nid['name']).first if navigation.respond_to?(:ecm_cms_navigation_items)
|
|
26
|
+
end
|
|
27
|
+
navigation_items
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def pages
|
|
31
|
+
@pages ||= build_pages
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def yaml
|
|
35
|
+
@yaml
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'ecm/cms/database_resolver'
|
|
2
|
+
|
|
3
|
+
module Ecm
|
|
4
|
+
module Cms
|
|
5
|
+
class PageResolver < ::ActionView::Resolver
|
|
6
|
+
require 'singleton'
|
|
7
|
+
include Singleton
|
|
8
|
+
|
|
9
|
+
# add shared behaviour for database backed templates
|
|
10
|
+
include Ecm::Cms::DatabaseResolver
|
|
11
|
+
|
|
12
|
+
def build_source(record)
|
|
13
|
+
output = ''
|
|
14
|
+
record.ecm_cms_page_content_blocks.each do |content_block|
|
|
15
|
+
# rendered_body = RedCloth.new(begin;content_block.body;end).to_html.html_safe
|
|
16
|
+
rendered_body = RedCloth.new(content_block.body).to_html
|
|
17
|
+
output << "<% content_for :#{content_block.content_box_name} do %>#{rendered_body}<% end %>"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
content_for_title = "<% content_for :title do %>#{record.title}<% end %>"
|
|
21
|
+
content_for_meta_description = "<% content_for :meta_description do %>#{record.meta_description}<% end %>"
|
|
22
|
+
output << content_for_title << content_for_meta_description
|
|
23
|
+
|
|
24
|
+
unless record.body.nil?
|
|
25
|
+
output << record.body
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
return output
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def normalize_basename(basename)
|
|
32
|
+
basename
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def resolve(partial_flag)
|
|
36
|
+
!partial_flag
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def template_class
|
|
40
|
+
'Ecm::Cms::Page'
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'ecm/cms/database_resolver'
|
|
2
|
+
|
|
3
|
+
module Ecm
|
|
4
|
+
module Cms
|
|
5
|
+
class PartialResolver < ::ActionView::Resolver
|
|
6
|
+
require 'singleton'
|
|
7
|
+
include Singleton
|
|
8
|
+
|
|
9
|
+
# add shared behaviour for database backed templates
|
|
10
|
+
include Ecm::Cms::DatabaseResolver
|
|
11
|
+
|
|
12
|
+
def template_class
|
|
13
|
+
'Ecm::Cms::Partial'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def build_source(record)
|
|
17
|
+
record.body
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def normalize_basename(basename)
|
|
21
|
+
'_' << basename
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def resolve(partial_flag)
|
|
25
|
+
partial_flag
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'ecm/cms/database_resolver'
|
|
2
|
+
|
|
3
|
+
module Ecm
|
|
4
|
+
module Cms
|
|
5
|
+
class TemplateResolver < ::ActionView::Resolver
|
|
6
|
+
require 'singleton'
|
|
7
|
+
include Singleton
|
|
8
|
+
|
|
9
|
+
# add shared behaviour for database backed templates
|
|
10
|
+
include Ecm::Cms::DatabaseResolver
|
|
11
|
+
|
|
12
|
+
def build_source(record)
|
|
13
|
+
record.body
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def normalize_basename(basename)
|
|
17
|
+
basename
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def resolve(partial_flag)
|
|
21
|
+
!partial_flag
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def template_class
|
|
25
|
+
'Ecm::Cms::Template'
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Ecm
|
|
2
|
+
module Cms
|
|
3
|
+
class Routing
|
|
4
|
+
def self.routes(router, options = {})
|
|
5
|
+
options.reverse_merge!({})
|
|
6
|
+
|
|
7
|
+
router.get "/*page", :to => "ecm/cms/page#respond", :as => :page
|
|
8
|
+
router.get '/' => "ecm/cms/page#respond", :page => 'home' #, :as => :root
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
data/lib/ecm_cms2.rb
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'ecm/cms/action_view/template/handlers/textile'
|
|
2
|
+
require 'ecm/cms/action_view/template_patch'
|
|
3
|
+
require 'ecm/cms/action_view/template_renderer_patch'
|
|
4
|
+
|
|
5
|
+
require 'awesome_nested_set'
|
|
6
|
+
require 'redcloth'
|
|
7
|
+
require 'simple-navigation'
|
|
8
|
+
require 'simple-navigation-bootstrap'
|
|
9
|
+
require 'active_admin-awesome_nested_set'
|
|
10
|
+
|
|
11
|
+
require 'ecm/cms/engine'
|
|
12
|
+
require 'ecm/cms/configuration'
|
|
13
|
+
require 'ecm/cms/routing'
|
|
14
|
+
|
|
15
|
+
require 'ecm/cms/database_template'
|
|
16
|
+
|
|
17
|
+
require 'ecm/cms/resolvers/ecm/cms/page_resolver'
|
|
18
|
+
require 'ecm/cms/resolvers/ecm/cms/template_resolver'
|
|
19
|
+
require 'ecm/cms/resolvers/ecm/cms/partial_resolver'
|
|
20
|
+
|
|
21
|
+
require 'ecm/cms/controller_extensions/page_resolver'
|
|
22
|
+
require 'ecm/cms/controller_extensions/partial_resolver'
|
|
23
|
+
require 'ecm/cms/controller_extensions/template_resolver'
|
|
24
|
+
|
|
25
|
+
::ActionView::Template.register_template_handler :textile, ::ActionView::Template::Handlers::Textile.new
|
|
26
|
+
|
|
27
|
+
module Ecm
|
|
28
|
+
module Cms
|
|
29
|
+
extend Configuration
|
|
30
|
+
|
|
31
|
+
def self.table_name_prefix
|
|
32
|
+
'ecm_cms_'
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|