simplec 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd4562c8c0bbab684b813215b25a37647dbbd134
4
- data.tar.gz: 924e595fdddaf414fcbd91a33b0a5008e7913864
3
+ metadata.gz: 30941905c919979a56cf165241070e5da7822192
4
+ data.tar.gz: 48b105ceabc6246c9b3cdbcc30dcbdc1a479696d
5
5
  SHA512:
6
- metadata.gz: 49b55b0d7c216b7e35a5cec8f8c2e99086077dfd43ad5f27d9da0e6de3446b62e51a06013b2fc707554a5888cfcb3b69cfa5947d51f73a9e7718775a18f9c8a5
7
- data.tar.gz: 6ce855a1ca1486f9e302dab3bf1b8c69cc8137c85cefd84daf1e14794658f35bd5a41f4f427d3031820d49e205833ddeb84c0fe9335460ba202630fa5c7ca7f3
6
+ metadata.gz: f9b3616fc0b37ae640025027a50f55a41a52bbc6187ffc781de995717311142b922fafb1990bc98290fdbdfe6378173257842051a892a65ca3d96e3038ac8024
7
+ data.tar.gz: 8e1fbe53a20d80b5362d16ff6a71be9d5c62ae97a855dc97e1f753010d9e92079ddb78733bbf3f6ca23e9544a973efb91b29618bc72957e10ae0e56ac892fc6c
data/README.md CHANGED
@@ -251,6 +251,8 @@ See this page for a good cheat sheet: http://markevans.github.io/dragonfly/image
251
251
 
252
252
  - Throw clear warning when creating a page without a type
253
253
 
254
+ - main_app document or method_missing
255
+
254
256
  - Document `lib/simplec/controller_extensions.rb`
255
257
 
256
258
  - Document why _subdomain in subdomain form in admin.
@@ -263,7 +265,7 @@ See this page for a good cheat sheet: http://markevans.github.io/dragonfly/image
263
265
 
264
266
  - utilize thread local variable for found subdomain in #subdomain
265
267
 
266
- - simplec_path/simplec_url caching
268
+ 1. Sitemap
267
269
 
268
270
  1. Installer `rails generater simplec:install`
269
271
 
@@ -1,3 +1,4 @@
1
+ # @!visibility private
1
2
  module Simplec
2
3
  class ApplicationController < ::ActionController::Base
3
4
  protect_from_forgery with: :exception
@@ -1,18 +1,12 @@
1
1
  require_dependency "simplec/application_controller"
2
+ require_dependency "simplec/page_action_helpers"
2
3
 
3
4
  module Simplec
4
5
  class PagesController < ApplicationController
6
+ include Simplec::PageActionHelpers
5
7
 
6
8
  def show
7
- @page = page("/#{params[:path]}")
8
- render layout: layout(@page)
9
- end
10
-
11
- private
12
-
13
- def layout(page)
14
- [page.layout, page.subdomain.default_layout, 'public']. # TODO allow config for public
15
- reject(&:blank?).first
9
+ render_path params[:path] || ''
16
10
  end
17
11
 
18
12
  end
@@ -1,3 +1,4 @@
1
+ # @private
1
2
  module Simplec
2
3
  class ApplicationJob < ActiveJob::Base
3
4
  end
@@ -1,3 +1,4 @@
1
+ # @private
1
2
  module Simplec
2
3
  class ApplicationRecord < ActiveRecord::Base
3
4
  self.abstract_class = true
@@ -1,11 +1,42 @@
1
1
  module Simplec
2
+
3
+ # An embedded image in an editor field.
4
+ #
5
+ # For the most part you don't need to utilize this record. These records are
6
+ # created by summernote and the administration of creating them is handled
7
+ # by the Simplec Engine.
8
+ #
9
+ # There is an #embedded_images association on a `Simplec::Page` record.
10
+ #
11
+ # @!visibility public
2
12
  class EmbeddedImage < ApplicationRecord
