ecm_cms2 1.1.1 → 2.0.2
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 +4 -4
- data/README.rdoc +19 -1
- data/{lib/ecm/cms/active_admin → app/admin}/ecm_cms_content_box.rb +5 -5
- data/{lib/ecm/cms/active_admin → app/admin}/ecm_cms_navigation_items.rb +6 -6
- data/{lib/ecm/cms/active_admin → app/admin}/ecm_cms_navigations.rb +11 -12
- data/{lib/ecm/cms/active_admin → app/admin}/ecm_cms_pages.rb +20 -22
- data/{lib/ecm/cms/active_admin → app/admin}/ecm_cms_partials.rb +6 -7
- data/{lib/ecm/cms/active_admin → app/admin}/ecm_cms_templates.rb +7 -8
- data/app/controllers/ecm/cms/page_controller.rb +13 -8
- data/app/helpers/ecm/cms_helper.rb +8 -4
- data/app/models/concerns/model/ecm/cms/navigation_item/properties_concern.rb +25 -0
- data/app/models/ecm/cms/content_box.rb +5 -8
- data/app/models/ecm/cms/folder.rb +11 -12
- data/app/models/ecm/cms/navigation.rb +10 -9
- data/app/models/ecm/cms/navigation_item.rb +21 -20
- data/app/models/ecm/cms/page/content_block.rb +7 -8
- data/app/models/ecm/cms/page.rb +11 -11
- data/app/models/ecm/cms/partial.rb +2 -3
- data/app/models/ecm/cms/template.rb +4 -5
- data/app/services/ecm/cms/add_homepages_service.rb +61 -0
- data/app/services/ecm/cms/import_partials_service.rb +37 -32
- data/config/locales/ecm.cms.de.yml +3 -0
- data/config/locales/ecm.cms.navigation.de.yml +1 -0
- data/config/locales/ecm.cms.navigation.en.yml +1 -0
- data/config/locales/ecm.cms.page.de.yml +1 -0
- data/config/locales/ecm.cms.page.en.yml +1 -0
- data/db/migrate/001_create_ecm_cms_folders.rb +2 -2
- data/db/migrate/004_create_ecm_cms_partials.rb +1 -1
- data/db/migrate/006_create_ecm_cms_navigation_items.rb +1 -1
- data/lib/ecm/cms/action_view/template/handlers/textile.rb +0 -3
- data/lib/ecm/cms/action_view/template_patch.rb +2 -3
- data/lib/ecm/cms/action_view/template_renderer_patch.rb +4 -6
- data/lib/ecm/cms/configuration.rb +1 -1
- data/lib/ecm/cms/controller_extensions/page_resolver.rb +0 -1
- data/lib/ecm/cms/controller_extensions/partial_resolver.rb +0 -1
- data/lib/ecm/cms/controller_extensions/template_resolver.rb +0 -1
- data/lib/ecm/cms/database_resolver.rb +21 -22
- data/lib/ecm/cms/database_template.rb +17 -18
- data/lib/ecm/cms/engine.rb +5 -7
- data/lib/ecm/cms/importers/navigation.rb +2 -5
- data/lib/ecm/cms/importers/navigation_item.rb +6 -9
- data/lib/ecm/cms/importers/page.rb +4 -7
- data/lib/ecm/cms/resolvers/ecm/cms/page_resolver.rb +3 -6
- data/lib/ecm/cms/resolvers/ecm/cms/partial_resolver.rb +0 -1
- data/lib/ecm/cms/resolvers/ecm/cms/template_resolver.rb +0 -1
- data/lib/ecm/cms/routing.rb +2 -3
- data/lib/ecm/cms/version.rb +1 -1
- data/lib/ecm_cms2.rb +1 -2
- data/lib/generators/ecm/cms/install/install_generator.rb +6 -6
- data/lib/generators/ecm/cms/install/templates/ecm_cms.rb +6 -6
- data/lib/generators/ecm/cms/locales/locales_generator.rb +19 -18
- data/lib/tasks/ecm_cms_tasks.rake +2 -3
- metadata +33 -25
- data/app/models/concerns/ecm/cms/navigation_item/properties.rb +0 -29
@@ -1,19 +1,19 @@
|
|
1
1
|
module Ecm::Cms
|
2
2
|
class Page::ContentBlock < ActiveRecord::Base
|
3
3
|
# associations
|
4
|
-
belongs_to :ecm_cms_content_box, :
|
5
|
-
:
|
6
|
-
belongs_to :ecm_cms_page, :
|
7
|
-
:
|
4
|
+
belongs_to :ecm_cms_content_box, class_name: 'ContentBox',
|
5
|
+
foreign_key: 'ecm_cms_content_box_id'
|
6
|
+
belongs_to :ecm_cms_page, class_name: 'Ecm::Cms::Page',
|
7
|
+
foreign_key: 'ecm_cms_page_id'
|
8
8
|
|
9
9
|
# attributes
|
10
10
|
attr_accessible(:body,
|
11
11
|
:ecm_cms_content_box_id) if Rails.version < '4.0.0'
|
12
12
|
|
13
13
|
# validations
|
14
|
-
validates :body, :
|
15
|
-
validates :ecm_cms_content_box, :
|
16
|
-
validates :ecm_cms_page, :
|
14
|
+
validates :body, presence: true
|
15
|
+
validates :ecm_cms_content_box, presence: true
|
16
|
+
validates :ecm_cms_page, presence: true
|
17
17
|
# validates :ecm_cms_page, :existence => true
|
18
18
|
|
19
19
|
def content_box_name
|
@@ -21,4 +21,3 @@ module Ecm::Cms
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
data/app/models/ecm/cms/page.rb
CHANGED
@@ -5,29 +5,29 @@ module Ecm::Cms
|
|
5
5
|
|
6
6
|
# associations
|
7
7
|
has_many :ecm_cms_navigation_items,
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
8
|
+
class_name: 'NavigationItem',
|
9
|
+
dependent: :nullify,
|
10
|
+
foreign_key: 'ecm_cms_page_id'
|
11
11
|
has_many :ecm_cms_page_content_blocks,
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
12
|
+
class_name: 'Ecm::Cms::Page::ContentBlock',
|
13
|
+
dependent: :destroy,
|
14
|
+
foreign_key: 'ecm_cms_page_id',
|
15
|
+
inverse_of: :ecm_cms_page
|
16
16
|
|
17
|
-
accepts_nested_attributes_for :ecm_cms_page_content_blocks, :
|
17
|
+
accepts_nested_attributes_for :ecm_cms_page_content_blocks, allow_destroy: true
|
18
18
|
|
19
19
|
# callbacks
|
20
20
|
after_save :touch_navigation_items # , :if => Proc.new { |page| page.locale_changed? || page.pathname_changed? || page.basename_changed? }
|
21
21
|
|
22
22
|
# validations
|
23
|
-
validates :title, :
|
23
|
+
validates :title, presence: true
|
24
24
|
|
25
25
|
def home_page?
|
26
|
-
|
26
|
+
pathname == '/' && basename == 'home'
|
27
27
|
end
|
28
28
|
|
29
29
|
def touch_navigation_items
|
30
|
-
|
30
|
+
ecm_cms_navigation_items.map(&:update_url_form_page!)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -5,12 +5,11 @@ class Ecm::Cms::Partial < ActiveRecord::Base
|
|
5
5
|
include Ecm::Cms::DatabaseTemplate
|
6
6
|
|
7
7
|
# callbacks
|
8
|
-
before_validation :ensure_basename_starts_with_underscore, :
|
8
|
+
before_validation :ensure_basename_starts_with_underscore, if: proc { |t| t.basename.present? }
|
9
9
|
|
10
10
|
private
|
11
11
|
|
12
12
|
def ensure_basename_starts_with_underscore
|
13
|
-
|
13
|
+
basename.insert(0, '_') unless basename.start_with?('_')
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
@@ -4,16 +4,15 @@ class Ecm::Cms::Template < ActiveRecord::Base
|
|
4
4
|
|
5
5
|
# associations
|
6
6
|
belongs_to :ecm_cms_folder,
|
7
|
-
:
|
8
|
-
:
|
7
|
+
class_name: 'Ecm::Cms::Folder',
|
8
|
+
foreign_key: 'ecm_cms_folder_id'
|
9
9
|
|
10
10
|
# callbacks
|
11
|
-
before_validation :ensure_basename_starts_without_underscore, :
|
11
|
+
before_validation :ensure_basename_starts_without_underscore, if: proc { |t| t.basename.present? }
|
12
12
|
|
13
13
|
private
|
14
14
|
|
15
15
|
def ensure_basename_starts_without_underscore
|
16
|
-
|
16
|
+
basename.slice!(0) if basename.start_with?('_')
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Ecm::Cms
|
2
|
+
class AddHomepagesService < Itsf::Services::V2::Service::Base
|
3
|
+
attr_accessor :locales
|
4
|
+
|
5
|
+
validates :locales, presence: true
|
6
|
+
|
7
|
+
def initialize(attributes = {})
|
8
|
+
attributes.reverse_merge!({ locales: I18n.available_locales })
|
9
|
+
attributes[:locales].try(:reject!, &:blank?)
|
10
|
+
|
11
|
+
super(attributes)
|
12
|
+
|
13
|
+
@all_pages = []
|
14
|
+
@already_existent_pages = []
|
15
|
+
@failed_pages = []
|
16
|
+
@created_pages = []
|
17
|
+
end
|
18
|
+
|
19
|
+
def do_work
|
20
|
+
say "Environment: #{Rails.env}"
|
21
|
+
respond unless valid?
|
22
|
+
create_homepages
|
23
|
+
warn("Skipped #{@already_existent_pages.size} already existent pages for locales: #{@already_existent_pages.map(&:locale).join(', ')}", indent: 1) if @already_existent_pages.any?
|
24
|
+
info("Added #{@created_pages.size} new home pages for locales: #{@created_pages.map(&:locale).join(', ')}", indent: 1)
|
25
|
+
warn("Failed adding #{@failed_pages.size} new home pages for locales: #{@failed_pages.map(&:locale).join(', ')}", indent: 1) if @failed_pages.any?
|
26
|
+
respond
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def create_homepages
|
32
|
+
@all_pages = @locales.collect do |locale|
|
33
|
+
say "Adding homepage for locale #{locale}", indent: 1
|
34
|
+
page = Ecm::Cms::Page.where(locale: locale, pathname: '/', basename: 'home', handler: 'textile').first_or_initialize
|
35
|
+
unless page.new_record?
|
36
|
+
@already_existent_pages << page
|
37
|
+
warn "already exists", indent: 2
|
38
|
+
next page
|
39
|
+
end
|
40
|
+
page.tap do |page|
|
41
|
+
page.title = "Homepage (#{locale})"
|
42
|
+
page.meta_description = 'home'
|
43
|
+
page.body = "h1. Homepage (#{locale})"
|
44
|
+
page.pathname = '/'
|
45
|
+
page.basename = 'home'
|
46
|
+
page.locale = locale
|
47
|
+
page.handler = 'textile'
|
48
|
+
end
|
49
|
+
if page.save
|
50
|
+
@created_pages << page
|
51
|
+
info "done", indent: 1
|
52
|
+
else
|
53
|
+
@failed_pages << page
|
54
|
+
errors << page.errors
|
55
|
+
warn "could not save page. errors: #{page.errors.full_messages.to_sentence}"
|
56
|
+
end
|
57
|
+
page
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Ecm::Cms
|
2
|
-
class ImportPartialsService
|
3
|
-
|
2
|
+
class ImportPartialsService < Itsf::Services::V2::Service::Base
|
4
3
|
class PartialInFileSystem
|
5
4
|
def initialize(filename, view_path)
|
6
5
|
@filename = filename
|
@@ -8,7 +7,7 @@ module Ecm::Cms
|
|
8
7
|
end
|
9
8
|
|
10
9
|
def pathname
|
11
|
-
@pathname ||= File.dirname(relative_filename)
|
10
|
+
@pathname ||= "#{File.dirname(relative_filename)}/"
|
12
11
|
end
|
13
12
|
|
14
13
|
def basename
|
@@ -19,26 +18,18 @@ module Ecm::Cms
|
|
19
18
|
locale = File.basename(relative_filename).split('.')[-3]
|
20
19
|
if I18n.available_locales.map(&:to_s).include?(locale)
|
21
20
|
@locale ||= locale
|
22
|
-
else
|
23
|
-
nil
|
24
21
|
end
|
25
22
|
end
|
26
23
|
|
27
24
|
def format
|
28
25
|
format = File.basename(relative_filename).split('.')[-2]
|
29
|
-
if Mime::SET.symbols.map(&:to_s).include?(format)
|
30
|
-
@format ||= format
|
31
|
-
else
|
32
|
-
nil
|
33
|
-
end
|
26
|
+
@format ||= format if Mime::SET.symbols.map(&:to_s).include?(format)
|
34
27
|
end
|
35
28
|
|
36
29
|
def handler
|
37
30
|
handler = File.basename(relative_filename).split('.').last
|
38
31
|
if ActionView::Template::Handlers.extensions.map(&:to_s).include?(handler)
|
39
32
|
@handler ||= handler
|
40
|
-
else
|
41
|
-
nil
|
42
33
|
end
|
43
34
|
end
|
44
35
|
|
@@ -67,38 +58,56 @@ module Ecm::Cms
|
|
67
58
|
@relative_filename ||= @filename.gsub(view_path.to_s, '')
|
68
59
|
end
|
69
60
|
|
70
|
-
|
71
|
-
@view_path
|
72
|
-
end
|
61
|
+
attr_reader :view_path
|
73
62
|
end
|
74
63
|
|
75
|
-
|
76
|
-
new(*args).do_work
|
77
|
-
end
|
64
|
+
attr_accessor :view_path, :force
|
78
65
|
|
79
|
-
|
80
|
-
|
81
|
-
|
66
|
+
validates :view_path, presence: true
|
67
|
+
|
68
|
+
def initialize(attributes = {})
|
69
|
+
attributes.reverse_merge!(view_path: Rails.root.join(*%w(app views)), force: false)
|
70
|
+
super(attributes)
|
82
71
|
end
|
83
72
|
|
84
|
-
def do_work
|
85
|
-
|
73
|
+
def do_work
|
74
|
+
info "Environment: #{Rails.env}"
|
75
|
+
respond unless valid?
|
86
76
|
@partials = load_partials
|
87
77
|
partials_count = @partials.size
|
88
|
-
|
78
|
+
info "Processing #{partials_count} partials in #{view_path}:"
|
89
79
|
@partials.each_with_index do |partial, index|
|
90
|
-
|
91
|
-
|
80
|
+
info " (#{index + 1}/#{partials_count}) #{partial.human}"
|
81
|
+
attributes_hash = partial.to_partial_attributes_hash
|
82
|
+
partial = force ? find_or_initialize_partial(attributes_hash) : initialize_partial(attributes_hash)
|
83
|
+
new_record = partial.new_record?
|
84
|
+
partial.attributes = attributes_hash
|
92
85
|
if partial.save
|
93
|
-
|
86
|
+
info " #{new_record ? 'Created' : 'Updated'} #{partial.human}"
|
94
87
|
else
|
95
|
-
|
88
|
+
info " Could not #{new_record ? 'create' : 'update'} #{partial.human}. Errors: #{partial.errors.full_messages.to_sentence}"
|
96
89
|
end
|
97
90
|
end
|
91
|
+
|
92
|
+
respond
|
93
|
+
end
|
94
|
+
|
95
|
+
def force=(value)
|
96
|
+
@force = ActiveRecord::Type::Boolean.new.type_cast_from_database(value)
|
98
97
|
end
|
99
98
|
|
100
99
|
private
|
101
100
|
|
101
|
+
def find_or_initialize_partial(attributes)
|
102
|
+
attributes = attributes.dup
|
103
|
+
attributes.compact!.delete(:body)
|
104
|
+
Partial.where(attributes).first_or_initialize
|
105
|
+
end
|
106
|
+
|
107
|
+
def initialize_partial(attributes)
|
108
|
+
Partial.new(attributes)
|
109
|
+
end
|
110
|
+
|
102
111
|
def load_partials
|
103
112
|
load_partials_absolute.collect { |file| PartialInFileSystem.new(file, view_path) }
|
104
113
|
end
|
@@ -106,9 +115,5 @@ module Ecm::Cms
|
|
106
115
|
def load_partials_absolute
|
107
116
|
Dir.glob("#{view_path}/**/_*.*")
|
108
117
|
end
|
109
|
-
|
110
|
-
def view_path
|
111
|
-
@view_path
|
112
|
-
end
|
113
118
|
end
|
114
119
|
end
|
@@ -5,8 +5,8 @@ class CreateEcmCmsFolders < ActiveRecord::Migration
|
|
5
5
|
t.string :pathname
|
6
6
|
|
7
7
|
# associations
|
8
|
-
t.integer :children_count, :
|
9
|
-
t.integer :ecm_cms_templates_count, :
|
8
|
+
t.integer :children_count, default: 0, null: false
|
9
|
+
t.integer :ecm_cms_templates_count, default: 0, null: false
|
10
10
|
|
11
11
|
# awesome nested set
|
12
12
|
t.references :parent
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module ActionView::Template::Handlers
|
2
2
|
class Textile
|
3
|
-
|
4
3
|
class_attribute :default_format
|
5
4
|
self.default_format = Mime::HTML
|
6
5
|
|
@@ -12,7 +11,5 @@ module ActionView::Template::Handlers
|
|
12
11
|
compiled_source = erb_handler.call(template)
|
13
12
|
"RedCloth.new(begin;#{compiled_source};end).to_html.html_safe"
|
14
13
|
end
|
15
|
-
|
16
14
|
end
|
17
15
|
end
|
18
|
-
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module ActionView
|
2
2
|
module TemplatePatch
|
3
|
-
def self.included
|
3
|
+
def self.included(base)
|
4
4
|
base.class_eval do
|
5
5
|
attr_accessor :layout
|
6
6
|
|
7
7
|
alias_method :original_initialize, :initialize
|
8
8
|
|
9
9
|
def initialize(source, identifier, handler, details)
|
10
|
-
@layout = details[:layout] if details.
|
10
|
+
@layout = details[:layout] if details.key?(:layout)
|
11
11
|
original_initialize(source, identifier, handler, details)
|
12
12
|
end
|
13
13
|
end
|
@@ -16,4 +16,3 @@ module ActionView
|
|
16
16
|
end
|
17
17
|
|
18
18
|
ActionView::Template.send(:include, ActionView::TemplatePatch)
|
19
|
-
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module ActionView
|
2
2
|
module TemplateRendererPatch
|
3
|
-
def self.included
|
3
|
+
def self.included(base)
|
4
4
|
base.class_eval do
|
5
5
|
alias_method :original_render, :render
|
6
6
|
if Rails::VERSION::MAJOR < 4
|
@@ -26,14 +26,14 @@ module ActionView
|
|
26
26
|
@view = context
|
27
27
|
@details = extract_details(options)
|
28
28
|
template = determine_template(options)
|
29
|
-
|
29
|
+
|
30
30
|
prepend_formats(template.formats)
|
31
|
-
|
31
|
+
|
32
32
|
@lookup_context.rendered_format ||= (template.formats.first || formats.first)
|
33
33
|
|
34
34
|
layout = template.layout if template.respond_to?(:layout)
|
35
35
|
layout ||= options[:layout]
|
36
|
-
|
36
|
+
|
37
37
|
render_template(template, layout, options[:locals])
|
38
38
|
end
|
39
39
|
end
|
@@ -42,6 +42,4 @@ module ActionView
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
45
|
ActionView::TemplateRenderer.send(:include, ActionView::TemplateRendererPatch)
|
47
|
-
|
@@ -15,29 +15,29 @@ module Ecm
|
|
15
15
|
return [] unless resolve(partial)
|
16
16
|
|
17
17
|
conditions = {
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
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
23
|
}
|
24
24
|
|
25
25
|
format = conditions.delete(:format)
|
26
26
|
locale = conditions.delete(:locale)
|
27
|
-
|
28
|
-
query =
|
27
|
+
|
28
|
+
query = template_class.constantize.where(conditions)
|
29
29
|
|
30
30
|
# 2) Check for templates with the given format or format is nil
|
31
|
-
query = query.where(["format = ? OR format = ''", format])
|
31
|
+
query = query.where(["format = ? OR format = '' OR format IS NULL", format])
|
32
32
|
|
33
33
|
# 3) Ensure templates with format come first
|
34
|
-
query = query.order(
|
34
|
+
query = query.order('format DESC')
|
35
35
|
|
36
36
|
# 4) Check for templates with the given locale or locale is nil
|
37
|
-
query = query.where(["locale = ? OR locale = ''", locale])
|
37
|
+
query = query.where(["locale = ? OR locale = '' OR locale IS NULL", locale])
|
38
38
|
|
39
39
|
# 5) Ensure templates with locale come first
|
40
|
-
query = query.order(
|
40
|
+
query = query.order('locale DESC')
|
41
41
|
|
42
42
|
# 6) Now trigger the query passing on conditions to initialization
|
43
43
|
query.map do |record|
|
@@ -58,9 +58,9 @@ module Ecm
|
|
58
58
|
format ||= details[:formats]
|
59
59
|
|
60
60
|
details = {
|
61
|
-
:
|
62
|
-
:
|
63
|
-
:
|
61
|
+
format: format,
|
62
|
+
updated_at: record.updated_at,
|
63
|
+
virtual_path: "#{record.pathname}#{record.basename}"
|
64
64
|
}
|
65
65
|
|
66
66
|
details[:layout] = record.layout if record.respond_to?(:layout) && record.layout.present?
|
@@ -72,7 +72,7 @@ module Ecm
|
|
72
72
|
output = prefix.dup
|
73
73
|
output << '/' unless output.end_with?('/')
|
74
74
|
output = '/' << output unless output.start_with?('/')
|
75
|
-
|
75
|
+
output
|
76
76
|
end
|
77
77
|
|
78
78
|
# Normalize arrays by converting all symbols to strings.
|
@@ -81,21 +81,20 @@ module Ecm
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def build_source
|
84
|
-
|
84
|
+
fail 'call to abstract method #build_source'
|
85
85
|
end
|
86
86
|
|
87
|
-
def normalize_basename(
|
88
|
-
|
87
|
+
def normalize_basename(_basename)
|
88
|
+
fail 'call to abstract method #normalize_basename'
|
89
89
|
end
|
90
90
|
|
91
|
-
def resolve(
|
92
|
-
|
91
|
+
def resolve(_partial_flag)
|
92
|
+
fail 'call to abstract method #resolve'
|
93
93
|
end
|
94
94
|
|
95
95
|
def template_class
|
96
|
-
|
96
|
+
fail 'call to abstract method #template_class'
|
97
97
|
end
|
98
98
|
end
|
99
99
|
end
|
100
100
|
end
|
101
|
-
|
@@ -6,8 +6,8 @@ module Ecm
|
|
6
6
|
|
7
7
|
# associations
|
8
8
|
base.belongs_to :ecm_cms_folder,
|
9
|
-
:
|
10
|
-
:
|
9
|
+
class_name: 'Ecm::Cms::Folder',
|
10
|
+
foreign_key: 'ecm_cms_folder_id'
|
11
11
|
|
12
12
|
# callbacks
|
13
13
|
base.after_initialize :set_defaults
|
@@ -15,16 +15,16 @@ module Ecm
|
|
15
15
|
base.after_save :clear_resolver_cache
|
16
16
|
|
17
17
|
# validations
|
18
|
-
base.validates :basename, :
|
19
|
-
:
|
20
|
-
base.validates :handler, :
|
21
|
-
base.validates :locale, :
|
22
|
-
:
|
23
|
-
:
|
24
|
-
base.validates :format, :
|
25
|
-
:
|
26
|
-
:
|
27
|
-
base.validates :pathname, :
|
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
28
|
end
|
29
29
|
|
30
30
|
module ClassMethods
|
@@ -49,8 +49,8 @@ module Ecm
|
|
49
49
|
private
|
50
50
|
|
51
51
|
def assert_trailing_slash_on_pathname
|
52
|
-
self.pathname = '/' and return if
|
53
|
-
|
52
|
+
self.pathname = '/' and return if pathname.blank?
|
53
|
+
pathname << '/' unless pathname.end_with?('/')
|
54
54
|
end
|
55
55
|
|
56
56
|
def clear_resolver_cache
|
@@ -59,12 +59,11 @@ module Ecm
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def set_defaults
|
62
|
-
if
|
63
|
-
self.locale
|
64
|
-
self.handler ||= Ecm::Cms::Configuration.default_handlers[
|
62
|
+
if new_record?
|
63
|
+
self.locale ||= I18n.default_locale.to_s
|
64
|
+
self.handler ||= Ecm::Cms::Configuration.default_handlers[self.class.name.demodulize.underscore.to_sym].to_s
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
70
|
-
|
data/lib/ecm/cms/engine.rb
CHANGED
@@ -2,27 +2,25 @@ module Ecm
|
|
2
2
|
module Cms
|
3
3
|
class Engine < ::Rails::Engine
|
4
4
|
config.app_generators do |c|
|
5
|
-
c.test_framework :rspec, :
|
6
|
-
:
|
5
|
+
c.test_framework :rspec, fixture: true,
|
6
|
+
fixture_replacement: nil
|
7
7
|
|
8
8
|
c.integration_tool :rspec
|
9
9
|
c.performance_tool :rspec
|
10
10
|
end
|
11
11
|
|
12
|
-
# active admin
|
13
12
|
initializer :ecm_cms_engine do
|
14
13
|
::ActiveAdmin.setup do |config|
|
15
|
-
config.load_paths += Dir[
|
14
|
+
config.load_paths += Dir[root.join('app', 'admin')]
|
16
15
|
config.register_stylesheet 'ecm_cms.css'
|
17
16
|
config.register_javascript 'ecm_cms.js'
|
18
17
|
end
|
19
|
-
end if
|
18
|
+
end if Gem::Specification.find_all_by_name('activeadmin').any?
|
20
19
|
|
21
|
-
initializer
|
20
|
+
initializer 'ecm_cms.asset_pipeline' do |app|
|
22
21
|
app.config.assets.precompile << 'ecm_cms.js'
|
23
22
|
app.config.assets.precompile << 'ecm_cms.css'
|
24
23
|
end
|
25
24
|
end
|
26
25
|
end
|
27
26
|
end
|
28
|
-
|