cadmus 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +8 -1
- data/Gemfile +2 -0
- data/README.md +6 -35
- data/Rakefile +33 -2
- data/app/helpers/cadmus/rendering_helper.rb +24 -0
- data/app/views/cadmus/layouts/_form.html.erb +11 -0
- data/app/views/cadmus/layouts/edit.html.erb +5 -0
- data/app/views/cadmus/layouts/index.html.erb +25 -0
- data/app/views/cadmus/layouts/new.html.erb +5 -0
- data/app/views/cadmus/pages/index.html.erb +2 -2
- data/app/views/cadmus/pages/show.html.erb +1 -1
- data/app/views/cadmus/partials/_form.html.erb +35 -0
- data/app/views/cadmus/partials/edit.html.erb +5 -0
- data/app/views/cadmus/partials/index.html.erb +25 -0
- data/app/views/cadmus/partials/new.html.erb +5 -0
- data/app/views/cadmus/partials/show.html.erb +4 -0
- data/bin/rake +16 -0
- data/cadmus.gemspec +2 -2
- data/lib/cadmus.rb +23 -6
- data/lib/cadmus/concerns/controller_with_parent.rb +70 -0
- data/lib/cadmus/concerns/liquid_template_field.rb +33 -0
- data/lib/cadmus/concerns/model_with_parent.rb +14 -0
- data/lib/cadmus/concerns/other_class_accessor.rb +50 -0
- data/lib/cadmus/engine.rb +9 -0
- data/lib/cadmus/layout.rb +32 -0
- data/lib/cadmus/layouts_controller.rb +70 -0
- data/lib/cadmus/page.rb +22 -7
- data/lib/cadmus/{controller_extensions.rb → pages_controller.rb} +8 -60
- data/lib/cadmus/partial.rb +32 -0
- data/lib/cadmus/partial_file_system.rb +28 -0
- data/lib/cadmus/partials_controller.rb +70 -0
- data/lib/cadmus/renderers.rb +1 -1
- data/lib/cadmus/version.rb +1 -1
- data/test/cadmus_test.rb +7 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/config/manifest.js +4 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/javascripts/cable.js +13 -0
- data/test/dummy/app/assets/javascripts/channels/.keep +0 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/channels/application_cable/channel.rb +4 -0
- data/test/dummy/app/channels/application_cable/connection.rb +4 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/jobs/application_job.rb +2 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/application_record.rb +3 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +38 -0
- data/test/dummy/bin/update +29 -0
- data/test/dummy/bin/yarn +10 -0
- data/test/dummy/config.ru +5 -0
- data/test/dummy/config/application.rb +18 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/cable.yml +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +54 -0
- data/test/dummy/config/environments/production.rb +91 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
- data/test/dummy/config/initializers/assets.rb +14 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +33 -0
- data/test/dummy/config/puma.rb +56 -0
- data/test/dummy/config/routes.rb +3 -0
- data/test/dummy/config/secrets.yml +32 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/log/development.log +5 -0
- data/test/dummy/package.json +5 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/test/dummy/public/apple-touch-icon.png +0 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/test_helper.rb +17 -0
- metadata +150 -9
- data/lib/cadmus/liquid_template_field.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6c607dee469a52a3503f7ed85361b5324c4b10cb44941ce653e122a6642881c6
|
4
|
+
data.tar.gz: ac58d718a15527304ebb19291d8fa641076334dfcebd6cc97711e493ee3afc77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5629fb1f4409a98cbd053110aad417e2d3dc697f5b0cb14f00dcfd24003e5ba2571d3de2651d659c794da91bd8d83b7afe45a8f34eb9e293ece85195f6cf3603
|
7
|
+
data.tar.gz: 1996d05f4e055806e4c76428414af0c1e437e7399d5d3792ccb03a7183301a7e8411f86d5f48355cb2dbfe9c4bec11f7992113d50e6cadf890068519d7a2dc74
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,15 @@
|
|
1
|
+
## cadmus 0.7.0 (09-19-2018)
|
2
|
+
|
3
|
+
* BREAKING CHANGE: Cadmus no longer mixes anything into `ActiveRecord::Base` when required; instead, models must explicitly include the mixins they need
|
4
|
+
* Layouts
|
5
|
+
* Partials
|
6
|
+
* Major internal refactors
|
7
|
+
|
1
8
|
## cadmus 0.6.0 (04-08-2017)
|
2
9
|
|
3
10
|
* Expose a `{% page_url %}` tag, which outputs the URL to a page (for easier inter-page linking)
|
4
11
|
* Expose a Liquid register called `parent` from controllers that mix in `Cadmus::ControllerExtensions`, which contains the page parent (if present)
|
5
|
-
* Extract a mixin module called `Cadmus::LiquidTemplateField`, which makes it easier to add Liquid templates to models
|
12
|
+
* Extract a mixin module called `Cadmus::Concerns::LiquidTemplateField`, which makes it easier to add Liquid templates to models
|
6
13
|
|
7
14
|
## cadmus 0.5.3 (02-04-2017)
|
8
15
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Cadmus: an embeddable CMS for Rails
|
2
2
|
|
3
|
-
Cadmus is an embeddable content management system for Rails
|
3
|
+
Cadmus is an embeddable content management system for Rails applications. It's based on [Liquid](http://liquidmarkup.org)
|
4
4
|
and is designed to be small and unobtrusive.
|
5
5
|
|
6
6
|
Cadmus doesn't define controllers or models itself, but rather, provides mixins to add CMS-like functionality to controllers
|
@@ -38,10 +38,11 @@ unique index on the parent and slug columns:
|
|
38
38
|
add_index :pages, [:parent_type, :parent_id, :slug], :unique => true
|
39
39
|
```
|
40
40
|
|
41
|
-
And in the model, add a `cadmus_page` declaration:
|
41
|
+
And in the model, include `Cadmus::Page` and add a `cadmus_page` declaration:
|
42
42
|
|
43
43
|
```ruby
|
44
44
|
class Page < ActiveRecord::Base
|
45
|
+
include Cadmus::Page
|
45
46
|
cadmus_page
|
46
47
|
end
|
47
48
|
```
|
@@ -51,36 +52,6 @@ You'll need a controller to deal with your pages. Here's a minimal example of o
|
|
51
52
|
```ruby
|
52
53
|
class PagesController < ApplicationController
|
53
54
|
include Cadmus::PagesController
|
54
|
-
|
55
|
-
protected
|
56
|
-
def page_class
|
57
|
-
Page
|
58
|
-
end
|
59
|
-
end
|
60
|
-
```
|
61
|
-
|
62
|
-
If you're on Rails 4 (or using the `strong_parameters` gem) you'll probably want to use forbidden attributes protection.
|
63
|
-
Here's how you do that:
|
64
|
-
|
65
|
-
```ruby
|
66
|
-
class Page < ActiveRecord::Base
|
67
|
-
include ActiveModel::ForbiddenAttributesProtection
|
68
|
-
cadmus_page
|
69
|
-
end
|
70
|
-
```
|
71
|
-
|
72
|
-
```ruby
|
73
|
-
class PagesController < ApplicationController
|
74
|
-
include Cadmus::PagesController
|
75
|
-
|
76
|
-
protected
|
77
|
-
def page_params
|
78
|
-
params.require(:page).permit(:name, :slug, :content)
|
79
|
-
end
|
80
|
-
|
81
|
-
def page_class
|
82
|
-
Page
|
83
|
-
end
|
84
55
|
end
|
85
56
|
```
|
86
57
|
|
@@ -307,7 +278,7 @@ Cadmus provides a convenience mixin to let you make that field a Liquid template
|
|
307
278
|
|
308
279
|
```ruby
|
309
280
|
class WelcomeEmail < ActiveRecord::Base
|
310
|
-
include Cadmus::LiquidTemplateField
|
281
|
+
include Cadmus::Concerns::LiquidTemplateField
|
311
282
|
|
312
283
|
liquid_template_field :content_liquid_template, :content
|
313
284
|
|
@@ -319,7 +290,7 @@ Now if you call `my_welcome_email.content_liquid_template`, you'll get a parsed
|
|
319
290
|
|
320
291
|
```ruby
|
321
292
|
class WelcomeEmail < ActiveRecord::Base
|
322
|
-
include Cadmus::LiquidTemplateField
|
293
|
+
include Cadmus::Concerns::LiquidTemplateField
|
323
294
|
include Cadmus::Renderable
|
324
295
|
|
325
296
|
liquid_template_field :content_liquid_template, :content
|
@@ -336,7 +307,7 @@ Presto! Now you can call `my_welcome_email.rendered_content`. Since `WelcomeEm
|
|
336
307
|
|
337
308
|
```ruby
|
338
309
|
class WelcomeEmail < ActiveRecord::Base
|
339
|
-
include Cadmus::LiquidTemplateField
|
310
|
+
include Cadmus::Concerns::LiquidTemplateField
|
340
311
|
include Cadmus::Renderable
|
341
312
|
|
342
313
|
liquid_template_field :content_liquid_template, :content
|
data/Rakefile
CHANGED
@@ -1,2 +1,33 @@
|
|
1
|
-
|
2
|
-
require
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Cadmus'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'test'
|
28
|
+
t.pattern = 'test/**/*_test.rb'
|
29
|
+
t.verbose = false
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
task default: :test
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Cadmus::RenderingHelper
|
2
|
+
def render_cadmus_page_in_effective_layout(page)
|
3
|
+
page_content = cadmus_renderer.render(@page.liquid_template, :html)
|
4
|
+
cms_layout = @page.effective_cms_layout
|
5
|
+
render_in_cadmus_layout(page_content, cms_layout, 'page' => page)
|
6
|
+
end
|
7
|
+
|
8
|
+
def render_in_cadmus_layout(content, cms_layout, assigns = {})
|
9
|
+
if cms_layout
|
10
|
+
assigns = assigns.merge({ 'content_for_layout' => content })
|
11
|
+
if defined?(:liquid_assigns_for_layout)
|
12
|
+
assigns.reverse_merge!(liquid_assigns_for_layout(cms_layout))
|
13
|
+
end
|
14
|
+
|
15
|
+
cadmus_renderer.render(cms_layout.liquid_template, :html, assigns: assigns, registers: { 'parent' => cms_layout.parent })
|
16
|
+
else
|
17
|
+
content_for :content do
|
18
|
+
content
|
19
|
+
end
|
20
|
+
|
21
|
+
render template: 'layouts/application'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<div class="form-group">
|
2
|
+
<%= f.label :name %>
|
3
|
+
<%= f.text_field :name, class: 'form-control' %>
|
4
|
+
</div>
|
5
|
+
|
6
|
+
<div class="form-group">
|
7
|
+
<%= f.label :content %>
|
8
|
+
<%= f.text_area(:content, :style => "font-family: monospace; min-height: 40vh;", class: 'form-control') %>
|
9
|
+
</div>
|
10
|
+
|
11
|
+
<%= f.submit class: 'btn btn-primary' %>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<h1>
|
2
|
+
<% if @cms_layout_parent && @cms_layout_parent.respond_to?(:name) -%>
|
3
|
+
Layouts in <%= @cms_layout_parent.name %>
|
4
|
+
<% else -%>
|
5
|
+
Layouts
|
6
|
+
<% end -%>
|
7
|
+
</h1>
|
8
|
+
|
9
|
+
<ul class="list-group mb-4">
|
10
|
+
<% @cms_layouts.each do |cms_layout| %>
|
11
|
+
<li class="list-group-item">
|
12
|
+
<div class="row w-100">
|
13
|
+
<div class="col">
|
14
|
+
<%= cms_layout.name %>
|
15
|
+
</div>
|
16
|
+
<div class="col text-right">
|
17
|
+
<%= link_to "Edit", url_for(action: 'edit', id: cms_layout), class: 'btn btn-secondary btn-sm' %>
|
18
|
+
<%= link_to "Delete", url_for(action: 'destroy', id: cms_layout), method: 'DELETE', "data-confirm" => "Are you sure you want to delete this layout?", class: 'btn btn-danger btn-sm' %>
|
19
|
+
</div>
|
20
|
+
</div>
|
21
|
+
</li>
|
22
|
+
<% end -%>
|
23
|
+
</ul>
|
24
|
+
|
25
|
+
<%= link_to "New layout", url_for(action: 'new'), class: 'btn btn-primary' %>
|
@@ -1 +1 @@
|
|
1
|
-
<%=
|
1
|
+
<%= render_in_page_layout @page %>
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<% if f.object.errors.any? -%>
|
2
|
+
<div id="error_explanation">
|
3
|
+
<h2><%= pluralize(f.object.errors.count, "error") %> prohibited this partial from being saved:</h2>
|
4
|
+
|
5
|
+
<ul>
|
6
|
+
<% f.object.errors.full_messages.each do |message| -%>
|
7
|
+
<li><%= message %></li>
|
8
|
+
<% end -%>
|
9
|
+
</ul>
|
10
|
+
</div>
|
11
|
+
<% end -%>
|
12
|
+
|
13
|
+
<div class="form-group">
|
14
|
+
<%= f.label f.object.class.name_field %>
|
15
|
+
<%= f.text_field f.object.class.name_field, class: 'form-control' %>
|
16
|
+
</div>
|
17
|
+
|
18
|
+
<div class="form-group">
|
19
|
+
<%= f.label :content %>
|
20
|
+
<%= f.text_area(:content, :style => "font-family: monospace; min-height: 40vh;", class: 'form-control') %>
|
21
|
+
</div>
|
22
|
+
|
23
|
+
<%= f.submit class: 'btn btn-primary' %>
|
24
|
+
|
25
|
+
<p><b>Rendered html preview</b></p>
|
26
|
+
<div id="html-preview" style="border:1px solid; min-height: 10em;">
|
27
|
+
</div>
|
28
|
+
<br/><br/>
|
29
|
+
|
30
|
+
<%= javascript_include_tag "cadmus.previewablehtml.js" %>
|
31
|
+
<script type="text/javascript">
|
32
|
+
$(document).ready(function(){
|
33
|
+
$('.cadmus-previewable-html').cadmusPreviewableHtml();
|
34
|
+
});
|
35
|
+
</script>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<h1>
|
2
|
+
<% if @parent_model && @parent_model.respond_to?(:name) -%>
|
3
|
+
Partials in <%= @parent_model.name %>
|
4
|
+
<% else -%>
|
5
|
+
Partials
|
6
|
+
<% end -%>
|
7
|
+
</h1>
|
8
|
+
|
9
|
+
<ul class="list-group mb-4">
|
10
|
+
<% @cms_partials.each do |cms_partial| %>
|
11
|
+
<li class="list-group-item">
|
12
|
+
<div class="row w-100">
|
13
|
+
<div class="col">
|
14
|
+
<%= cms_partial.public_send(cms_partial.class.name_field) %>
|
15
|
+
</div>
|
16
|
+
<div class="col text-right">
|
17
|
+
<%= link_to "Edit", url_for(action: 'edit', id: cms_partial), class: 'btn btn-secondary btn-sm' %>
|
18
|
+
<%= link_to "Delete", url_for(action: 'destroy', id: cms_partial), method: 'DELETE', "data-confirm" => "Are you sure you want to delete this partial?", class: 'btn btn-danger btn-sm' %>
|
19
|
+
</div>
|
20
|
+
</div>
|
21
|
+
</li>
|
22
|
+
<% end -%>
|
23
|
+
</ul>
|
24
|
+
|
25
|
+
<%= link_to "New partial", url_for(action: 'new'), class: 'btn btn-primary' %>
|
data/bin/rake
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rake' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('rake', 'rake')
|
data/cadmus.gemspec
CHANGED
@@ -9,13 +9,13 @@ Gem::Specification.new do |gem|
|
|
9
9
|
gem.homepage = "http://github.com/gively/cadmus"
|
10
10
|
gem.license = "MIT"
|
11
11
|
|
12
|
-
gem.executables = `git ls-files --
|
12
|
+
gem.executables = `git ls-files -- exe/*`.split("\n").map{ |f| File.basename(f) }
|
13
13
|
gem.files = `git ls-files`.split("\n")
|
14
14
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
15
|
gem.name = "cadmus"
|
16
16
|
gem.require_paths = ["lib"]
|
17
17
|
gem.version = Cadmus::VERSION
|
18
18
|
|
19
|
-
gem.add_dependency("rails", ">=
|
19
|
+
gem.add_dependency("rails", ">= 5.0.0")
|
20
20
|
gem.add_dependency("liquid")
|
21
21
|
end
|
data/lib/cadmus.rb
CHANGED
@@ -1,14 +1,31 @@
|
|
1
|
+
require 'liquid'
|
2
|
+
|
1
3
|
require "cadmus/version"
|
4
|
+
|
5
|
+
require "cadmus/concerns/controller_with_parent"
|
6
|
+
require "cadmus/concerns/model_with_parent"
|
7
|
+
require "cadmus/concerns/liquid_template_field"
|
8
|
+
require "cadmus/concerns/other_class_accessor"
|
9
|
+
|
2
10
|
require "cadmus/routing"
|
3
11
|
require "cadmus/renderers"
|
4
|
-
require "cadmus/controller_extensions"
|
5
12
|
require "cadmus/slugs"
|
6
|
-
require "cadmus/liquid_template_field"
|
7
|
-
require "cadmus/page"
|
8
13
|
require "cadmus/tags"
|
14
|
+
require "cadmus/page"
|
15
|
+
require "cadmus/layout"
|
16
|
+
require "cadmus/partial"
|
17
|
+
require "cadmus/partial_file_system"
|
18
|
+
require "cadmus/pages_controller"
|
19
|
+
require "cadmus/partials_controller"
|
20
|
+
require "cadmus/layouts_controller"
|
21
|
+
|
9
22
|
require "rails"
|
23
|
+
require "cadmus/engine"
|
10
24
|
|
11
25
|
module Cadmus
|
12
|
-
|
13
|
-
|
14
|
-
|
26
|
+
extend Cadmus::Concerns::OtherClassAccessor
|
27
|
+
|
28
|
+
other_class_accessor :layout_model
|
29
|
+
other_class_accessor :page_model
|
30
|
+
other_class_accessor :partial_model
|
31
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Cadmus
|
2
|
+
module Concerns
|
3
|
+
module ControllerWithParent
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
class << self
|
8
|
+
attr_accessor :parent_model_name, :parent_model_class, :find_parent_by
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# This gets kind of meta.
|
13
|
+
#
|
14
|
+
# If cms_layout_parent_name and cms_layout_parent_class are both defined for this class, this method uses it to find
|
15
|
+
# the parent object in which layouts live. For example, if cms_layout_parent_class is Blog and
|
16
|
+
# cms_layout_parent_name is "blog", then this is equivalent to calling:
|
17
|
+
#
|
18
|
+
# @cms_layout_parent = Blog.where(:id => params["blog_id"]).first
|
19
|
+
#
|
20
|
+
# If you don't want to use :id to find the parent object, then redefine the find_parent_by method to return
|
21
|
+
# what you want to use.
|
22
|
+
def parent_model
|
23
|
+
return @parent_model if @parent_model
|
24
|
+
|
25
|
+
if parent_model_name && parent_model_class
|
26
|
+
parent_id_param = "#{parent_model_name}_id"
|
27
|
+
if params[parent_id_param]
|
28
|
+
@parent_model = parent_model_class.find_by(find_parent_by => params[parent_id_param])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
@parent_model
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns the name of the layout parent object. This will be used for determining the parameter name for
|
36
|
+
# finding the parent object. For example, if the parent name is "wiki", the finder will look in
|
37
|
+
# params["wiki_id"] to determine the object ID.
|
38
|
+
#
|
39
|
+
# By default, this will return the value of cms_layout_parent_name set at the controller class level, but can
|
40
|
+
# be overridden for cases where the layout parent name must be determined on a per-request basis.
|
41
|
+
def parent_model_name
|
42
|
+
self.class.parent_model_name
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns the class of the layout parent object. For example, if the pages used by this controller are
|
46
|
+
# children of a Section object, this method should return the Section class.
|
47
|
+
#
|
48
|
+
# By default, this will return the value of cms_layout_parent_class set at the controller class level, but can
|
49
|
+
# be overridden for cases where the layout parent class must be determined on a per-request basis.
|
50
|
+
def parent_model_class
|
51
|
+
self.class.parent_model_class
|
52
|
+
end
|
53
|
+
|
54
|
+
# Returns the field used to find the layout parent object. By default this is :id, but if you need to
|
55
|
+
# find the layout parent object using a different parameter (for example, if you use a "slug" field for
|
56
|
+
# part of the URL), this can be changed.
|
57
|
+
#
|
58
|
+
# By default this method takes its value from the "find_parent_by" accessor set at the controller class
|
59
|
+
# level, but it can be overridden for cases where the finder field name should be determined on a
|
60
|
+
# per-request basis.
|
61
|
+
def find_parent_by
|
62
|
+
self.class.find_parent_by || :id
|
63
|
+
end
|
64
|
+
|
65
|
+
def liquid_file_system
|
66
|
+
Cadmus::PartialFileSystem.new(parent_model)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|