cmor_cms 0.0.59.pre → 0.0.60.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e185b056371db7d645ccb896b3a87ca63aa61427fa0bf4d27f4f8b3ae2c9cee4
4
- data.tar.gz: b7942385f07c0dbbce28f8b129229635ab4c00af1e8ed6d92d8c29322409ffaa
3
+ metadata.gz: bbc08f4ce3bcb2c2753ba1939cd871591a64716629711206892a911489bddf9e
4
+ data.tar.gz: 9c2b42cc5b4df4a2ccdb7ed61f5619c570091951f981586ec0a49c07787b01a5
5
5
  SHA512:
6
- metadata.gz: 8d976aee1a3eab730e130b8a842123d80c44342b265cdf989ac6752847a6615fa8a117393abf47db4e954f9bf64a1ce86ed6a2572957ee3846f646c0ad128979
7
- data.tar.gz: cf09c9a732f6fdd53213e84fa1d220e2056985ba11fb682bb5e996fb0f5ce616db7359db10f1cf1612d9c2a55b8ad2c9d6bbfd268a081093cbfde22d25bfe4a2
6
+ metadata.gz: 1263916512e708c1897e1db50a83c4bea1dd34217852a1b3c13aa8dc1b559a9ea99a2ca3c0675aa573d82b085febe6486bae9198cd7e83f149c4d41663cf8089
7
+ data.tar.gz: 8e71a0b45c061464471062def6d22d2a950978c29127956fc49042c070e2842626d4925cf158b04a1255dba3a695d1abda1677c612c3594d0cb44b1c7c6fd6cb
@@ -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
@@ -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
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.59.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-08-18 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.59.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.59.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.59.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.59.pre
54
+ version: 0.0.60.pre
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: sqlite3
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -499,6 +499,7 @@ files:
499
499
  - lib/generators/cmor/cms/install/install_generator.rb
500
500
  - lib/generators/cmor/cms/install/templates/initializer.rb
501
501
  - lib/generators/cmor/cms/install/templates/routes.source
502
+ - lib/generators/cmor/cms/install/templates/routes_without_root.source
502
503
  - lib/tasks/cmor_cms_tasks.rake
503
504
  - spec/factories/cmor/cms/content_block.rb
504
505
  - spec/factories/cmor/cms/content_box.rb