13
+
14
+ # @!attribute embeddable
15
+ # The object that owns the embedded image
16
+ # @return [Object, nil] An ActiveRecord object
3
17
  belongs_to :embeddable,
4
18
  polymorphic: true,
5
19
  optional: true
6
20
 
21
+ # @!attribute asset
22
+ # @return [Dragonfly::Model::Attachment, nil] The embedded asset
7
23
  dragonfly_accessor :asset
8
24
 
25
+ # @!attribute embeddable_type
26
+ # @return [String, nil] The type of the #embeddable association
27
+
28
+ # @!attribute embeddable_id
29
+ # @return [String, Integer, nil] The uuid (or id) of the #embeddable association
30
+
31
+ # @!attribute asset_uid
32
+ # @return [String, nil] The unique id of the Dragonfly #asset
33
+
34
+ # @!attribute asset_name
35
+ # @return [String, nil] The name of the Dragonfly #asset
36
+
37
+ # Dragonfly url for the asset.
38
+ #
39
+ # @return [String] the url for the dragonfly asset
9
40
  def url
10
41
  return unless self.asset
11
42
  return self.asset.url unless persisted?
@@ -1,203 +1,255 @@
1
- # Simplec::Page
2
- #
3
- # This class represents a page in the system.
4
- #
5
- # Each page has a class located in:
6
- # app/models/page/NAME.html.erb
7
- #
8
- # Each page has a partial template in:
9
- # app/views/pages/_NAME.html.erb
10
- #
11
- # Where NAME is the demodulized, snake-case name of the Page Subclasss. For
12
- # example:
13
- #
14
- # class Page::Home < Page
15
- # field :h1
16
- # end
17
- #
18
- # Would live in app/models/page/home.html.erb and have a template in
19
- # app/views/pages/_home.html.erb.
20
- #
21
- # Each page has the following attributes by default:
22
- # - page.title
23
- #
24
- # Read the documentation below for the class method .field, it is the most
25
- # used method.
26
- #
27
- #
28
1
  module Simplec
2
+
3
+ # This class represents a page in the system.
4
+ #
5
+ # == Model and Template Relationship.
6
+ #
7
+ # Each page has a class located in:
8
+ # app/models/page/NAME.rb
9
+ #
10
+ # Each page has a partial template in:
11
+ # app/views/pages/_NAME.html.erb
12
+ #
13
+ # Where NAME is the demodulized, snake-case name of the Page Subclasss. For
14
+ # example:
15
+ #
16
+ # class Page::Home < Page
17
+ # field :h1
18
+ # end
19
+ #
20
+ # Would have a have a template in `app/views/pages/_home.html.erb`.
21
+ #
22
+ # @!visibility public
29
23
  class Page < ApplicationRecord
30
24
 
25
+ FILE_FIELDS = [:file, :image].freeze
26
+
27
+ belongs_to :subdomain,
28
+ optional: false
29
+ belongs_to :parent,
30
+ class_name: 'Page',
31
+ optional: true
32
+ has_many :childern,
33
+ class_name: 'Page',
34
+ foreign_key: :parent_id
35
+ has_many :embedded_images,
36
+ as: :embeddable,
37
+ dependent: :delete_all
38
+
39
+ validates :type,
40
+ presence: true
41
+ validates :path,
42
+ uniqueness: { scope: :subdomain_id }
43
+ validate :validate_path_not_nil!
44
+ validates :layout,
45
+ inclusion: {in: :layouts, allow_blank: true}
46
+ validates :title,
47
+ presence: true
48
+
49
+ before_validation :match_parent_subdomain
50
+ before_validation :build_path
51
+ after_save :link_embedded_images!
52
+
53
+ # @!attribute slug
54
+ # The value is normalized to a string starting without a leading slash
55
+ # and ending without a slash. Case is not changed.
56
+ # @return [String]
57
+
58
+ # @!attribute [r] path
59
+ # The the path is computed from the slug and the sum all parent pages.
60
+ # @return [String]
61
+
62
+ # @!attribute title
63
+ # This is the title of the page.
64
+ # @return [String]
65
+
66
+ # @!attribute meta_description
67
+ # This is the meta description tag for the page.
68
+ # @return [String]
69
+
70
+ # @!attribute layout
71
+ # This is the layout to be used when the page is rendered. This attribute
72
+ # overrides the associated Subdomain's default_layout.
73
+ #
74
+ # See Simplec::Subdomain#layouts to get a list of optional layouts.
75
+ #
76
+ # @return [String]
77
+
78
+ # @!attribute fields
79
+ # JSONB Postgres field that holds all defined fields. Use only if you
80
+ # know what you are doing.
81
+ # @return [JSON]
31
82
 
