cmor_cms 0.0.55.pre → 0.0.60.pre

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf551caf3690866dadf9f89ced1eb6a77bf85a8d52b262d6f4e67e3b7c7a1b66
4
- data.tar.gz: 2e0ae960a7b152d9c08a76323324916f77c155a6330ffceb6c3398ec9cedfdc7
3
+ metadata.gz: bbc08f4ce3bcb2c2753ba1939cd871591a64716629711206892a911489bddf9e
4
+ data.tar.gz: 9c2b42cc5b4df4a2ccdb7ed61f5619c570091951f981586ec0a49c07787b01a5
5
5
  SHA512:
6
- metadata.gz: 786f2a27eb81b39133624eef109b980c91e6387a2a648eb26a62358d6246c24250f552ccc5d6e0edfaae11813a012284c0a9fae48452ae633eab00395ebf7072
7
- data.tar.gz: d212c339d25304e17e16f188b44702bfba24187aa03da07abd86227c4222b9b92243a6c44afd7f8d44946148338b1b2d805b9424a8c700b6d5a02e881cc8b3e1
6
+ metadata.gz: 1263916512e708c1897e1db50a83c4bea1dd34217852a1b3c13aa8dc1b559a9ea99a2ca3c0675aa573d82b085febe6486bae9198cd7e83f149c4d41663cf8089
7
+ data.tar.gz: 8e71a0b45c061464471062def6d22d2a950978c29127956fc49042c070e2842626d4925cf158b04a1255dba3a695d1abda1677c612c3594d0cb44b1c7c6fd6cb
@@ -0,0 +1,63 @@
1
+ module Cmor
2
+ module Cms
3
+ module Models
4
+ module DatabaseTemplateConcern
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ # callbacks
9
+ after_initialize :set_defaults
10
+ before_validation :assert_trailing_slash_on_pathname
11
+ after_save :clear_resolver_cache
12
+
13
+ # validations
14
+ validates :basename, presence: true,
15
+ uniqueness: { scope: [:pathname, :locale, :format, :handler] }
16
+ validates :handler, inclusion: { in: ActionView::Template::Handlers.extensions.map(&:to_s) }
17
+ validates :locale, inclusion: { in: I18n.available_locales.map(&:to_s) },
18
+ allow_nil: true,
19
+ allow_blank: true
20
+ validates :format, inclusion: { in: Mime::SET.symbols.map(&:to_s) },
21
+ allow_nil: true,
22
+ allow_blank: true
23
+ validates :pathname, presence: true
24
+ end
25
+
26
+ def human
27
+ "#{self.class.name}: #{path_and_filename}"
28
+ end
29
+
30
+ def filename
31
+ filename = basename.nil? ? '' : basename.dup
32
+ filename << ".#{locale}" if locale.present?
33
+ filename << ".#{format}" if format.present?
34
+ filename << ".#{handler}" if handler.present?
35
+ filename
36
+ end
37
+
38
+ def path_and_filename
39
+ "#{pathname}#{filename}"
40
+ end
41
+
42
+ private
43
+
44
+ def assert_trailing_slash_on_pathname
45
+ self.pathname = '/' and return if pathname.blank?
46
+ pathname << '/' unless pathname.end_with?('/')
47
+ end
48
+
49
+ def clear_resolver_cache
50
+ klass = "#{self.class.name}Resolver"
51
+ klass.constantize.instance.clear_cache
52
+ end
53
+
54
+ def set_defaults
55
+ if new_record?
56
+ self.locale ||= I18n.default_locale.to_s
57
+ self.handler ||= Cmor::Cms::Configuration.default_handlers[self.class.name.demodulize.underscore.to_sym].to_s
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,34 @@
1
+ module Cmor
2
+ module Cms
3
+ class RedirectMiddleware
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def redirect_to(location)
9
+ [301, {'Location' => location, 'Content-Type' => 'text/html'}, ['Moved Permanently']]
10
+ end
11
+
12
+ def call(env)
13
+ req = Rack::Request.new(env)
14
+ if redirect = find_redirect_for(req.path)
15
+ return redirect_to(redirect.target)
16
+ end
17
+ @app.call(env)
18
+ end
19
+
20
+ def find_redirect_for(request_path)
21
+ Cmor::Cms::Redirect.published.where(source: request_path).first
22
+ end
23
+ # def call(env)
24
+ # req = Rack::Request.new(env)
25
+ # return redirect(redirects[req.path]) if redirects.include?(req.path)
26
+ # @app.call(env)
27
+ # end
28
+
29
+ # def redirects
30
+ # { '/source' => '/target' }
31
+ # end
32
+ end
33
+ end
34
+ end
@@ -1,7 +1,7 @@
1
1
  module Cmor::Cms
