tb_cms 1.1.2 → 1.1.3

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
  SHA1:
3
- metadata.gz: 42c344bf641663acb745ec63487f3bc3991bdeff
4
- data.tar.gz: 04187a4e8221bb57b592cb6cc164939267ab87ee
3
+ metadata.gz: 2989c1cf4dd02e1dd82aa3d0e44943ab0459bfd9
4
+ data.tar.gz: 488799900f0342b2fba67d8ccb87fb1f1dfeff4f
5
5
  SHA512:
6
- metadata.gz: 3b375f04f8021e21612a92982a3d5fa2b6242b874fe3f8826959b9be29b4ac5d7684cac3c7a9b23feb771c5e107aa9d335cad324c8b05823e722c7c9776bd29f
7
- data.tar.gz: faa30c0d60fbe576157f9f09f51aa10a709405c170d781e7bf4a902bd0c0168771b291ddddd9cb92a7b5dbc1a130644a52609e38bc045d163bd86f333e02b4ec
6
+ metadata.gz: e99c51f09cc14b669e335baee58243d602a514eec2ed15c83539bc672097559253012917722c478f3c36fe8556fcfec93231cfa4e78542b66404a0d31057fc1d
7
+ data.tar.gz: 176da5b738c8e3838609b50a336178c6e28fd3bf45296a67cd993bb9e569afc01a99bab9addfa5bd492c2ef5ad5f1609c7ca56aaa61c9e1a58444e07f47d691b
data/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # TB CMS
2
+
3
+ TB CMS is a content managment engine intended for use with Rails and [Twice Baked](https://bitbucket.org/westlakedesign/tb_core/).
4
+
5
+ ## Installation
6
+
7
+ First, it is recommended you run the steps listed in the "Installation/Usage" section of the [TB Core](https://bitbucket.org/westlakedesign/tb_core/) README file. Then, perform the following steps:
8
+
9
+ 1. Add the following to your Gemfile
10
+
11
+ gem 'tb_cms'
12
+
13
+ 2. Run bundle install
14
+ 3. Copy in database migrations to your new rails project
15
+
16
+ bundle exec rake railties:install:migrations
17
+ rake db:migrate
18
+
19
+ 4. Restart your application
20
+
21
+ ## Configuration
22
+
23
+ TB CMS accepts the following configuration options.
24
+
25
+ Spud::Cms.configure do |config|
26
+ config.menus_enabled = true
27
+ end
28
+
29
+ ## Defining Layouts
30
+
31
+ By default, CMS pages will use your standard `application.html.erb` layout. Chances are you will eventually want to specify different layouts for different pages. This is where page layouts come in handy.
32
+
33
+ A page layout is essentially a plain old Rails layout file with a little bit of metadata inserted at the top. The following example defines a layout with two content blocks, Left and Right.
34
+
35
+ <%
36
+ #template_name: Two Column
37
+ #html: Left
38
+ #html: Right
39
+ %>
40
+ <div class="left">
41
+ <%= yield :left %>
42
+ </div>
43
+ <div class="right">
44
+ <%= yield :right %>
45
+ </div>
46
+
47
+ You may also use the `spud:cms:layout` generator to quickly generate a layout file.
48
+
49
+ rails g spud:cms:layout two_column left right
50
+
51
+ ## Layout Actions
52
+
53
+ Layout actions provide a mechanism for running custom Ruby code when a given layout is hit. For example, suppose you have an `About` layout that needs to show an array of `Employee` records. Let's also imagine you want to show a different list of employees for `get` and `post` requests.
54
+
55
+ Create a controller concern at `app/controllers/concerns/spud_cms_layout_actions.rb` with the following code.
56
+
57
+ module SpudCmsLayoutActions
58
+ extend ActiveSupport::Concern
59
+
60
+ def about_action(method)
61
+ if method == :post
62
+ @employees = Employee.where(:secret_agent => true).order('first_name asc')
63
+ else
64
+ @employees = Employee.where(:is_cool => true).order('first_name asc')
65
+ end
66
+ end
67
+
68
+ end
69
+
70
+ If you ran the `spud:cms:layout` generator described earlier, the concern and empty action would have been created for you automatically.
71
+
72
+ ## Using Liquid Templates
73
+
74
+ Pages use the [liquid](https://github.com/Shopify/liquid) template syntax engine created by Shopify. This allows you to easily inject variables into your pages in the page editor. Example:
75
+
76
+ <h2>{{page.name}}</h2>
77
+
78
+ ## Using Menus
79
+
80
+ A lot of cms engines allow you to render your navigation links in a ul block by using your page tree structure. In a lot of cases this is insufficient as some sites have urls that redirect to pages outside of your cms. This is where menus come in. They can be built in the admin control panel.
81
+ In your application layout file or any erb template you can render a ul block like so
82
+
83
+ <%= sp_list_menu({:id => "navigation",:name => "Main"}) %>
84
+
85
+ This will output a <ul id="navigation"></ul> block for the menu you created in admin named "Main"
86
+
87
+ ## Testing
88
+
89
+ TB CMS uses RSpec for testing. Get the tests running with a few short commands:
90
+
91
+ 1. Create and migrate the databases:
92
+
93
+ rake db:create
94
+ rake db:migrate
95
+
96
+ 2. Load the schema in to the test database:
97
+
98
+ rake app:db:test:prepare
99
+
100
+ 3. Run the tests with RSpec
101
+
102
+ rspec spec
103
+
104
+ After the tests have completed the current code coverage stats is available by opening ```/coverage/index.html``` in a browser.
105
+
106
+
107
+
@@ -0,0 +1,4 @@
1
+ module SpudCmsLayoutActions
2
+ extend ActiveSupport::Concern
3
+
4
+ end
@@ -1,4 +1,5 @@
1
1
  class PagesController < ApplicationController
2
+ include SpudCmsLayoutActions
2
3
 
3
4
  respond_to :html
4
5
  before_filter :set_default_content_type
@@ -61,9 +62,12 @@ class PagesController < ApplicationController
61
62
 
62
63
  layout = @page.layout || layout
63
64
 
65
+ action_name = "#{layout}_action"
66
+ if respond_to?(action_name)
67
+ send(action_name, request.method.downcase.to_sym)
68
+ end
64
69
 
65
70
  render :layout => layout
66
-
67
71
  end
68
72
 
69
73
  private
@@ -82,6 +82,7 @@ module Cms::ApplicationHelper
82
82
  end
83
83
 
84
84
  def sp_list_menu(options = {})
85
+ options[:path] = request.original_fullpath
85
86
 
86
87
  if !options.has_key?(:name)
87
88
  logger.debug 'sp_list_menu require a :name option'
@@ -0,0 +1,34 @@
1
+ require 'rails/generators/migration'
2
+
3
+ class Spud::Cms::LayoutGenerator < ::Rails::Generators::Base
4
+ desc "This generator creates a new spud cms layout file"
5
+ argument :template_name, :type => :string
6
+ argument :attributes, :type => :array, :default => [], :banner => "content_block content_block"
7
+
8
+ source_root File.expand_path('../templates', __FILE__)
9
+
10
+ def create_layout
11
+ template "layout.html.erb", "app/views/layouts/#{template_name.downcase.underscore}.html.erb"
12
+ end
13
+
14
+ def create_layout_action
15
+ concern_path = 'app/controllers/concerns/spud_cms_layout_actions.rb'
16
+ if !File.exist?(File.join(Rails.root, concern_path))
17
+ template 'layout_actions.rb', 'app/controllers/concerns/spud_cms_layout_actions.rb'
18
+ end
19
+ inject_into_file concern_path, :after => "extend ActiveSupport::Concern\n" do <<-HEREDOC
20
+
21
+ def #{template_name.downcase.underscore}_action(method)
22
+ # this action is called when the #{template_name} cms layout is used
23
+ end
24
+ HEREDOC
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def concern_content
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,18 @@
1
+ <%%
2
+ #template_name: <%=template_name.humanize.titlecase%>
3
+ <%-attributes.each do |attribute|-%>
4
+ <%="#html: #{attribute.humanize.titlecase}\n"-%>
5
+ <%-end-%>
6
+ %>
7
+
8
+ <%% content_for :body do %>
9
+ <div class="layout-<%= template_name.downcase.underscore %>">
10
+ <% attributes.each do |attribute| %>
11
+ <div class="content-<%= attribute.downcase %>">
12
+ <%%= yield :<%=attribute.downcase.underscore%> %>
13
+ </div>
14
+ <% end %>
15
+ </div>
16
+ <%% end %>
17
+
18
+ <%%= render :template => '/layouts/application' %>
@@ -0,0 +1,4 @@
1
+ module SpudCmsLayoutActions
2
+ extend ActiveSupport::Concern
3
+
4
+ end
@@ -119,7 +119,7 @@ module Spud
119
119
  end
120
120
 
121
121
  def engines
122
- Rails::Application::Railties.engines
122
+ ::Rails::Engine.subclasses.map(&:instance)
123
123
  end
124
124
  end
125
125
  end
@@ -1,5 +1,5 @@
1
1
  module Spud
2
2
  module Cms
3
- VERSION = "1.1.2"
3
+ VERSION = "1.1.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tb_cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Westlake Design
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-24 00:00:00.000000000 Z
11
+ date: 2014-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -186,13 +186,11 @@ extensions: []
186
186
  extra_rdoc_files: []
187
187
  files:
188
188
  - MIT-LICENSE
189
- - README.markdown
189
+ - README.md
190
190
  - Rakefile
191
191
  - app/assets/images/spud/admin/menus_thumb.png
192
- - app/assets/images/spud/admin/menus_thumb@2x.png
193
192
  - app/assets/images/spud/admin/pages_thumb.png
194
193
  - app/assets/images/spud/admin/snippets_thumb.png
195
- - app/assets/images/spud/admin/snippets_thumb@2x.png
196
194
  - app/assets/javascripts/admin/cms/application.js
197
195
  - app/assets/javascripts/admin/cms/menu_items.js
198
196
  - app/assets/javascripts/admin/cms/pages.js
@@ -202,6 +200,7 @@ files:
202
200
  - app/controllers/admin/pages_controller.rb
203
201
  - app/controllers/admin/snippets_controller.rb
204
202
  - app/controllers/cms/sitemaps_controller.rb
203
+ - app/controllers/concerns/spud_cms_layout_actions.rb
205
204
  - app/controllers/pages_controller.rb
206
205
  - app/helpers/cms/application_helper.rb
207
206
  - app/models/spud_menu.rb
@@ -262,8 +261,9 @@ files:
262
261
  - db/migrate/20121119025608_create_spud_snippets.rb
263
262
  - db/migrate/20121119030136_change_liquid_tags_to_polymorphic.rb
264
263
  - db/migrate/20140110142037_drop_spud_page_liquid_tags.rb
265
- - lib/generators/spud/cms/template_generator.rb
266
- - lib/generators/spud/cms/templates/template.html.erb
264
+ - lib/generators/spud/cms/layout_generator.rb
265
+ - lib/generators/spud/cms/templates/layout.html.erb
266
+ - lib/generators/spud/cms/templates/layout_actions.rb
267
267
  - lib/spud_cms/configuration.rb
268
268
  - lib/spud_cms/engine.rb
269
269
  - lib/spud_cms/liquid_snippet.rb
data/README.markdown DELETED
@@ -1,110 +0,0 @@
1
- Spud CMS
2
- ========
3
-
4
- Spud CMS is a CMS Engine designed to be robust, easy to use, and light weight.
5
-
6
-
7
- Installation/Usage
8
- ------------------
9
-
10
- 1. In your Gemfile add the following
11
-
12
- gem 'tb_cms'
13
-
14
- 2. Run bundle install
15
- 3. Copy in database migrations to your new rails project
16
-
17
- bundle exec rake railties:install:migrations
18
- rake db:migrate
19
- 4. Change ApplicationController to inherit from Spud::ApplicationController instead of ActionController::Base
20
-
21
- class ApplicationController < Spud::ApplicationController
22
-
23
- 5. run a rails server instance and point your browser to /spud/admin
24
-
25
- Routing to the CMS Engine
26
- --------------------------
27
- Routing your home page to the CMS engine is fairly straight forward.
28
- in your applications application.rb file add a configure block as such
29
-
30
-
31
- Spud::Cms.configure do |config|
32
- config.menus_enabled = true
33
- config.root_page_name = "home"
34
- end
35
-
36
-
37
-
38
- Where "home" is the page name you wish to use.
39
-
40
- Pages will default render to the 'application' layout of your application. You can change this by using templates to specify base layouts.
41
-
42
- Defining Templates / Layouts
43
- ----------------------------
44
- Spud CMS has recently changed its template structure. The admin templates area is no longer with us. In Spud CMS templates are defined similar to how an asset pipeline manifest is defined. At the top of your layout files a series of comments can be used to define the name of the template, and the content_for blocks that are editable by the user.
45
-
46
- Example:
47
-
48
- <%
49
- #template_name: 2 Column Page
50
- #html: Left
51
- #html: Right
52
- %>
53
-
54
- Optionally a description can be passed as well as a `site_name: default` for multisite mode.
55
-
56
-
57
- Using Liquid Template Engine
58
- ----------------------------
59
- Spud CMS utilizes the liquid template syntax engine created by Shopify. This allows you to easily inject variables into your pages in the page editor. Example:
60
-
61
- <h2>{{page.name}}</h2>
62
-
63
- Using Menus
64
- -----------
65
- A lot of cms engines allow you to render your navigation links in a ul block by using your page tree structure. In a lot of cases this is insufficient as some sites have urls that redirect to pages outside of your cms. This is where menus come in. They can be built in the spud admin control panel.
66
- In your application layout file or any erb template you can render a ul block like so
67
-
68
- <%=sp_list_menu({:id => "navigation",:name => "Main"})%>
69
-
70
- This will output a <ul id="navigation"></ul> block for the menu you created in admin named "Main"
71
-
72
- Adding Your Own Engines
73
- -----------------------
74
-
75
- Creating a rails engine that ties into spud admin is fairly straight forward
76
- In your new engine add spud_admin as a dependency and create an initializer inside your engine class as such:
77
-
78
- initializer :admin do
79
- Spud::Core.configure do |config|
80
- config.admin_applications += [{:name => "Pages",:thumbnail => "spud/admin/pages_thumb.png",:url => "/spud/admin/pages",:order => 0}]
81
-
82
- end
83
- end
84
-
85
- You can use the layouts provided with spud admin by using 'spud/admin/application' or 'spud/admin/detail' layouts
86
-
87
- When creating controllers for the admin panel create them in the Admin Namespace and have them extend Admin::ApplicationController for automatic user authentication restrictions.
88
-
89
- Testing
90
- -----------------
91
-
92
- Spud uses RSpec for testing. Get the tests running with a few short commands:
93
-
94
- 1. Create and migrate the databases:
95
-
96
- rake db:create
97
- rake db:migrate
98
-
99
- 2. Load the schema in to the test database:
100
-
101
- rake app:db:test:prepare
102
-
103
- 3. Run the tests with RSpec
104
-
105
- rspec spec
106
-
107
- After the tests have completed the current code coverage stats is available by opening ```/coverage/index.html``` in a browser.
108
-
109
-
110
-
@@ -1,17 +0,0 @@
1
- require 'rails/generators/migration'
2
-
3
- class Spud::Cms::TemplateGenerator < ::Rails::Generators::Base
4
- desc "This generator creates a new spud cms layout file"
5
- argument :template_name, :type => :string
6
- argument :attributes, :type => :array, :default => [], :banner => "content_block content_block"
7
-
8
- source_root File.expand_path('../templates', __FILE__)
9
-
10
- def create_module
11
- template "template.html.erb", "app/views/layouts/#{template_name.downcase.underscore}.html.erb"
12
- end
13
-
14
- private
15
-
16
-
17
- end
@@ -1,28 +0,0 @@
1
- <%%
2
- #template_name: <%=template_name.humanize.titlecase%>
3
- <%-attributes.each do |attribute|-%>
4
- <%="#html: #{attribute.humanize.titlecase}\n"-%>
5
- <%-end-%>
6
- %>
7
-
8
- <!DOCTYPE html>
9
- <html>
10
- <head>
11
- <title><%%=content_for?(:title) ? yield(:title) : Spud::Core.site_name%></title>
12
- <%%= stylesheet_link_tag "application", :media => "all" %>
13
- <%%= javascript_include_tag "application" %>
14
- <%%= csrf_meta_tags %>
15
- <%%= yield :head%>
16
- </head>
17
- <body>
18
-
19
- <%attributes.each do |attribute|%>
20
- <%if(attribute.downcase == 'body')%>
21
- <%%=yield%>
22
- <%else%>
23
- <%%=yield :<%=attribute.downcase.underscore%>%>
24
- <%end%>
25
- <%end%>
26
-
27
- </body>
28
- </html>