32
- # TODO Document FILE_FIELDS constant
33
- #
34
- FILE_FIELDS = [:file, :image].freeze
35
-
36
- belongs_to :subdomain,
37
- optional: false
38
- belongs_to :parent,
39
- class_name: 'Page',
40
- optional: true
41
- has_many :childern,
42
- class_name: 'Page',
43
- foreign_key: :parent_id
44
- has_many :embedded_images,
45
- as: :embeddable,
46
- dependent: :delete_all
47
-
48
- validates :type,
49
- presence: true
50
- validates :path,
51
- presence: true,
52
- uniqueness: { scope: :subdomain_id }
53
- validates :layout,
54
- inclusion: {in: :layouts, allow_blank: true}
55
- validates :title,
56
- presence: true
57
-
58
- before_validation :match_parent_subdomain
59
- before_validation :build_path
60
- after_save :link_embedded_images!
61
-
62
- # Define a field on the page.
63
- #
64
- # - name - name of field
65
- # - options[:type] - :string (default), :text, :editor, :file, :image
66
- # :string - yields a text input
67
- # :text - yields a textarea
68
- # :editor - yields a summernote editor
69
- # :file - yields a file field
70
- # :image - yields a file field with image preview
71
- #
72
- # There is as template for each type for customization located in:
73
- # app/views/shared/fields/_TYPE.html.erb
74
- #
75
- # Defines a field on a subclass. This creates a getter and setter for the
76
- # name passed in. The options are used when building the administration forms.
77
- #
78
- # Regular dragonfly validations are available on :file and :image fields.
79
- # http://markevans.github.io/dragonfly/models#validations
80
- #
81
- def self.field(name, options={})
82
- fields[name] = {name: name, type: :string}.merge(options)
83
- if FILE_FIELDS.member?(fields[name][:type])
84
- dragonfly_accessor name
85
- data_field :"#{name}_uid"
86
- data_field :"#{name}_name"
87
- else
88
- data_field(name)
89
- end
90
- end
91
-
92
- # List fields
93
- #
94
- def self.fields
95
- @fields ||= Hash.new
96
- end
97
-
98
- # Return a constantized type, whitelisted by known subclasses.
99
- #
100
- def self.type(type)
83
+ # Define a field on the page
84
+ #
85
+ # There is as template for each type for customization located in:
86
+ # app/views/shared/fields/_TYPE.html.erb
87
+ #
88
+ # Defines a field on a subclass. This creates a getter and setter for the
89
+ # name passed in. The options are used when building the administration forms.
90
+ #
91
+ # Regular dragonfly validations are available on :file and :image fields.
92
+ # http://markevans.github.io/dragonfly/models#validations
93
+ # :string - yields a text input
94
+ # :text - yields a textarea
95
+ # :editor - yields a summernote editor
96
+ # :file - yields a file field
97
+ # :image - yields a file field with image preview
98
+ #
99
+ # @param name [String] name of field to be defined
100
+ # @param options [Hash] field options
101
+ # @option options [Symbol] :type one of :string (default), :text, :editor, :file, :image
102
+ def self.field(name, options={})
103
+ fields[name] = {name: name, type: :string}.merge(options)
104
+ if FILE_FIELDS.member?(fields[name][:type])
105
+ dragonfly_accessor name
106
+ data_field :"#{name}_uid"
107
+ data_field :"#{name}_name"
108
+ else
109
+ data_field(name)
110
+ end
111
+ end
112
+
113
+ # @return [Hash]
114
+ def self.fields
115
+ @fields ||= Hash.new
116
+ end
117
+
118
+ # Return a constantized type, whitelisted by known subclasses.
119
+ #
120
+ # @raise [RuntimeError] if Page subclass isn't defined.
121
+ # @return [Class]
122
+ def self.type(type)
101
123
  ::Page rescue raise '::Page not defined, define it in app/models'