2
2
  class Layout < ApplicationRecord
3
3
  # add shared behaviour for database backed templates
4
- include Cmor::Cms::DatabaseTemplate
4
+ include Cmor::Cms::Models::DatabaseTemplateConcern
5
5
 
6
6
  # publishing
7
7
  include ActsAsPublished::ActiveRecord
@@ -1,7 +1,7 @@
1
1
  module Cmor::Cms
2
2
  class Page < ActiveRecord::Base
3
3
  # add shared behaviour for database backed templates
4
- include Cmor::Cms::DatabaseTemplate
4
+ include Cmor::Cms::Models::DatabaseTemplateConcern
5
5
 
6
6
  # associations
7
7
  has_many :navigation_items,
@@ -1,7 +1,7 @@
1
1
  module Cmor::Cms
2
2
  class Partial < ActiveRecord::Base
3
3
  # add shared behaviour for database backed templates
4
- include Cmor::Cms::DatabaseTemplate
4
+ include Cmor::Cms::Models::DatabaseTemplateConcern
5
5
 
6
6
  # publishing
7
7
  include ActsAsPublished::ActiveRecord
@@ -0,0 +1,13 @@
1
+ module Cmor
2
+ module Cms
3
+ class Redirect < ApplicationRecord
4
+ include ActsAsPublished::ActiveRecord
5
+ acts_as_published
6
+
7
+ acts_as_list
8
+
9
+ validates :source, presence: true
10
+ validates :target, presence: true
11
+ end
12
+ end
13
+ end
@@ -1,7 +1,7 @@
1
1
  module Cmor::Cms
2
2
  class Template < ActiveRecord::Base
3
3
  # add shared behaviour for database backed templates
4
- include Cmor::Cms::DatabaseTemplate
4
+ include Cmor::Cms::Models::DatabaseTemplateConcern
5
5
 
6
6
  # publishing
7
7
  include ActsAsPublished::ActiveRecord
@@ -11,40 +11,79 @@ module Cmor
11
11
  end
12
12
 
13
13
  # instance methods go here
14
- def find_templates(name, prefix, partial, details, outside_app_allowed = false)
15
- return [] unless resolve(partial)
14
+ if Rails.version < '6.0'
15
+ def find_templates(name, prefix, partial, details, outside_app_allowed = false)
16
+ return [] unless resolve(partial)
17
+
18
+ conditions = {
19
+ pathname: assert_slashs(prefix.to_s),
20
+ basename: normalize_basename(name),
21
+ locale: normalize_array(details[:locale]).first,
22
+ format: normalize_array(details[:formats]).first,
23
+ handler: normalize_array(details[:handlers])
24
+ }
25
+
26
+ format = conditions.delete(:format)
27
+ locale = conditions.delete(:locale)
28
+
29
+ query = template_class.constantize.where(conditions)
16
30
 
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
- }
31
+ # 1) Only include published templates
32
+ query = query.published
24
33
 
25
- format = conditions.delete(:format)
26
- locale = conditions.delete(:locale)
34
+ # 2) Check for templates with the given format or format is nil
35
+ query = query.where(["format = ? OR format = '' OR format IS NULL", format])
27
36
 
28
- query = template_class.constantize.where(conditions)
37
+ # 3) Ensure templates with format come first
38
+ query = query.order('format DESC')
29
39
 
30
- # 1) Only include published templates
31
- query = query.published
40
+ # 4) Check for templates with the given locale or locale is nil
41
+ query = query.where(["locale = ? OR locale = '' OR locale IS NULL", locale])
32
42
 
33
- # 2) Check for templates with the given format or format is nil
34
- query = query.where(["format = ? OR format = '' OR format IS NULL", format])
43
+ # 5) Ensure templates with locale come first
44
+ query = query.order('locale DESC')
35
45
 
