nocms-pages 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +238 -3
- data/app/controllers/no_cms/pages/application_controller.rb +1 -1
- data/app/controllers/no_cms/pages/pages_controller.rb +5 -1
- data/app/helpers/no_cms/pages/pages_helper.rb +24 -0
- data/app/models/no_cms/pages/block.rb +34 -6
- data/app/models/no_cms/pages/page.rb +29 -8
- data/app/views/no_cms/pages/pages/show.html.erb +2 -2
- data/config/locales/en.yml +4 -0
- data/config/locales/es.yml +22 -0
- data/db/migrate/20140227143723_add_fields_info_to_no_cms_block.rb +1 -1
- data/db/migrate/20140329160306_add_parent_id_to_no_cms_pages_block.rb +5 -0
- data/db/migrate/20140407083115_add_css_class_and_id_to_no_cms_pages_page_translations.rb +6 -0
- data/db/migrate/20140702112813_add_cache_enabled_to_no_cms_pages_page_translations.rb +5 -0
- data/db/migrate/20140806074811_add_layout_to_no_cms_pages_page.rb +5 -0
- data/lib/generators/nocms/templates/config/initializers/nocms/pages.rb +28 -4
- data/lib/nocms/pages/configuration.rb +11 -0
- data/lib/nocms/pages/version.rb +1 -1
- data/lib/{nocms_pages.rb → nocms-pages.rb} +0 -0
- metadata +11 -12
- data/app/helpers/no_cms/pages/application_helper.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd58af22ca24e3b0617e52dc00f4a12e186a7cf7
|
4
|
+
data.tar.gz: 336c772c261531d84e1d84b58df5a83f240cddff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8981fcf6322dd3d5d91d93908f6ae184c5938b7ba03a91222930cc550826b3d4b34cc99b1e49fc680fc8c79a94452c42a627a5c4a0fbce355037f6c2175f098
|
7
|
+
data.tar.gz: 2dd795d0b8cbb767baff11b16c36f094f3df9714cdc067a9a09d0388eb2d251aa71d86dc07d248ec20ac02e9db58656bbc0130a4f042c26124d2753e7a522901
|
data/README.md
CHANGED
@@ -1,4 +1,239 @@
|
|
1
|
-
|
2
|
-
===========
|
1
|
+
# NoCMS Pages
|
3
2
|
|
4
|
-
|
3
|
+
## What's this?
|
4
|
+
|
5
|
+
This is a Rails engine with a basic functionality of content pages made of customizable blocks. It's not attached to any particular CMS so you can use it freely within your Rails application without too much dependencies.
|
6
|
+
|
7
|
+
## How do I install it?
|
8
|
+
|
9
|
+
Right now there's no proper gem, although we have a couple of projects making extensive use of it.
|
10
|
+
|
11
|
+
To install it just put the repo in your Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem "nocms-pages", git: 'git@github.com:simplelogica/nocms-pages.git'
|
15
|
+
```
|
16
|
+
|
17
|
+
Then you update the bundle:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
bundle install
|
21
|
+
```
|
22
|
+
|
23
|
+
And then import all the migrations:
|
24
|
+
|
25
|
+
```
|
26
|
+
rake no_cms_pages:install:migrations
|
27
|
+
```
|
28
|
+
|
29
|
+
And run them:
|
30
|
+
|
31
|
+
```
|
32
|
+
rake db:migrate
|
33
|
+
```
|
34
|
+
|
35
|
+
And run the initializer:
|
36
|
+
|
37
|
+
```
|
38
|
+
rails g nocms:pages
|
39
|
+
```
|
40
|
+
|
41
|
+
Optionally, you may be interested on adding this engine routes to your app. You just have to mount the engine in your routes.rb file [just like any other standard engine](http://edgeguides.rubyonrails.org/engines.html#highlighter_95949).
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
mount NoCms::Pages::Engine => "/"
|
45
|
+
```
|
46
|
+
|
47
|
+
If you prefer not to mount the whole engine just take a look at the config/routes.rb file of the engine to see which controllers and actions are used.
|
48
|
+
|
49
|
+
## How does it work?
|
50
|
+
|
51
|
+
In NoCms you can customize the layout, templates and blocks a page is made of. Let's how to customize each one of them:
|
52
|
+
|
53
|
+
### Layouts
|
54
|
+
|
55
|
+
Pages are rendered through the pages controller in a standard Rails way, so all the available layouts four your application are available for your pages.
|
56
|
+
|
57
|
+
The attribute `layout` from the `NoCms::Pages::Page` model set the layout used for rendering. The default layout is `application`.
|
58
|
+
|
59
|
+
### Templates
|
60
|
+
|
61
|
+
The template is the `action` set to the render instruction in the pages controller. Because of that any view in the no_cms/pages/pages may be used as template.
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
render action: template, layout: layout
|
65
|
+
```
|
66
|
+
|
67
|
+
This `template` is set from the template attribute, being `show` the default value.
|
68
|
+
|
69
|
+
### Blocks
|
70
|
+
|
71
|
+
Blocks are the unit of contents the pages are made of. They are thought to be independent and customizable modules that can be created, edited or removed on their own, without dependency of any other module.
|
72
|
+
|
73
|
+
#### Block layouts
|
74
|
+
|
75
|
+
In NoCMS Pages, block layouts define two main things:
|
76
|
+
|
77
|
+
1. What kind of information a block contains and other settings (i.e. cache settings).
|
78
|
+
2. How this information is displayed within the page.
|
79
|
+
|
80
|
+
Block settings are configured in the file `config/initializers/nocms/pages.rb`. Here we declare all the available layouts for a block.
|
81
|
+
|
82
|
+
The following code
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
NoCms::Pages.configure do |config|
|
86
|
+
|
87
|
+
config.block_layouts = {
|
88
|
+
'default' => {
|
89
|
+
template: 'default',
|
90
|
+
fields: {
|
91
|
+
title: :string,
|
92
|
+
body: :text
|
93
|
+
}
|
94
|
+
},
|
95
|
+
'title-3_columns' => {
|
96
|
+
template: 'title_3_columns',
|
97
|
+
fields: {
|
98
|
+
title: :string,
|
99
|
+
column_1: :text,
|
100
|
+
column_2: :text,
|
101
|
+
column_3: :text
|
102
|
+
},
|
103
|
+
},
|
104
|
+
'logo-caption' => {
|
105
|
+
template: 'logo_caption',
|
106
|
+
fields: {
|
107
|
+
caption: :string,
|
108
|
+
logo: TestImage
|
109
|
+
}
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
end
|
114
|
+
```
|
115
|
+
|
116
|
+
declares 3 layouts ('default', 'title-3_columns' and 'logo-caption'). Each layout has a template and some declared fields. These fields will be available in the ruby object for that block. As an example, if `@block` is an instance of the NoCms::Pages::Block model which layout attribute is set to 'default' you will be able to do `@block.title`
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
block = NoCms::Pages::Block.new
|
120
|
+
block.layout = 'default'
|
121
|
+
|
122
|
+
block.title = 'a title'
|
123
|
+
block.title # => 'a title'
|
124
|
+
|
125
|
+
block.column_1 = 'a column' # => NoMethodError
|
126
|
+
block.column_1 # => NoMethodError
|
127
|
+
|
128
|
+
|
129
|
+
block.layout = 'title-3_columns'
|
130
|
+
|
131
|
+
block.title # => 'a title'
|
132
|
+
block.column_1 = 'a column'
|
133
|
+
block.column_1 # => 'a column'
|
134
|
+
block.body # => NoMethodError
|
135
|
+
|
136
|
+
block.layout = 'logo_caption'
|
137
|
+
block.title # => NoMethodError
|
138
|
+
block.logo = { name: 'testing logo' } # Currently this is the way to assign objects
|
139
|
+
block.logo.name # => 'testing logo'
|
140
|
+
block.logo.class # => TestImage
|
141
|
+
block.logo = TestImage.new name: 'testing logo' # Error! Currently assigning the object is not allowed :(
|
142
|
+
```
|
143
|
+
|
144
|
+
#### Block templates
|
145
|
+
|
146
|
+
Blocks are rendered using the `render_block` helper which controls all the logic related with renderinf a block, including fragment cache control.
|
147
|
+
|
148
|
+
In the end a partial is rendered using the block as a local variable to obtain the information. This partial must be found at `no_cms/pages/blocks` views folder and have the name configured in the `template` setting of the block. This way, rendering a 'title-3_columns' would render the partial `/no_cms/pages/blocks/title_3_columns`.
|
149
|
+
|
150
|
+
This partial is a regular Rails partial (nothing special here). AS an example, this could be the content of our `/no_cms/pages/blocks/title_3_columns.html.erb` partial:
|
151
|
+
|
152
|
+
```html
|
153
|
+
<div class='columns_block'>
|
154
|
+
<h2 class="title"><%= block.title %></h2>
|
155
|
+
<p class="column_1"><%= block.column_1 %></p>
|
156
|
+
<p class="column_2"><%= block.column_2 %></p>
|
157
|
+
<p class="column_3"><%= block.column_3 %></p>
|
158
|
+
</div>
|
159
|
+
```
|
160
|
+
|
161
|
+
As you can see, the partial has a block variable containing the block object you are rendering.
|
162
|
+
|
163
|
+
Since this is plain old rails you can do everything you can do with a partial (i.e. having a `/no_cms/pages/blocks/title_3_columns.en.html.erb` for the english version and a `/no_cms/pages/blocks/title_3_columns.es.html.erb` for the spanish one).
|
164
|
+
|
165
|
+
### Block Cache
|
166
|
+
|
167
|
+
Since blocks are independent units of content within a page, the standard Rails fragment cache seemed to fit well with them. That's why the `render_block` helper decides wether Rails cache should be used for rendering an individual block.
|
168
|
+
|
169
|
+
Cache for the blocks are configured at 3 levels:
|
170
|
+
|
171
|
+
1. The page may have its `cache_enabled` attribute set to false. If this is the case then the cache will be disabled without any further check. This way, a page can be marked as "not cacheable" (e.g. in an admin interface) and no other setting can overwrite it.
|
172
|
+
|
173
|
+
2. The `render_block` helper may be called with a `cache_enabled` option set to true or false. This option will enable/disable the cache. This allow us to render a block without using the cache (maybe on a preview action).
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
render_block block, cache: false
|
177
|
+
```
|
178
|
+
|
179
|
+
3. In the blocks configuration we can enable/disable the cache for all the blocks of a kind. We just have to add the cache_enabled setting.
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
NoCms::Pages.configure do |config|
|
183
|
+
|
184
|
+
config.block_layouts = {
|
185
|
+
'default' => {
|
186
|
+
template: 'default',
|
187
|
+
fields: {
|
188
|
+
title: :string,
|
189
|
+
body: :text
|
190
|
+
},
|
191
|
+
cache_enabled: false
|
192
|
+
}
|
193
|
+
}
|
194
|
+
end
|
195
|
+
```
|
196
|
+
|
197
|
+
4. In the blocks configuration file we can enable/disable cache for all the blocks that doesn't have a cache_enabled setting. This configuration will be stored at `NoCms::Pages.cache_enabled`
|
198
|
+
|
199
|
+
```ruby
|
200
|
+
NoCms::Pages.configure do |config|
|
201
|
+
|
202
|
+
config.cache_enabled = true
|
203
|
+
|
204
|
+
end
|
205
|
+
```
|
206
|
+
|
207
|
+
As a summary:
|
208
|
+
|
209
|
+
```ruby
|
210
|
+
|
211
|
+
b = NoCms::Pages::Block.new layout: 'default', title: 'Foo', description: 'Bar', page: page
|
212
|
+
b.page.cache_enabled # => true
|
213
|
+
NoCms::Pages.cache_enabled # => true
|
214
|
+
b.cache_enabled # => false, since the block configuration sets it to false
|
215
|
+
render_block b # => This won't use fragment cache since this block layout have cache disabled
|
216
|
+
|
217
|
+
b = NoCms::Pages::Block.new layout: 'title-3_columns', title: 'Foo', description: 'Bar', page: page
|
218
|
+
b.page.cache_enabled # => true
|
219
|
+
NoCms::Pages.cache_enabled # => true
|
220
|
+
b.cache_enabled # => true, since this block configuration doesn't override NoCms::Pages.cache_enabled
|
221
|
+
render_block b # => This will use fragment cache since, by default, it's enabled for all blocks
|
222
|
+
|
223
|
+
render_block b, cache_enabled: false # => This won't use fragment cache as the option in the helper overrides the block configuration
|
224
|
+
|
225
|
+
page.cache_enabled = false
|
226
|
+
render_block b # => This won't use fragment cache sincs it's been disabled for the page and blocks configuration has been override
|
227
|
+
render_block b, cache_enabled: true # => This won't use fragment cache even when saying the helper to do it. Power for the users!
|
228
|
+
|
229
|
+
```
|
230
|
+
|
231
|
+
## Where is the admin interface?
|
232
|
+
|
233
|
+
`nocms-pages` is a gem with the minimum dependencies and that includes the admin interface.
|
234
|
+
|
235
|
+
Main idea is that this gem can be used in a project with a Rails Admin, an Active Admin or a home made admin. Of course, it can be tricky to embed this dynamic kind of blocks in a pre-built admin, but we think that freedom must be given to the developers.
|
236
|
+
|
237
|
+
As soon as we started using this gem we started our own admin interface, which is contained in another gem [nocms-admin-pages](https://github.com/simplelogica/nocms-admin-pages) and you can use it.
|
238
|
+
|
239
|
+
If your project already has another standard admin interface such as Rails Admin and you manage to embed nocms-pages on it, please, let us know and we will make a note here giving you full credit for the development :)
|
@@ -5,8 +5,12 @@ module NoCms::Pages
|
|
5
5
|
def show
|
6
6
|
@page = Page.no_drafts.where(path: "/#{params[:path]}").first
|
7
7
|
raise ActionController::RoutingError.new('Not Found') if @page.nil?
|
8
|
+
@blocks = @page.blocks.roots.no_drafts
|
8
9
|
|
9
|
-
|
10
|
+
template = @page.template.blank? ? 'show' : @page.template
|
11
|
+
layout = @page.layout.blank? ? 'application' : @page.layout
|
12
|
+
|
13
|
+
render action: template, layout: layout
|
10
14
|
end
|
11
15
|
end
|
12
16
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module NoCms
|
2
|
+
module Pages
|
3
|
+
module PagesHelper
|
4
|
+
def render_block block, options = {}
|
5
|
+
# If cache is disabled for this block then we disable no matter what the block or the options passed have to say about it. This way, the user in the back has the last word about disabling cache
|
6
|
+
options[:cache_enabled] = false unless block.page.cache_enabled
|
7
|
+
# If we don't have any option about cache enabled then we ask the block
|
8
|
+
options[:cache_enabled] = block.cache_enabled unless options.has_key? :cache_enabled
|
9
|
+
|
10
|
+
block_template = "no_cms/pages/blocks/#{block.template}"
|
11
|
+
|
12
|
+
# And now decide if we use cache or not
|
13
|
+
if options[:cache_enabled]
|
14
|
+
Rails.cache.fetch "#{block_template}/#{block.id}/#{block.updated_at.to_i}" do
|
15
|
+
render block_template, block: block
|
16
|
+
end
|
17
|
+
else
|
18
|
+
render block_template, block: block
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,13 +1,17 @@
|
|
1
1
|
module NoCms::Pages
|
2
2
|
class Block < ActiveRecord::Base
|
3
3
|
|
4
|
-
include Concerns::TranslationScopes
|
4
|
+
include NoCms::Pages::Concerns::TranslationScopes
|
5
5
|
|
6
6
|
scope :drafts, ->() { where_with_locale(draft: true) }
|
7
7
|
scope :no_drafts, ->() { where_with_locale(draft: false) }
|
8
|
-
|
8
|
+
scope :roots, ->() { where parent_id: nil }
|
9
9
|
belongs_to :page
|
10
10
|
|
11
|
+
belongs_to :parent, class_name: "NoCms::Pages::Block"
|
12
|
+
has_many :children, class_name: "NoCms::Pages::Block", foreign_key: 'parent_id', inverse_of: :parent, dependent: :destroy
|
13
|
+
accepts_nested_attributes_for :children, allow_destroy: true
|
14
|
+
|
11
15
|
attr_reader :cached_objects
|
12
16
|
|
13
17
|
translates :layout, :fields_info, :draft
|
@@ -19,10 +23,15 @@ module NoCms::Pages
|
|
19
23
|
after_initialize :set_blank_fields
|
20
24
|
after_create :set_default_position
|
21
25
|
before_save :save_related_objects
|
26
|
+
before_validation :copy_parent_page
|
22
27
|
|
23
28
|
validates :fields_info, presence: { allow_blank: true }
|
24
29
|
validates :page, :layout, presence: true
|
25
30
|
|
31
|
+
def position
|
32
|
+
self[:position] || 0
|
33
|
+
end
|
34
|
+
|
26
35
|
def layout_config
|
27
36
|
NoCms::Pages.block_layouts.stringify_keys[layout]
|
28
37
|
end
|
@@ -31,6 +40,11 @@ module NoCms::Pages
|
|
31
40
|
layout_config[:template] if layout_config
|
32
41
|
end
|
33
42
|
|
43
|
+
def cache_enabled
|
44
|
+
return NoCms::Pages.cache_enabled unless layout_config
|
45
|
+
layout_config.has_key?(:cache_enabled) ? layout_config[:cache_enabled] : NoCms::Pages.cache_enabled
|
46
|
+
end
|
47
|
+
|
34
48
|
def has_field? field
|
35
49
|
# We have the field if...
|
36
50
|
!layout_config.nil? && # We have a layout configuration AND
|
@@ -53,10 +67,15 @@ module NoCms::Pages
|
|
53
67
|
|
54
68
|
# If value is still nil, but the field exists we must get the object from the database
|
55
69
|
if value.nil?
|
70
|
+
field_type = field_type(field)
|
56
71
|
field_id = fields_info["#{field}_id".to_sym]
|
57
|
-
value = @cached_objects[field.to_sym] = field_type
|
72
|
+
value = @cached_objects[field.to_sym] = field_type.find(field_id) unless field_id.nil?
|
58
73
|
end
|
59
74
|
|
75
|
+
# If value is still nil, and the field_type is an ActiveRecord class, then we
|
76
|
+
if value.nil? && field_type.is_a?(Class)
|
77
|
+
value = @cached_objects[field.to_sym] = field_type.new
|
78
|
+
end
|
60
79
|
value
|
61
80
|
end
|
62
81
|
|
@@ -105,6 +124,8 @@ module NoCms::Pages
|
|
105
124
|
new_layout = new_attributes[:layout] || new_attributes['layout']
|
106
125
|
self.layout = new_layout unless new_layout.nil?
|
107
126
|
|
127
|
+
Rails.logger.info "Searching #{new_attributes.keys.inspect} fields in #{self.layout} layout"
|
128
|
+
|
108
129
|
# And now separate fields and attributes
|
109
130
|
fields = new_attributes.select{|k, _| has_field? k }.symbolize_keys
|
110
131
|
new_attributes.reject!{|k, _| has_field? k }
|
@@ -123,6 +144,10 @@ module NoCms::Pages
|
|
123
144
|
super
|
124
145
|
end
|
125
146
|
|
147
|
+
def copy_parent_page
|
148
|
+
self.page = parent.page unless parent.nil?
|
149
|
+
end
|
150
|
+
|
126
151
|
private
|
127
152
|
|
128
153
|
def set_blank_fields
|
@@ -131,13 +156,16 @@ module NoCms::Pages
|
|
131
156
|
end
|
132
157
|
|
133
158
|
def set_default_position
|
134
|
-
self.update_attribute :position, ((page.blocks.pluck(:position).compact.max || 0) + 1) if self
|
159
|
+
self.update_attribute :position, ((page.blocks.pluck(:position).compact.max || 0) + 1) if self[:position].blank?
|
135
160
|
end
|
136
161
|
|
137
162
|
def save_related_objects
|
163
|
+
# Now we save each activerecord related object
|
138
164
|
cached_objects.each do |field, object|
|
139
|
-
if object
|
140
|
-
|
165
|
+
# Notice that we don't care if the object is actually saved
|
166
|
+
# We don't care because there may be some cases where no real information is sent to an object but something is sent (i.e. the locale in a new Globalize translation) and then the object is created empty
|
167
|
+
# When this happens if we save! the object an error is thrown and we can't leave the object blank
|
168
|
+
if object.is_a?(ActiveRecord::Base) && object.save
|
141
169
|
fields_info["#{field}_id".to_sym] = object.id
|
142
170
|
end
|
143
171
|
end
|
@@ -1,36 +1,57 @@
|
|
1
1
|
module NoCms::Pages
|
2
2
|
class Page < ActiveRecord::Base
|
3
3
|
|
4
|
-
include Concerns::TranslationScopes
|
4
|
+
include NoCms::Pages::Concerns::TranslationScopes
|
5
5
|
|
6
6
|
scope :drafts, ->() { where_with_locale(draft: true) }
|
7
7
|
scope :no_drafts, ->() { where_with_locale(draft: false) }
|
8
8
|
|
9
|
+
def self.home
|
10
|
+
where_with_locale(slug: '').where(parent_id: nil).first
|
11
|
+
end
|
12
|
+
|
9
13
|
acts_as_nested_set
|
10
14
|
|
11
15
|
has_many :blocks, inverse_of: :page, class_name: 'NoCms::Pages::Block'
|
12
16
|
accepts_nested_attributes_for :blocks, allow_destroy: true
|
13
17
|
|
14
|
-
translates :title, :body, :slug, :path, :draft
|
18
|
+
translates :title, :body, :slug, :path, :draft, :css_class, :css_id, :cache_enabled
|
15
19
|
|
16
|
-
validates :title,
|
20
|
+
validates :title, presence: true
|
21
|
+
validates :body, presence: true if NoCms::Pages.use_body?
|
17
22
|
validates :slug, presence: { allow_blank: true }
|
23
|
+
validates :path, presence: true, uniqueness: true
|
18
24
|
|
19
25
|
before_validation :set_slug_and_path
|
26
|
+
|
20
27
|
after_move :rebuild_path
|
21
28
|
|
22
29
|
def set_slug_and_path
|
23
|
-
self.slug = title.parameterize if slug.nil? && !title.nil?
|
24
|
-
self.
|
30
|
+
self.slug = title.parameterize if slug.nil? && !title.nil? # If there's no slug then we create it
|
31
|
+
self.slug = title.parameterize if slug.blank? && !parent.nil? # If slug is blank and this page has a parent then we recreate it
|
32
|
+
self.slug = title.parameterize if slug.blank? && Page.home && (Page.home != self) # If slug is blank and there's already a home (and it's another page) then we recreate it
|
33
|
+
self.rebuild_path if path.nil? || attribute_changed?('slug')
|
25
34
|
end
|
26
35
|
|
27
36
|
def rebuild_path
|
28
|
-
self.update_attribute :path, "#{
|
37
|
+
self.update_attribute :path, "#{parent.path unless parent.nil?}/#{slug}"
|
38
|
+
descendants.each(&:rebuild_path)
|
29
39
|
end
|
30
40
|
|
31
41
|
def self.templates
|
32
|
-
|
33
|
-
map
|
42
|
+
@templates ||= (Gem::Specification.all.map(&:gem_dir) + [Rails.root]). # We get all gems and rails paths
|
43
|
+
map{ |d| Dir["#{d}/app/views/no_cms/pages/pages/*.html.erb"]}. # We get all page templates
|
44
|
+
flatten.map { |f| File.basename(f, '.html.erb') }.uniq.sort # And get their names
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.layouts
|
48
|
+
return @layouts unless @layouts.blank?
|
49
|
+
@layouts = NoCms::Pages::page_layouts if @layouts.blank?
|
50
|
+
@layouts = Dir["#{Rails.root}/app/views/layouts/*.html.erb"]. # We get all the files in app/views/layouts
|
51
|
+
map { |f| File.basename(f, '.html.erb') }. # Get the name without any extension
|
52
|
+
reject {|l| l.starts_with? '_'}. # reject partials
|
53
|
+
sort if @layouts.blank? # and sort
|
54
|
+
@layouts
|
34
55
|
end
|
35
56
|
|
36
57
|
end
|
data/config/locales/en.yml
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
es:
|
2
|
+
activerecord:
|
3
|
+
models:
|
4
|
+
no_cms/pages/page: Página
|
5
|
+
no_cms/pages/block: Bloque de contenido
|
6
|
+
attributes:
|
7
|
+
no_cms/pages/page:
|
8
|
+
title: Título
|
9
|
+
body: Cuerpo
|
10
|
+
cache_enabled: Habilitar caché
|
11
|
+
css_class: Clases CSS
|
12
|
+
css_id: Id CSS
|
13
|
+
layout: Layout
|
14
|
+
no_cms/pages/block:
|
15
|
+
layout: Layout
|
16
|
+
title: Título
|
17
|
+
body: Cuerpo
|
18
|
+
no_cms:
|
19
|
+
pages:
|
20
|
+
blocks:
|
21
|
+
layouts:
|
22
|
+
default: Layout por defecto
|
@@ -1,14 +1,32 @@
|
|
1
1
|
NoCms::Pages.configure do |config|
|
2
2
|
|
3
|
+
# Enable Rails fragment cache for the block templates when you call the render_block helper
|
4
|
+
# You can override this cache setting in any block configuration below or sending
|
5
|
+
# the cache option true or false when calling the block helpers
|
6
|
+
# e.g: render_block block, cache: true
|
7
|
+
# config.cache_enabled = false
|
8
|
+
|
3
9
|
# In this section we configure block layouts. It's just an array of layouts, each consisting on a hash.
|
4
|
-
# Each layout has a
|
10
|
+
# Each layout has a series of options
|
5
11
|
# E.g: config.block_layouts = {
|
6
12
|
# 'title-long_text' => {
|
7
|
-
# template: 'title-long_text',
|
8
|
-
#
|
13
|
+
# template: 'title-long_text', # This is the template of this block,
|
14
|
+
# # used as a partial both in the front
|
15
|
+
# # and the admin (if you use the nocms-admin-pages gem)
|
16
|
+
# fields: { # This is the list of fields a block with this layout would have
|
9
17
|
# title: :string,
|
10
|
-
# long_text: :text
|
18
|
+
# long_text: :text,
|
19
|
+
# image: Image, # You may use another ActiveRecord classes of your own
|
11
20
|
# }
|
21
|
+
# allow_nested_blocks: true, # A block with this layout may include a list of nested blocks
|
22
|
+
# # This setting is actually used by nocms-admin-pages gem to show
|
23
|
+
# # nested forms
|
24
|
+
# nest_levels: [0] # Some layout may not be nestable, or useful only in certain nesting level
|
25
|
+
# # Once again, this setting is used by nocms-admin-pages gem to hide certain
|
26
|
+
# # in nested blocks. When blank, it's assumed there's no restriction.
|
27
|
+
# cache_enabled: false # When setting cache_enabled you will be **overriding** the global cache_enabled
|
28
|
+
# # setting. If you don't set a cache setting then it will use the global cache
|
29
|
+
# # setting specified above
|
12
30
|
# },
|
13
31
|
# 'title-3_columns_text' => {
|
14
32
|
# template: 'title-3_columns_text',
|
@@ -22,4 +40,10 @@ NoCms::Pages.configure do |config|
|
|
22
40
|
# }
|
23
41
|
# config.block_layouts = {}
|
24
42
|
|
43
|
+
# By default we use blocks to create the content of the page. If we just want a big textarea to insert the content we must set use_body to true
|
44
|
+
# config.use_body = false
|
45
|
+
|
46
|
+
# By default we use all the layouts in the app/views/layouts from the app
|
47
|
+
# config.page_layouts = ['application', ...]
|
48
|
+
|
25
49
|
end
|
@@ -3,7 +3,12 @@ module NoCms
|
|
3
3
|
include ActiveSupport::Configurable
|
4
4
|
|
5
5
|
config_accessor :block_layouts
|
6
|
+
config_accessor :page_layouts
|
7
|
+
config_accessor :use_body
|
8
|
+
config_accessor :cache_enabled
|
6
9
|
|
10
|
+
self.use_body = false
|
11
|
+
self.cache_enabled = false
|
7
12
|
self.block_layouts = {
|
8
13
|
'default' => {
|
9
14
|
template: 'default',
|
@@ -14,5 +19,11 @@ module NoCms
|
|
14
19
|
}
|
15
20
|
}
|
16
21
|
|
22
|
+
self.page_layouts = []
|
23
|
+
|
24
|
+
def self.use_body?
|
25
|
+
use_body
|
26
|
+
end
|
27
|
+
|
17
28
|
end
|
18
29
|
end
|
data/lib/nocms/pages/version.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nocms-pages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simplelogica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -54,22 +54,16 @@ dependencies:
|
|
54
54
|
name: awesome_nested_set
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
|
-
- - "~>"
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
version: '2.1'
|
60
57
|
- - ">="
|
61
58
|
- !ruby/object:Gem::Version
|
62
|
-
version:
|
59
|
+
version: 3.0.0.rc.6
|
63
60
|
type: :runtime
|
64
61
|
prerelease: false
|
65
62
|
version_requirements: !ruby/object:Gem::Requirement
|
66
63
|
requirements:
|
67
|
-
- - "~>"
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '2.1'
|
70
64
|
- - ">="
|
71
65
|
- !ruby/object:Gem::Version
|
72
|
-
version:
|
66
|
+
version: 3.0.0.rc.6
|
73
67
|
- !ruby/object:Gem::Dependency
|
74
68
|
name: sqlite3
|
75
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,7 +92,7 @@ files:
|
|
98
92
|
- app/assets/stylesheets/pages/application.css
|
99
93
|
- app/controllers/no_cms/pages/application_controller.rb
|
100
94
|
- app/controllers/no_cms/pages/pages_controller.rb
|
101
|
-
- app/helpers/no_cms/pages/
|
95
|
+
- app/helpers/no_cms/pages/pages_helper.rb
|
102
96
|
- app/models/no_cms/pages/block.rb
|
103
97
|
- app/models/no_cms/pages/concerns/translation_scopes.rb
|
104
98
|
- app/models/no_cms/pages/page.rb
|
@@ -106,6 +100,7 @@ files:
|
|
106
100
|
- app/views/no_cms/pages/blocks/_default.html.erb
|
107
101
|
- app/views/no_cms/pages/pages/show.html.erb
|
108
102
|
- config/locales/en.yml
|
103
|
+
- config/locales/es.yml
|
109
104
|
- config/routes.rb
|
110
105
|
- db/migrate/20140226123742_create_no_cms_pages.rb
|
111
106
|
- db/migrate/20140227100626_create_no_cms_blocks.rb
|
@@ -117,14 +112,18 @@ files:
|
|
117
112
|
- db/migrate/20140303145615_add_template_to_no_cms_page.rb
|
118
113
|
- db/migrate/20140313171000_add_draft_to_block.rb
|
119
114
|
- db/migrate/20140314110439_add_draft_to_pages.rb
|
115
|
+
- db/migrate/20140329160306_add_parent_id_to_no_cms_pages_block.rb
|
116
|
+
- db/migrate/20140407083115_add_css_class_and_id_to_no_cms_pages_page_translations.rb
|
117
|
+
- db/migrate/20140702112813_add_cache_enabled_to_no_cms_pages_page_translations.rb
|
118
|
+
- db/migrate/20140806074811_add_layout_to_no_cms_pages_page.rb
|
120
119
|
- lib/generators/nocms/pages_generator.rb
|
121
120
|
- lib/generators/nocms/templates/config/initializers/nocms/pages.rb
|
121
|
+
- lib/nocms-pages.rb
|
122
122
|
- lib/nocms/pages/configuration.rb
|
123
123
|
- lib/nocms/pages/engine.rb
|
124
124
|
- lib/nocms/pages/routes.rb
|
125
125
|
- lib/nocms/pages/routes/page_found_constraint.rb
|
126
126
|
- lib/nocms/pages/version.rb
|
127
|
-
- lib/nocms_pages.rb
|
128
127
|
- lib/tasks/pages_tasks.rake
|
129
128
|
homepage: https://github.com/simplelogica/nocms-pages
|
130
129
|
licenses: []
|