102
- raise 'Unsupported Page Type; define in app/models/page/' unless ::Page.subclasses.map(&:name).
103
- member?(type)
104
- type.constantize
105
- end
106
-
107
- # Return names of fields.
108
- #
109
- # type: :file, is the only option
110
- #
111
- def self.field_names(type=nil)
112
- _fields = case type
113
- when :file
114
- fields.select {|k, v| FILE_FIELDS.member?(v[:type])}
115
- else
116
- fields
117
- end
118
- _fields.keys
119
- end
120
-
121
- # Return field options for building forms.
122
- #
123
- def field_options
124
- self.class.fields.values
125
- end
126
-
127
- # List parents, closest to furthest.
128
- #
129
- def parents
130
- page, parents = self, Array.new
131
- while page.parent
132
- page = page.parent
133
- parents << page
134
- end
135
- parents
136
- end
137
-
138
- # Before validation hook.
139
- #
140
- # Build the path of the page to be used in routing.
141
- #
142
- def build_path
143
- _pages = self.parents.reverse + [self]
144
- self.path = "/#{_pages.map(&:slug).reject(&:blank?).join('/')}"
145
- end
146
-
147
- # Before validation hook
148
- #
149
- # All pages need to have a matching subdomain to parent page
150
- #
151
- def match_parent_subdomain
152
- return unless self.parent
153
- self.subdomain = self.parent.subdomain
154
- end
155
-
156
- def find_embedded_images
157
- text = self.fields.values.join(' ')
158
- matches = text.scan(/ei=([^&]*)/)
159
- encoded_ids = matches.map(&:first)
160
- ids = encoded_ids.map { |eid| Base64.urlsafe_decode64(URI.unescape(eid)) }
161
- EmbeddedImage.includes(:embeddable).find(ids)
162
- end
163
-
164
- def link_embedded_images!
165
- images = self.find_embedded_images
166
- images.each do |image|
167
- raise AlreadyLinkedEmbeddedImage if image.embeddable &&
168
- image.embeddable != self
169
- image.update!(embeddable: self)
170
- end
171
- end
172
-
173
- def layouts
174
- @layouts ||= Subdomain.new.layouts
175
- end
176
-
177
- module Normalizers
178
- def slug=(val)
179
- val = val ? val.to_s.split('/').reject(&:blank?).join('/') : val
180
- super val
181
- end
182
-
183
- def slug
184
- if self.parent_id && self.parent.nil?
185
- self.path.to_s.split('/').reject(&:blank?).join('/')
186
- else
187
- super
188
- end
189
- end
190
- end
191
- prepend Normalizers
192
-
193
- class AlreadyLinkedEmbeddedImage < StandardError; end
194
-
195
- private
196
-
197
- def self.data_field(name)
198
- define_method(name) { fields[name.to_s] }
199
- define_method("#{name}=") { |val| fields[name.to_s] = val }
200
- end
124
+ raise 'Unsupported Page Type; define in app/models/page/' unless ::Page.subclasses.map(&:name).
125
+ member?(type)
126
+ type.constantize
127
+ end
128
+
129
+ # Return names of fields.
130
+ #
131
+ # type: :file, is the only option
132
+ #
133
+ def self.field_names(type=nil)
134
+ _fields = case type
135
+ when :file
136
+ fields.select {|k, v| FILE_FIELDS.member?(v[:type])}
137
+ else
138
+ fields
139
+ end
140
+ _fields.keys
141
+ end
142
+
143
+ # Return field options for building forms.
144
+ #
145
+ def field_options
146
+ self.class.fields.values
147
+ end
148
+
149
+ # List parents, closest to furthest.
150
+ #
151
+ # This is a recursive, expensive call.
152
+ #
153
+ # @return [Array] of parent Pages
154
+ def parents
155
+ page, parents = self, Array.new
156
+ while page.parent
157
+ page = page.parent
158
+ parents << page
159
+ end
160
+ parents
161
+ end
162
+
163
+ # Build the path of the page to be used in routing.
164
+ #
165
+ # Used as a before validation hook.
166
+ #
167
+ # @return [String] the computed path for the page
168
+ def build_path
169
+ _pages = self.parents.reverse + [self]
170
+ self.path = _pages.map(&:slug).reject(&:blank?).join('/')
171
+ end
172
+
173
+ # Sets the #subdomain t that of the parent.
174
+ #
175
+ # All pages need to have a matching subdomain to parent page. Does nothing
176
+ # if there is no parent.
177
+ #
178
+ # Used as a before validation hook.
179
+ #
180
+ # @return [Simplec::Subdomain] the parent's subdomain
181
+ def match_parent_subdomain
182
+ return unless self.parent
183
+ self.subdomain = self.parent.subdomain
184
+ end
185
+
186
+ # Search all of the fields text and create an array of all found
187
+ # Simplec::EmbeddedImages.
188
+ #
189
+ # @return [Array] of Simplec::EmbeddedImages
190
+ def find_embedded_images
191
+ text = self.fields.values.join(' ')
192
+ matches = text.scan(/ei=([^&]*)/)
193
+ encoded_ids = matches.map(&:first)
194
+ ids = encoded_ids.map { |eid| Base64.urlsafe_decode64(URI.unescape(eid)) }
195
+ EmbeddedImage.includes(:embeddable).find(ids)
196
+ end
197
+
198
+ # Set this instance as the #embeddable association on the
199
+ # Simplec::EmbeddedImage
200
+ #
201
+ # Used as an after_save hook.
202
+ #
203
+ # @return [Array] of Simplec::EmbeddedImages
204
+ def link_embedded_images!
205
+ images = self.find_embedded_images
206
+ images.each do |image|
207
+ raise AlreadyLinkedEmbeddedImage if image.embeddable &&
208
+ image.embeddable != self
209
+ image.update!(embeddable: self)
210
+ end
211
+ end
212
+
213
+ # Get layout options.
214
+ #
215
+ # See Simplec::Subdomain#layouts.
216
+ #
217
+ # @return [Array] of layout String names
218
+ def layouts
219
+ @layouts ||= Subdomain.new.layouts
220
+ end
221
+
222
+ # @!visibility private
223
+ module Normalizers
224
+
225
+ def slug=(val)
226
+ val = val ? val.to_s.split('/').reject(&:blank?).join('/') : val
227
+ super val
228
+ end
229
+
230
+ def slug
231
+ if self.parent_id && self.parent.nil?
232
+ self.path.to_s.split('/').reject(&:blank?).join('/')
233
+ else
234
+ super
235
+ end
236
+ end
237
+ end
238
+ prepend Normalizers
239
+
240
+ class AlreadyLinkedEmbeddedImage < StandardError; end
241
+
242
+ private
243
+
244
+ def validate_path_not_nil!
245
+ return unless self.path.nil?
246
+ errors.add :path, "cannot be nil"
247
+ end
248
+
249
+ def self.data_field(name)
250
+ define_method(name) { fields[name.to_s] }
251
+ define_method("#{name}=") { |val| fields[name.to_s] = val }
252
+ end
201
253
  end
