manifest-rails 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +1 -1
- data/README.md +30 -0
- data/app/controllers/manifest/content_blocks_controller.rb +2 -0
- data/app/controllers/manifest/manifest_controller.rb +5 -0
- data/app/controllers/manifest/pages_controller.rb +1 -0
- data/app/controllers/manifest/sessions_controller.rb +1 -0
- data/app/controllers/pages_controller.rb +2 -0
- data/app/form_builders/manifest/labelled_form_builder.rb +1 -0
- data/app/models/content_block.rb +2 -0
- data/app/models/editor.rb +1 -0
- data/app/models/page.rb +8 -0
- data/app/views/layouts/manifest/manifest.html.erb +2 -2
- data/app/views/layouts/manifest/sessions.html.erb +2 -2
- data/config/initializers/manifest.rb +2 -0
- data/lib/active_record/base/data_type_for_manifest.rb +1 -0
- data/lib/generators/manifest/data_type/data_type_generator.rb +3 -0
- data/lib/generators/manifest/install/install_generator.rb +4 -0
- data/lib/manifest.rb +8 -1
- data/lib/manifest/version.rb +1 -1
- metadata +36 -24
- data/README.rdoc +0 -3
data/MIT-LICENSE
CHANGED
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Manifest
|
2
|
+
|
3
|
+
Manifest is a [Rails::Engine][rails_engine] content management system, packaged as the RubyGem [manifest-rails][manifest_rails_gem].
|
4
|
+
|
5
|
+
It was created out of frustration with the fact that many content management systems require hacks or breaking with their own conventions in order to implement true custom data types, and the fact that many content management systems require view-editing to be done from within the application itself, persisting view templates to the database.
|
6
|
+
|
7
|
+
In Manifest, custom data types are sets of Rails models, controllers, and views that Manifest has visibility of. This means that Manifest data types can either be generated with the built-in `manifest:data_type` generator, or can be constructed by hand and easily tied into Manifest.
|
8
|
+
|
9
|
+
Views in Manifest are views in Rails. Editing these views and templates is a matter of editing the public-facing views in `app/views` and any custom Manifest views in `app/views/manifest`.
|
10
|
+
|
11
|
+
## Getting Started
|
12
|
+
|
13
|
+
Getting started with Manifest is as easy as:
|
14
|
+
|
15
|
+
1. Add it to your `Gemfile`.
|
16
|
+
2. Require it in your `config/application.rb`.
|
17
|
+
3. Run the install generator and migrate the database.
|
18
|
+
|
19
|
+
Detailed instructions can be found in the [Wiki][wiki] on the [Getting Started][getting_started] page.
|
20
|
+
|
21
|
+
## License
|
22
|
+
|
23
|
+
Manifest was created by [Jonathan Clem][jclem] and is licensed under the [MIT license][license].
|
24
|
+
|
25
|
+
[rails_engine]: http://api.rubyonrails.org/classes/Rails/Engine.html
|
26
|
+
[manifest_rails_gem]: http://rubygems.org/gems/manifest-rails
|
27
|
+
[wiki]: https://github.com/jclem/manifest-rails/wiki
|
28
|
+
[getting_started]: https://github.com/jclem/manifest-rails/wiki/Getting-Started
|
29
|
+
[jclem]: http://jclem.net
|
30
|
+
[license]: https://github.com/jclem/manifest-rails/blob/master/MIT-LICENSE
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# Controls CRUD actions for {ContentBlock} objects.
|
1
2
|
class Manifest::ContentBlocksController < Manifest::ManifestController
|
2
3
|
before_filter :authorize_admin, except: [:index, :edit, :update]
|
3
4
|
|
@@ -46,6 +47,7 @@ class Manifest::ContentBlocksController < Manifest::ManifestController
|
|
46
47
|
|
47
48
|
private
|
48
49
|
|
50
|
+
# Non-admins may only edit the content of a {ContentBlock}.
|
49
51
|
def content_block_params
|
50
52
|
if current_editor.admin?
|
51
53
|
params[:content_block]
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# The primary Manifest admin controller. Mostly used for determining {#current_editor} and for authorization.
|
1
2
|
class Manifest::ManifestController < ApplicationController
|
2
3
|
before_filter :authorize
|
3
4
|
|
@@ -5,20 +6,24 @@ class Manifest::ManifestController < ApplicationController
|
|
5
6
|
|
6
7
|
private
|
7
8
|
|
9
|
+
# @return [Editor] the currently signed-in {Editor}, or nil.
|
8
10
|
def current_editor
|
9
11
|
@current_editor ||= Editor.find(session[:editor_id]) if session[:editor_id]
|
10
12
|
end
|
11
13
|
|
12
14
|
helper_method :current_editor
|
13
15
|
|
16
|
+
# Redirects to login if {#current_editor} is nil.
|
14
17
|
def authorize
|
15
18
|
redirect_to manifest_login_url if current_editor.nil?
|
16
19
|
end
|
17
20
|
|
21
|
+
# Used to protect sensitive {Page} and {ContentBlock} actions from non-admin {Editor}s.
|
18
22
|
def authorize_admin
|
19
23
|
redirect_to manifest_path, alert: 'Admins only' unless current_editor.admin?
|
20
24
|
end
|
21
25
|
|
26
|
+
# Expires the cached version of every {Page} object view.
|
22
27
|
def expire_all_pages
|
23
28
|
expire_page '/index.html'
|
24
29
|
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# The public-facing controller. Responsible for getting {Page} objects, collecting their {ContentBlock}s, and rendering their templates.
|
1
2
|
class PagesController < ApplicationController
|
2
3
|
layout 'public'
|
3
4
|
|
4
5
|
caches_page :show
|
5
6
|
|
7
|
+
# Finds the requested {Page} or raises ActiveRecord::RecordNotFound.
|
6
8
|
def show
|
7
9
|
if @page = Page.find(params[:id])
|
8
10
|
@content_blocks = @page.content_blocks
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# Helper for quickly building forms and templates without having to rewrite the same HTML element wrappers.
|
1
2
|
class Manifest::LabelledFormBuilder < ActionView::Helpers::FormBuilder
|
2
3
|
%w[text_field check_box collection_select check_box text_area date_select datetime_select time_select].each do |method_name|
|
3
4
|
define_method(method_name) do |name, *args|
|
data/app/models/content_block.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# Belongs to a {Page}. A chunk of presentable content, either made up of plain text or HTML.
|
1
2
|
class ContentBlock < ActiveRecord::Base
|
2
3
|
extend FriendlyId
|
3
4
|
friendly_id :title, use: :slugged
|
@@ -10,6 +11,7 @@ class ContentBlock < ActiveRecord::Base
|
|
10
11
|
|
11
12
|
default_scope includes(:page).order('pages.title')
|
12
13
|
|
14
|
+
# @return [String] a string of plain text or render-safe HTML.
|
13
15
|
def render
|
14
16
|
if allow_html
|
15
17
|
content.html_safe
|
data/app/models/editor.rb
CHANGED
data/app/models/page.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# Represents an individual site page, which has many {ContentBlock}s and has an associated template file.
|
1
2
|
class Page < ActiveRecord::Base
|
2
3
|
extend FriendlyId
|
3
4
|
friendly_id :title, use: :slugged
|
@@ -14,25 +15,32 @@ class Page < ActiveRecord::Base
|
|
14
15
|
|
15
16
|
default_scope order('title')
|
16
17
|
|
18
|
+
# @return [String] the path to the Page's template
|
17
19
|
def template_path
|
18
20
|
template_path_from_slug(slug)
|
19
21
|
end
|
20
22
|
|
21
23
|
private
|
22
24
|
|
25
|
+
# Creates the template file after the Page is created.
|
23
26
|
def create_template
|
24
27
|
%x(touch #{self.template_path})
|
25
28
|
end
|
26
29
|
|
30
|
+
# Renames the template file after the Page is updated.
|
27
31
|
def rename_template
|
28
32
|
old_template_path = template_path_from_slug(slug_was)
|
29
33
|
%x(mv #{old_template_path} #{template_path})
|
30
34
|
end
|
31
35
|
|
36
|
+
# Removes the template file after the Page is destroyed.
|
32
37
|
def remove_template
|
33
38
|
%x(rm #{template_path})
|
34
39
|
end
|
35
40
|
|
41
|
+
# Generates a Page template path given a slug.
|
42
|
+
# @param [String] slug a Page object's slug attribute.
|
43
|
+
# @return [String] the path to a Page's template based on the given slug.
|
36
44
|
def template_path_from_slug(slug)
|
37
45
|
"#{Rails.root}/app/views/pages/#{slug}.html.erb"
|
38
46
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
<html>
|
4
4
|
<head>
|
5
|
-
<title
|
5
|
+
<title><%= Manifest.configuration.app_name %></title>
|
6
6
|
|
7
7
|
<%= stylesheet_link_tag 'manifest/main' %>
|
8
8
|
<%= javascript_include_tag 'manifest/main' %>
|
@@ -13,7 +13,7 @@
|
|
13
13
|
</head>
|
14
14
|
<body>
|
15
15
|
<div class='app-nav'>
|
16
|
-
<h1
|
16
|
+
<h1><%= Manifest.configuration.app_name %></h1>
|
17
17
|
|
18
18
|
<nav>
|
19
19
|
<ul>
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
<html>
|
4
4
|
<head>
|
5
|
-
<title
|
5
|
+
<title><%= Manifest.configuration.app_name %></title>
|
6
6
|
|
7
7
|
<%= stylesheet_link_tag 'manifest/sessions' %>
|
8
8
|
<%= stylesheet_link_tag 'manifest/main' %>
|
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
<body>
|
16
16
|
<div class='app-nav'>
|
17
|
-
<h1
|
17
|
+
<h1><%= Manifest.configuration.app_name %></h1>
|
18
18
|
</div><!-- app-nav -->
|
19
19
|
|
20
20
|
<div class='app-content'>
|
@@ -1,4 +1,6 @@
|
|
1
1
|
module Manifest
|
2
|
+
# Searches for models containing the {ActiveRecord::Base#data_type_for_manifest}
|
3
|
+
# and touches them so that #data_type_for_manifest is called at app initialization.
|
2
4
|
def self.add_app_models_to_manifest_data_types
|
3
5
|
models = Dir.glob("#{Rails.root}/app/models/*")
|
4
6
|
|
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'rails/generators/active_record'
|
2
2
|
|
3
|
+
# Creates templates and migrations for custom Manifest data types.
|
4
|
+
# Example:
|
5
|
+
# rails generate manifest:data_type Person first_name:string last_name:string
|
3
6
|
class Manifest::DataTypeGenerator < ActiveRecord::Generators::Base
|
4
7
|
source_root File.expand_path('../templates', __FILE__)
|
5
8
|
argument :attributes, type: :array, default: [], banner: 'field:type field:type'
|
@@ -1,5 +1,9 @@
|
|
1
1
|
require 'rails/generators/active_record'
|
2
2
|
|
3
|
+
# Creates templates and migrations for the initial Manifest install.
|
4
|
+
# Example:
|
5
|
+
# rails generate manifest:install Page
|
6
|
+
# The "Page" argument is completely arbitrary.
|
3
7
|
class Manifest::InstallGenerator < ActiveRecord::Generators::Base
|
4
8
|
source_root File.expand_path('../templates', __FILE__)
|
5
9
|
|
data/lib/manifest.rb
CHANGED
@@ -5,6 +5,7 @@ require 'sass-rails'
|
|
5
5
|
require 'compass-rails'
|
6
6
|
require 'tinymce-rails'
|
7
7
|
|
8
|
+
# The primary Manifest namespace. Note that {Page}, {Editor}, and {ContentBlock} are not namespaced models.
|
8
9
|
module Manifest
|
9
10
|
def self.configure
|
10
11
|
yield configuration
|
@@ -14,11 +15,17 @@ module Manifest
|
|
14
15
|
@configuration ||= Configuration.new
|
15
16
|
end
|
16
17
|
|
18
|
+
# App configuration, which can be altered in config/initializers/manifest.rb
|
19
|
+
# Example:
|
20
|
+
# Manifest.configure do |config|
|
21
|
+
# config.app_name = "My App"
|
22
|
+
# end
|
17
23
|
class Configuration
|
18
|
-
attr_accessor :data_types
|
24
|
+
attr_accessor :data_types, :app_name
|
19
25
|
|
20
26
|
def initialize
|
21
27
|
@data_types = []
|
28
|
+
@app_name = 'Manifest'
|
22
29
|
end
|
23
30
|
end
|
24
31
|
end
|
data/lib/manifest/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: manifest-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70330392459720 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.2.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70330392459720
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: friendly_id
|
27
|
-
requirement: &
|
27
|
+
requirement: &70330392458920 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70330392458920
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sass-rails
|
38
|
-
requirement: &
|
38
|
+
requirement: &70330392458240 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 3.2.3
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70330392458240
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: compass-rails
|
49
|
-
requirement: &
|
49
|
+
requirement: &70330392457720 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70330392457720
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: bcrypt-ruby
|
60
|
-
requirement: &
|
60
|
+
requirement: &70330392457100 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 3.0.0
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70330392457100
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: tinymce-rails
|
71
|
-
requirement: &
|
71
|
+
requirement: &70330392456560 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70330392456560
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: sqlite3
|
82
|
-
requirement: &
|
82
|
+
requirement: &70330392456040 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70330392456040
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rspec-rails
|
93
|
-
requirement: &
|
93
|
+
requirement: &70330392455540 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70330392455540
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: factory_girl_rails
|
104
|
-
requirement: &
|
104
|
+
requirement: &70330392455060 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,7 +109,18 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70330392455060
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: yard
|
115
|
+
requirement: &70330392454580 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: *70330392454580
|
113
124
|
description: Manifest allows for the creation of simple content management with support
|
114
125
|
for easy custom data types. It attempts to preserve the Rails way of working where
|
115
126
|
possible.
|
@@ -175,7 +186,7 @@ files:
|
|
175
186
|
- lib/tasks/manifest_tasks.rake
|
176
187
|
- MIT-LICENSE
|
177
188
|
- Rakefile
|
178
|
-
- README.
|
189
|
+
- README.md
|
179
190
|
homepage: http://github.com/jclem/manifest-rails
|
180
191
|
licenses: []
|
181
192
|
post_install_message:
|
@@ -190,7 +201,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
190
201
|
version: '0'
|
191
202
|
segments:
|
192
203
|
- 0
|
193
|
-
hash:
|
204
|
+
hash: 1014662028778785223
|
194
205
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
195
206
|
none: false
|
196
207
|
requirements:
|
@@ -199,11 +210,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
210
|
version: '0'
|
200
211
|
segments:
|
201
212
|
- 0
|
202
|
-
hash:
|
213
|
+
hash: 1014662028778785223
|
203
214
|
requirements: []
|
204
215
|
rubyforge_project:
|
205
|
-
rubygems_version: 1.8.
|
216
|
+
rubygems_version: 1.8.17
|
206
217
|
signing_key:
|
207
218
|
specification_version: 3
|
208
219
|
summary: Manifest is a Rails Engine content management system
|
209
220
|
test_files: []
|
221
|
+
has_rdoc:
|
data/README.rdoc
DELETED