36
- # 3) Ensure templates with format come first
37
- query = query.order('format DESC')
46
+ # 6) Now trigger the query passing on conditions to initialization
47
+ query.map do |record|
48
+ initialize_template(record, details)
49
+ end
50
+ end
51
+ else
52
+ def find_templates(name, prefix, partial, details, locals)
53
+ return [] unless resolve(partial)
54
+
55
+ conditions = {
56
+ pathname: assert_slashs(prefix.to_s),
57
+ basename: normalize_basename(name),
58
+ locale: normalize_array(details[:locale]).first,
59
+ format: normalize_array(details[:formats]).first,
60
+ handler: normalize_array(details[:handlers])
61
+ }
38
62
 
39
- # 4) Check for templates with the given locale or locale is nil
40
- query = query.where(["locale = ? OR locale = '' OR locale IS NULL", locale])
63
+ format = conditions.delete(:format)
64
+ locale = conditions.delete(:locale)
41
65
 
42
- # 5) Ensure templates with locale come first
43
- query = query.order('locale DESC')
66
+ query = template_class.constantize.where(conditions)
44
67
 
45
- # 6) Now trigger the query passing on conditions to initialization
46
- query.map do |record|
47
- initialize_template(record, details)
68
+ # 1) Only include published templates
69
+ query = query.published
70
+
71
+ # 2) Check for templates with the given format or format is nil
72
+ query = query.where(["format = ? OR format = '' OR format IS NULL", format])
73
+
74
+ # 3) Ensure templates with format come first
75
+ query = query.order('format DESC')
76
+
77
+ # 4) Check for templates with the given locale or locale is nil
78
+ query = query.where(["locale = ? OR locale = '' OR locale IS NULL", locale])
79
+
80
+ # 5) Ensure templates with locale come first
81
+ query = query.order('locale DESC')
82
+
83
+ # 6) Now trigger the query passing on conditions to initialization
84
+ query.map do |record|
85
+ initialize_template(record, details, locals)
86
+ end
48
87
  end
49
88
  end
50
89
 
@@ -71,13 +110,12 @@ module Cmor
71
110
  ::ActionView::Template.new(source, identifier, handler, details)
72
111
  end
73
112
  else
74
- def initialize_template(record, details)
113
+ def initialize_template(record, details, locals)
75
114
  source = build_source(record)
76
115
  identifier = "#{record.class} - #{record.id} - #{record.pathname}#{record.basename}"
77
116
  handler = ::ActionView::Template.registered_template_handler(record.handler)
78
117
  virtual_path = "#{record.pathname}#{record.basename}"
79
118
  layout = record.layout if record.respond_to?(:layout) && record.layout.present?
80
- locals = []
81
119
 
82
120
  # 5) Check for the record.format, if none is given, try the template
83
121
  # handler format and fallback to the one given on conditions
@@ -63,6 +63,7 @@ module Cmor::Cms
63
63
  page.basename = 'home'
64
64
  page.locale = locale
65
65
  page.handler = 'textile'
66
+ page.published = true
66
67
  end
67
68
  if page.save
68
69
  @created_pages << page
@@ -22,6 +22,9 @@ de:
22
22
  cmor/cms/partial:
23
23
  one: Fragment
24
24
  other: Fragmente
25
+ cmor/cms/redirect:
26
+ one: Umleitung
27
+ other: Umleitungen
25
28
  cmor/cms/template:
26
29
  one: Vorlage
27
30
  other: Vorlagen
@@ -113,6 +116,11 @@ de:
113
116
  locale: Sprache
114
117
  path_and_filename: Dateipfad
115
118
  pathname: Pfad
119
+ cmor/cms/redirect:
120
+ <<: *defaults
121
+ source: Quelle
122
+ target: Ziel
123
+ position: Position
116
124
  cmor/cms/template:
117
125
  <<: *defaults
118
126
  basename: Name
@@ -22,6 +22,9 @@ en:
22
22
  cmor/cms/partial:
23
23
  one: Partial
24
24
  other: Partials
25
+ cmor/cms/redirect:
26
+ one: Umleitung
27
+ other: Umleitungen
25
28
  cmor/cms/template:
26
29
  one: Template
27
30
  other: Templates
@@ -111,6 +114,11 @@ en:
111
114
  locale: Language
112
115
  path_and_filename: Filepath
113
116
  pathname: Path
117
+ cmor/cms/redirect:
118
+ <<: *defaults
119
+ source: Source
120
+ target: Target
121
+ position: Position
114
122
  cmor/cms/template:
115
123
  <<: *defaults
116
124
  basename: Name
@@ -1,6 +1,8 @@
1
1
  Cmor::Cms::Engine.routes.draw do
2
2
  localized do