202
254
  end
203
255
 
data/config/routes.rb CHANGED
@@ -3,7 +3,7 @@ Simplec::Engine.routes.draw do
3
3
  scope constraints: Simplec::Subdomains do
4
4
  resources :embedded_images, path: 'embedded-images', only: :create
5
5
  root 'pages#show'
6
- get '*path', to: 'pages#show'
6
+ get '(*path)', to: 'pages#show', as: :page
7
7
  end
8
8
 
9
9
  end
data/lib/simplec.rb CHANGED
@@ -1,6 +1,13 @@
1
1
  require "simplec/engine"
2
2
  require "simplec/embedded_image_actions"
3
+ require 'simplec/action_controller/extensions'
4
+ require 'simplec/action_view/helper'
5
+ require "simplec/page_action_helpers"
3
6
 
7
+
8
+ # Configuration details will go here.
9
+ #
10
+ # @!visibility public
4
11
  module Simplec
5
12
  # TODO configuration options
6
13
  end
@@ -4,9 +4,11 @@ module Simplec
4
4
 
5
5
  def self.included(receiver)
6
6
  receiver.helper_method :subdomain, :page,
7
- :simplec_path, :simplec_url
7
+ :simplec_path_for, :simplec_url_for
8
8
  end
9
9
 
10
+ # Get the subdomain.
11
+ # TODO docs
10
12
  def subdomain(name=nil)
11
13
  name ||= request.subdomain
12
14
  @_subdomains ||= Hash.new
@@ -14,42 +16,85 @@ module Simplec
14
16
  @_subdomains[name] = Subdomain.find_by!(name: name)
15
17
  end
16
18
 
19
+ # TODO docs
20
+ # @param path [String] path with no leading /
21
+ #
22
+ # @return [Simplec::Page]
17
23
  def page(path, options={})
18
24
  @_page ||= Hash.new
19
25
  return @_page[path] if @_page[path]
20
26
 
21
- _subdomain = subdomain
22
- _subdomain = Subdomain.find_by!(
23
- name: options[:subdomain]
24
- ) if options[:subdomain]
27
+ _subdomain = options[:subdomain] ?
28
+ Subdomain.find_by!(name: options[:subdomain]) :
29
+ subdomain
25
30
 
31
+ # TODO add raise option for find_by!
26
32
  @_page[path] = _subdomain.pages.find_by!(path: path)
27
33
  end
28
34
 
29
- def simplec_path(page_or_path, options={})
30
- # TODO cache page_paths
31
- _page = page_or_path.is_a?(Page) ?
32
- page_or_path : page(page_or_path, options)
33
-
34
- unless _page
35
- raise ActiveRecord::RecordNotFound if options[:raise]
36
- return nil
37
- end
35
+ # Get the path of a page.
36
+ #
37
+ # By default, if the Page cannot be located nil will be the result.
38
+ #
39
+ # @param page_or_path [Simplec::Page, String]
40
+ # If a page it will find the page.
41
+ # If a path it will find the page from the given path (no leading /).
42
+ #
43
+ # @param options [Hash] options
44
+ # @option options [Symbol] :raise
45
+ # If :raise is true, then ActiveRecord::RecordNotFound will be raised
46
+ # if the page cannot be found.
47
+ #
48
+ # @raise [ActiveRecord::RecordNotFound]
49
+ # if options[:raise] is true and Page cannot be located
50
+ #
51
+ # @return [String, nil] path of page, or nil
52
+ def simplec_path_for(page_or_path, options={})
53
+ page = page_for(page_or_path, options.extract!(:raise))
54
+ return unless page
55
+ simplec.page_path options.merge(
56
+ path: page.path
57
+ )
58
+ end
38
59
 