3
- get '/*page', to: 'page#respond', as: :page
3
+ get '/*page', to: 'page#respond', as: :page, constraints: lambda { |req|
4
+ req.path.exclude? 'rails/active_storage'
5
+ }
4
6
  get '/', to: 'page#respond', page: 'home'
5
7
  end
6
8
  end
@@ -0,0 +1,12 @@
1
+ class CreateCmorCmsRedirects < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :cmor_cms_redirects do |t|
4
+ t.text :source
5
+ t.text :target
6
+ t.integer :position
7
+ t.timestamp :published_at
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -4,8 +4,6 @@ require 'cmor/cms/action_view/template_renderer_patch'
4
4
  require 'cmor/cms/engine'
5
5
  require 'cmor/cms/configuration'
6
6
 
7
- require 'cmor/cms/database_template'
8
-
9
7
  require 'cmor/cms/controller_extensions/layout_resolver'
10
8
  require 'cmor/cms/controller_extensions/page_resolver'
11
9
  require 'cmor/cms/controller_extensions/partial_resolver'
@@ -55,8 +55,9 @@ module ActionView
55
55
  template = determine_template(options)
56
56
 
57
57
  prepend_formats(template.format)
58
-
59
- render_template(context, template, (template.layout || options[:layout]), options[:locals] || {})
58
+
59
+ layout = (template.respond_to?(:layout) ? template.layout : nil) || options[:layout]
60
+ render_template(context, template, (layout || options[:layout]), options[:locals] || {})
60
61
  end
61
62
  end
62
63
  end
@@ -11,6 +11,14 @@ module Cmor
11
11
  c.performance_tool :rspec
12
12
 
13
13
  end
14
+
15
+ initializer "cmor_cms_engine.register_template_handlers" do |app|
16
+ ::ActionView::Template.register_template_handler :textile, ::ActionView::Template::Handlers::Textile.new
17
+ end
18
+
19
+ initializer "cmor_cms_engine.add_redirect_middleware" do |app|
20
+ app.middleware.use Cmor::Cms::RedirectMiddleware
21
+ end
14
22
  end
15
23
  end
16
24
  end
@@ -1,3 +1,4 @@
1
+ require 'acts_as_list'
1
2
  require 'acts_as_published'
2
3
  require 'awesome_nested_set'
3
4
  require 'cmor_core_frontend'
@@ -18,16 +18,24 @@ module Cmor
18
18
  end
19
19
 
20
20
  def generate_routes
21
+ if Rails.application.routes.url_helpers.respond_to?(:root_path)
22
+ routes_source = 'routes_without_root.source'
23
+ else
24
+ routes_source = 'routes.source'
25
+ end
26
+
21
27
  inject_into_file 'config/routes.rb', before: "\nend" do
22
- File.read(File.join(File.expand_path('../templates', __FILE__), 'routes.source'))
28
+ File.read(File.join(File.expand_path('../templates', __FILE__), routes_source))
23
29
  end
24
30
  end
25
31
 
26
- # def add_homepages
27
- # if yes? "Do you want to add homepages?"
28
- # AddHomepagesService.call
29
- # end
30
- # end
32
+ def add_homepages
33
+ begin
34
+ AddHomepagesService.call(locales: [I18n.locale])
35
+ rescue ActiveRecord::StatementInvalid => e
36
+ puts "[Cmor::Cms] Could not generate homepage: #{e.message}"
37
+ end
38
+ end
31
39
  end
32
40
  end
33
41
  end
@@ -1,4 +1,11 @@
1
1
 
2
2
  mount Cmor::Cms::Engine, at: '/' # This one is greedy and has to go last!
3
3
 
4
+ # Cmor::Cms adds a root route to redirect the root of your application
5
+ # to the default locale.
6
+ #
7
+ # For example if your default locale is en and you access www.example.com
8
+ # it redirects to www.example.com/en. At /en the request is handled by
9
+ # by Cmor::Cms.
10
+ #
4
11
  root to: redirect("/#{I18n.locale}")
@@ -0,0 +1,14 @@
1
+
2
+ mount Cmor::Cms::Engine, at: '/' # This one is greedy and has to go last!
3
+
4
+ # Cmor::Cms adds a root route to redirect the root of your application
5
+ # to the default locale.
6
+ #
7
+ # For example if your default locale is en and you access www.example.com
8
+ # it redirects to www.example.com/en. At /en the request is handled by
9
+ # by Cmor::Cms.
10
+ #
11
+ # WARNING: As you already have a root route this default was not added.
12
+ # Please review your routing.
13
+ #
14
+ # root to: redirect("/#{I18n.locale}")
@@ -6,10 +6,15 @@ namespace :cmor do
6
6
  Cmor::Cms::ImportPartialsService.call(args)
7
7
  end
8
8
 
9
- desc 'Adds homepages for all (or given) locales'
9
+ desc 'Adds homepages for all (or given) locales (Specify locales like this: rails cmor:cms:add_homepages["en de"])'
10
10
  task :add_homepages, [:locales] => [:environment] do |_t, args|
11
11
  args.with_defaults(locales: I18n.available_locales)
12
- Cmor::Cms::AddHomepagesService.call(args)
12
+ options = args.to_h
13
+ if options[:locales].is_a?(String)
14
+ options[:locales] = options[:locales].split.map(&:to_sym) & I18n.available_locales
15
+ end
16
+
17
+ Cmor::Cms::AddHomepagesService.call(options)
13
18
  end
14
19
  end
15
20
  end
@@ -0,0 +1,6 @@
1
+ FactoryBot.define do
2
+ factory :cmor_cms_redirect, class: 'Cmor::Cms::Redirect' do
3
+ source { "/source" }
4
+ target { "/target" }
5
+ end
6
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmor_cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.55.pre
4
+ version: 0.0.60.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Vasquez Angel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-28 00:00:00.000000000 Z
11
+ date: 2020-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.0.55.pre
33
+ version: 0.0.60.pre
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 0.0.55.pre
40
+ version: 0.0.60.pre
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: cmor_core_frontend
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 0.0.55.pre
47
+ version: 0.0.60.pre
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 0.0.55.pre
54
+ version: 0.0.60.pre
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: sqlite3
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -318,6 +318,20 @@ dependencies:
318
318
  - - ">="
319
319
  - !ruby/object:Gem::Version
320
320
  version: '0'
321
+ - !ruby/object:Gem::Dependency
322
+ name: acts_as_list
323
+ requirement: !ruby/object:Gem::Requirement
324
+ requirements:
325
+ - - ">="
326
+ - !ruby/object:Gem::Version
327
+ version: '0'
328
+ type: :runtime
329
+ prerelease: false
330
+ version_requirements: !ruby/object:Gem::Requirement
331
+ requirements:
332
+ - - ">="
333
+ - !ruby/object:Gem::Version
334
+ version: '0'
321
335
  - !ruby/object:Gem::Dependency
322
336
  name: awesome_nested_set
323
337
  requirement: !ruby/object:Gem::Requirement
@@ -418,11 +432,13 @@ files:
418
432
  - app/assets/stylesheets/cmor/cms/application.css
419
433
  - app/assets/stylesheets/cmor/cms/application/keep.css
420
434
  - app/assets/stylesheets/cmor_cms.css
435
+ - app/concerns/cmor/cms/models/database_template_concern.rb
421
436
  - app/concerns/cmor/cms/navigation_item/properties_concern.rb~
422
437
  - app/controllers/cmor/cms/page_controller.rb
423
438
  - app/importers/cmor/cms/importers/navigation.rb
424
439
  - app/importers/cmor/cms/importers/navigation_item.rb
425
440
  - app/importers/cmor/cms/importers/page.rb
441
+ - app/middlewares/cmor/cms/redirect_middleware.rb
426
442
  - app/models/cmor/cms/content_block.rb
427
443
  - app/models/cmor/cms/content_box.rb
428
444
  - app/models/cmor/cms/layout.rb
@@ -430,6 +446,7 @@ files:
430
446
  - app/models/cmor/cms/navigation_item.rb
431
447
  - app/models/cmor/cms/page.rb
432
448
  - app/models/cmor/cms/partial.rb
449
+ - app/models/cmor/cms/redirect.rb
433
450
  - app/models/cmor/cms/template.rb
434
451
  - app/resolvers/cmor/cms/database_resolver.rb
435
452
  - app/resolvers/cmor/cms/layout_resolver.rb
@@ -449,7 +466,6 @@ files:
449
466
  - config/initializers/assets.rb
450
467
  - config/initializers/mime_types.rb
451
468
  - config/initializers/simple_navigation.rb
452
- - config/initializers/textile_support.rb
453
469
  - config/locales/de.yml
454
470
  - config/locales/en.yml
455
471
  - config/navigation.rb