39
- _page.path
60
+ # Get the url of a page.
61
+ #
62
+ # By default, if the Page cannot be located nil will be the result.
63
+ #
64
+ # @param page_or_path [Simplec::Page, String]
65
+ # If a page it will find the page.
66
+ # If a path it will find the page from the given path (no leading /).
67
+ #
68
+ # @param options [Hash] options
69
+ # @option options [Symbol] :raise
70
+ # If :raise is true, then ActiveRecord::RecordNotFound will be raised
71
+ # if the page cannot be found.
72
+ #
73
+ # @raise [ActiveRecord::RecordNotFound]
74
+ # if options[:raise] is true and Page cannot be located
75
+ #
76
+ # @return [String, nil] path of page, or nil
77
+ def simplec_url_for(page_or_path, options={})
78
+ page = page_for(page_or_path, options.extract!(:raise))
79
+ return unless page
80
+ simplec.page_url options.merge(
81
+ subdomain: page.subdomain.try(:name),
82
+ path: page.path
83
+ )
40
84
  end
41
85
 
42
- def simplec_url(page_or_path, options={})
43
- # TODO cache page_urls
44
- _page = page_or_path.is_a?(Page) ?
86
+ private
87
+
88
+ def page_for(page_or_path, options={})
89
+ page = page_or_path.is_a?(Page) ?
45
90
  page_or_path : page(page_or_path, options)
46
91
 
47
- unless _page
92
+ unless page
48
93
  raise ActiveRecord::RecordNotFound if options[:raise]
49
94
  return nil
50
95
  end
51
96
 
52
- URI.join(root_url(subdomain: _page.subdomain.try(:name)), _page.path).to_s
97
+ page
53
98
  end
54
99
  end
55
100
  end
@@ -1,5 +1,7 @@
1
1
  module Simplec
2
2
  module EmbeddedImageActions
3
+
4
+ # @private
3
5
  module ClassMethods; end
4
6
 
5
7
  module InstanceMethods
@@ -1,18 +1,18 @@
1
- require 'simplec/action_controller/extensions'
2
- require 'simplec/action_view/helper'
3
-
4
1
  module Simplec
5
2
  class Engine < ::Rails::Engine
6
3
  isolate_namespace Simplec
7
4
 
8
5
  initializer "simplec_controller_extensions" do
9
6
  ActiveSupport.on_load(:action_controller_base) {
10
- prepend Simplec::ActionController::Extensions
7
+ include Simplec::ActionController::Extensions
8
+ prepend Simplec::PageActionHelpers
11
9
  helper Simplec::ActionView::Helper
12
10
  }
13
- ActiveSupport.on_load(:active_record) {
14
- Dir["#{Rails.root}/app/models/page/*.rb"].each {|file| require_dependency file }
15
- }
11
+ ActiveSupport.on_load(:active_record) { Simplec.load_pages }
16
12
  end
17
13
  end
14
+
15
+ def self.load_pages
16
+ Dir["#{Rails.root}/app/models/page/*.rb"].each {|file| require_dependency file }
17
+ end
18
18
  end
@@ -0,0 +1,29 @@
1
+ module Simplec
2
+ module PageActionHelpers
3
+
4
+ # @private
5
+ module ClassMethods; end
6
+
7
+ module InstanceMethods
8
+
9
+ private
10
+
11
+ def render_path(path)
12
+ @page = page(path)
13
+ render template: 'simplec/pages/show', layout: layout(@page)
14
+ end
15
+
16
+ def layout(page)
17
+ # TODO allow config for public
18
+ [page.layout, page.subdomain.default_layout, 'public'].
19
+ reject(&:blank?).first
20
+ end
21
+
22
+ end
23
+
24
+ def self.included(receiver)
25
+ receiver.extend ClassMethods
26
+ receiver.send :include, InstanceMethods
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module Simplec
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-15 00:00:00.000000000 Z
11
+ date: 2017-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -143,6 +143,7 @@ files:
143
143
  - lib/simplec/action_view/helper.rb
144
144
  - lib/simplec/embedded_image_actions.rb
145
145
  - lib/simplec/engine.rb
146
+ - lib/simplec/page_action_helpers.rb
146
147
  - lib/simplec/version.rb
147
148
  - lib/tasks/simplec_tasks.rake
148
149
  homepage: https://github.com/nearapogee/simplec