@@ -467,6 +483,7 @@ files:
467
483
  - db/migrate/20200120134422_add_published_at_to_cmor_cms_navigation_items.rb
468
484
  - db/migrate/20200120141440_set_all_publishable_to_published.rb
469
485
  - db/migrate/20200514115526_create_cmor_cms_layouts.rb
486
+ - db/migrate/20200813085847_create_cmor_cms_redirects.rb
470
487
  - lib/cmor/cms.rb
471
488
  - lib/cmor/cms/action_view/template_patch.rb
472
489
  - lib/cmor/cms/action_view/template_renderer_patch.rb
@@ -476,13 +493,13 @@ files:
476
493
  - lib/cmor/cms/controller_extensions/partial_resolver.rb
477
494
  - lib/cmor/cms/controller_extensions/template_resolver.rb
478
495
  - lib/cmor/cms/database_resolver.rb~
479
- - lib/cmor/cms/database_template.rb
480
496
  - lib/cmor/cms/engine.rb
481
497
  - lib/cmor/cms/version.rb
482
498
  - lib/cmor_cms.rb
483
499
  - lib/generators/cmor/cms/install/install_generator.rb
484
500
  - lib/generators/cmor/cms/install/templates/initializer.rb
485
501
  - lib/generators/cmor/cms/install/templates/routes.source
502
+ - lib/generators/cmor/cms/install/templates/routes_without_root.source
486
503
  - lib/tasks/cmor_cms_tasks.rake
487
504
  - spec/factories/cmor/cms/content_block.rb
488
505
  - spec/factories/cmor/cms/content_box.rb
@@ -491,6 +508,7 @@ files:
491
508
  - spec/factories/cmor/cms/navigations.rb
492
509
  - spec/factories/cmor/cms/pages.rb
493
510
  - spec/factories/cmor/cms/partials.rb
511
+ - spec/factories/cmor/cms/redirects.rb
494
512
  - spec/factories/cmor/cms/templates.rb
495
513
  homepage: https://github.com/content-management-on-rails
496
514
  licenses:
@@ -1,3 +0,0 @@
1
- Rails.application.config.to_prepare do
2
- ::ActionView::Template.register_template_handler :textile, ::ActionView::Template::Handlers::Textile.new
3
- end
@@ -1,64 +0,0 @@
1
- module Cmor
2
- module Cms
3
- module DatabaseTemplate
4
- def self.included(base)
5
- base.extend(ClassMethods)
6
-
7
- # callbacks
8
- base.after_initialize :set_defaults
9
- base.before_validation :assert_trailing_slash_on_pathname
10
- base.after_save :clear_resolver_cache
11
-
12
- # validations
13
- base.validates :basename, presence: true,
14
- uniqueness: { scope: [:pathname, :locale, :format, :handler] }
15
- base.validates :handler, inclusion: ActionView::Template::Handlers.extensions.map(&:to_s)
16
- base.validates :locale, inclusion: I18n.available_locales.map(&:to_s),
17
- allow_nil: true,
18
- allow_blank: true
19
- base.validates :format, inclusion: Mime::SET.symbols.map(&:to_s),
20
- allow_nil: true,
21
- allow_blank: true
22
- base.validates :pathname, presence: true
23
- end
24
-
25
- module ClassMethods
26
- end
27
-
28
- def human
29
- "#{self.class.name}: #{path_and_filename}"
30
- end
31
-
32
- def filename
33
- filename = basename.nil? ? '' : basename.dup
34
- filename << ".#{locale}" if locale.present?
35
- filename << ".#{format}" if format.present?
36
- filename << ".#{handler}" if handler.present?
37
- filename
38
- end
39
-
40
- def path_and_filename
41
- "#{pathname}#{filename}"
42
- end
43
-
44
- private
45
-
46
- def assert_trailing_slash_on_pathname
47
- self.pathname = '/' and return if pathname.blank?
48
- pathname << '/' unless pathname.end_with?('/')
49
- end
50
-
51
- def clear_resolver_cache
52
- klass = "#{self.class.name}Resolver"
53
- klass.constantize.instance.clear_cache
54
- end
55
-
56
- def set_defaults
57
- if new_record?
58
- self.locale ||= I18n.default_locale.to_s
59
- self.handler ||= Cmor::Cms::Configuration.default_handlers[self.class.name.demodulize.underscore.to_sym].to_s
60
- end
61
- end
62
- end
63
- end
64
- end