activeadmin-cms 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +73 -0
- data/Rakefile +27 -0
- data/lib/active_admin/cms.rb +54 -0
- data/lib/active_admin/cms/content.rb +71 -0
- data/lib/active_admin/cms/content_type.rb +73 -0
- data/lib/active_admin/cms/content_types/image.rb +17 -0
- data/lib/active_admin/cms/content_types/large_image.rb +21 -0
- data/lib/active_admin/cms/content_types/string.rb +10 -0
- data/lib/active_admin/cms/content_types/text.rb +13 -0
- data/lib/active_admin/cms/content_types/text_and_image.rb +12 -0
- data/lib/active_admin/cms/controller_extensions.rb +27 -0
- data/lib/active_admin/cms/helpers/cms_helper.rb +13 -0
- data/lib/active_admin/cms/page.rb +77 -0
- data/lib/active_admin/cms/recipe.rb +45 -0
- data/lib/active_admin/cms/recipe/ingredient.rb +56 -0
- data/lib/active_admin/cms/recipe/section.rb +36 -0
- data/lib/active_admin/cms/recipes/section_helper.rb +99 -0
- data/lib/active_admin/cms/uploaders/content_file_uploader.rb +56 -0
- data/lib/active_admin/cms/uploaders/content_image_uploader.rb +62 -0
- data/lib/active_admin/cms/uploaders/large_image_uploader.rb +66 -0
- data/lib/active_admin/cms/utility/class_level_inheritable_attributes.rb +31 -0
- data/lib/activeadmin-cms.rb +6 -0
- data/lib/activeadmin-cms/version.rb +3 -0
- data/lib/activeadmin/cms.rb +1 -0
- data/lib/generators/active_admin/cms/install/install_generator.rb +39 -0
- data/lib/generators/active_admin/cms/install/templates/initializer.rb +7 -0
- data/lib/generators/active_admin/cms/install/templates/migrations/1_install_aacms.rb +29 -0
- data/lib/generators/active_admin/cms/page/page_generator.rb +41 -0
- data/lib/generators/active_admin/cms/page/templates/admin/pages.rb.erb +39 -0
- data/lib/generators/active_admin/cms/page/templates/migrations/1_create_pages.rb +25 -0
- data/lib/generators/active_admin/cms/page/templates/page.rb.erb +3 -0
- data/lib/generators/active_admin/cms/page/templates/views/admin/cms/page.html.haml +0 -0
- data/lib/generators/active_admin/cms/page/templates/views/admin/cms/pages/_form.html.haml +20 -0
- data/lib/generators/active_admin/cms/page/templates/views/admin/cms/pages/_ingredient.html.haml +7 -0
- data/lib/generators/active_admin/cms/page/templates/views/admin/cms/pages/_section.html.haml +6 -0
- data/lib/generators/active_admin/cms/page/templates/views/admin/cms/pages/_show.html.haml +10 -0
- data/lib/generators/active_admin/cms/recipe/recipe_generator.rb +42 -0
- data/lib/generators/active_admin/cms/recipe/templates/recipe.rb.erb +20 -0
- data/lib/tasks/activeadmin-cms_tasks.rake +20 -0
- metadata +432 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
= ActiveAdmin Cms
|
2
|
+
|
3
|
+
{<img src="https://secure.travis-ci.org/adamphillips/activeadmin-cms.png" alt="Build Status" />}[http://travis-ci.org/adamphillips/activeadmin-cms]
|
4
|
+
{<img src="https://codeclimate.com/badge.png" />}[https://codeclimate.com/github/adamphillips/activeadmin-cms]
|
5
|
+
|
6
|
+
A simple CMS extension for ActiveAdmin.
|
7
|
+
|
8
|
+
== To Install
|
9
|
+
|
10
|
+
First you need to add ActiveAdmin Cms to your gemfile and run a bundle install
|
11
|
+
|
12
|
+
# Gemfile
|
13
|
+
gem 'activeadmin-cms'
|
14
|
+
|
15
|
+
# On command line
|
16
|
+
> bundle install
|
17
|
+
|
18
|
+
=== Run active admin install
|
19
|
+
|
20
|
+
> rails g active_admin:install
|
21
|
+
|
22
|
+
Follow the on-screen instructions.
|
23
|
+
|
24
|
+
The default user has a login of 'admin@example.com' and a password of 'password'.
|
25
|
+
|
26
|
+
== Configure Fog
|
27
|
+
|
28
|
+
Create a new file in config/initializers called fog.rb to setup fog.
|
29
|
+
|
30
|
+
# config/initializers/fog.rb
|
31
|
+
CarrierWave.configure do |config|
|
32
|
+
config.fog_credentials = {
|
33
|
+
:provider => 'AWS',
|
34
|
+
:aws_access_key_id => '-aws-access-key-',
|
35
|
+
:aws_secret_access_key => '-aws-secret-,
|
36
|
+
:region => 'eu-west-1'
|
37
|
+
}
|
38
|
+
config.fog_host = "//mywebsite.co.uk.s3.amazonaws.com"
|
39
|
+
config.fog_directory = "mywebsite.co.uk"
|
40
|
+
end
|
41
|
+
|
42
|
+
=== Run CMS install
|
43
|
+
|
44
|
+
> rails g active_admin:cms:install
|
45
|
+
|
46
|
+
=== Generate a page class
|
47
|
+
|
48
|
+
> rails g active_admin:cms:page Page
|
49
|
+
|
50
|
+
=== Generate a recipe
|
51
|
+
|
52
|
+
> rails g active_admin:cms:recipe Default
|
53
|
+
|
54
|
+
You will need to also create a migration to insert a database record for the recipe
|
55
|
+
|
56
|
+
> rails g migration AddDefaultRecipe
|
57
|
+
|
58
|
+
# db/migrations/123456789_add_default_recipe.rb
|
59
|
+
class AddDefaultRecipe < ActiveRecord::Migration
|
60
|
+
def up
|
61
|
+
r = Recipes::Default.new
|
62
|
+
r.title = 'Default'
|
63
|
+
r.type = 'Recipes::Default'
|
64
|
+
r.save
|
65
|
+
end
|
66
|
+
|
67
|
+
def down
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
This project rocks and uses MIT-LICENSE.
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'ActiveadminCms'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'haml'
|
2
|
+
require 'carrierwave'
|
3
|
+
require 'carrierwave_backgrounder'
|
4
|
+
require 'carrierwave/orm/activerecord'
|
5
|
+
|
6
|
+
require 'active_admin/cms/helpers/cms_helper'
|
7
|
+
require 'active_admin/cms/utility/class_level_inheritable_attributes'
|
8
|
+
|
9
|
+
module ActiveAdmin
|
10
|
+
module Cms
|
11
|
+
module ContentTypes
|
12
|
+
end
|
13
|
+
module Recipes
|
14
|
+
module SectionHelper
|
15
|
+
module SectionContainer
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
module Uploaders
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'acts_as_markup'
|
25
|
+
require 'acts_as_markup/railtie'
|
26
|
+
require 'acts_as_markup/active_record_extension'
|
27
|
+
require 'acts_as_markup/stringlike'
|
28
|
+
|
29
|
+
ActsAsMarkup.markdown_library = :rdiscount
|
30
|
+
|
31
|
+
require 'active_admin/cms/uploaders/content_file_uploader'
|
32
|
+
require 'active_admin/cms/uploaders/content_image_uploader'
|
33
|
+
require 'active_admin/cms/uploaders/large_image_uploader'
|
34
|
+
|
35
|
+
require 'active_admin/cms/content'
|
36
|
+
require 'active_admin/cms/content_type'
|
37
|
+
require 'active_admin/cms/controller_extensions'
|
38
|
+
require 'active_admin/cms/page'
|
39
|
+
require 'active_admin/cms/recipe'
|
40
|
+
|
41
|
+
ActiveAdmin::Cms::Recipe.autoload :Ingredient, 'active_admin/cms/recipe/ingredient'
|
42
|
+
ActiveAdmin::Cms::Recipe.autoload :Section, 'active_admin/cms/recipe/section'
|
43
|
+
|
44
|
+
require 'active_admin/cms/recipes/section_helper'
|
45
|
+
|
46
|
+
ActiveAdmin::Cms::ContentTypes.autoload :LargeImage, 'active_admin/cms/content_types/large_image'
|
47
|
+
ActiveAdmin::Cms::ContentTypes.autoload :Image, 'active_admin/cms/content_types/image'
|
48
|
+
ActiveAdmin::Cms::ContentTypes.autoload :String, 'active_admin/cms/content_types/string'
|
49
|
+
ActiveAdmin::Cms::ContentTypes.autoload :Text, 'active_admin/cms/content_types/text'
|
50
|
+
ActiveAdmin::Cms::ContentTypes.autoload :TextAndImage, 'active_admin/cms/content_types/text_and_image'
|
51
|
+
#require 'active_admin/cms/content_types/image'
|
52
|
+
#require 'active_admin/cms/content_types/string'
|
53
|
+
#require 'active_admin/cms/content_types/text'
|
54
|
+
#require 'active_admin/cms/content_types/text_and_image'
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
module Cms
|
3
|
+
class Content < ActiveRecord::Base
|
4
|
+
|
5
|
+
include ActionView::Helpers
|
6
|
+
include Haml::Helpers
|
7
|
+
|
8
|
+
class << self
|
9
|
+
include ActsAsMarkup::ActiveRecordExtension::ClassMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
self.table_name = 'content'
|
13
|
+
|
14
|
+
belongs_to :page, :class_name => 'Cms::Page'
|
15
|
+
|
16
|
+
acts_as_markdown :text
|
17
|
+
|
18
|
+
after_initialize do
|
19
|
+
self.class.mount_uploader :image, content_type.image_uploader
|
20
|
+
self.class.mount_uploader :file, ActiveAdmin::Cms::Uploaders::ContentFileUploader
|
21
|
+
end
|
22
|
+
|
23
|
+
#process_in_background :image
|
24
|
+
#process_in_background :file
|
25
|
+
|
26
|
+
def content_type
|
27
|
+
content_type_class.constantize if content_type_class
|
28
|
+
end
|
29
|
+
|
30
|
+
def content_type_class
|
31
|
+
super || 'ActiveAdmin::Cms::ContentTypes::String'
|
32
|
+
end
|
33
|
+
|
34
|
+
def content_type=(type)
|
35
|
+
update_attribute :content_type_class, type.to_s
|
36
|
+
end
|
37
|
+
|
38
|
+
def image_uploader
|
39
|
+
content_type.image_uploader
|
40
|
+
end
|
41
|
+
|
42
|
+
def set_content(value)
|
43
|
+
self.send("#{self.content_type.input_field}=", value)
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_html(options = {})
|
47
|
+
#debugger
|
48
|
+
html = ''
|
49
|
+
|
50
|
+
if content_type.text_allowed?
|
51
|
+
if content_type.markdown_allowed?
|
52
|
+
html += text.to_html
|
53
|
+
else
|
54
|
+
html += text.to_s
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
if content_type.image_allowed?
|
59
|
+
if image
|
60
|
+
tag_options = options[:tag]
|
61
|
+
tag_options ||= {}
|
62
|
+
tag_options[:src] ||= image.url(options[:version])
|
63
|
+
html += tag(:img, tag_options) if tag_options[:src] != 'missing.png'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
html
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
module Cms
|
3
|
+
class ContentType
|
4
|
+
include ActiveAdmin::Cms::Utility::ClassLevelInheritableAttributes
|
5
|
+
cattr_inheritable :text_allowed, :markdown_allowed, :text_required,
|
6
|
+
:image_allowed, :image_required,
|
7
|
+
:file_allowed, :file_required,
|
8
|
+
:input_field,
|
9
|
+
:input_opts,
|
10
|
+
:description,
|
11
|
+
:partial,
|
12
|
+
:display_preview, :preview_options,
|
13
|
+
:options
|
14
|
+
|
15
|
+
@text_allowed = false
|
16
|
+
:A
|
17
|
+
@markdown_allowed = false
|
18
|
+
@text_required = false
|
19
|
+
@image_allowed = false
|
20
|
+
@image_required = false
|
21
|
+
@file_allowed = false
|
22
|
+
@file_required = false
|
23
|
+
|
24
|
+
@input_field = :text
|
25
|
+
@input_opts = {:as => :string}
|
26
|
+
@description = ''
|
27
|
+
@partial = nil
|
28
|
+
@display_preview = false
|
29
|
+
@preview_options = {}
|
30
|
+
@options = {}
|
31
|
+
|
32
|
+
class << self
|
33
|
+
|
34
|
+
def text_allowed?
|
35
|
+
@text_allowed
|
36
|
+
end
|
37
|
+
|
38
|
+
def markdown_allowed?
|
39
|
+
@markdown_allowed
|
40
|
+
end
|
41
|
+
|
42
|
+
def text_required?
|
43
|
+
@text_required
|
44
|
+
end
|
45
|
+
|
46
|
+
def image_allowed?
|
47
|
+
@image_allowed
|
48
|
+
end
|
49
|
+
|
50
|
+
def image_required?
|
51
|
+
@image_required
|
52
|
+
end
|
53
|
+
|
54
|
+
def file_allowed?
|
55
|
+
@file_allowed
|
56
|
+
end
|
57
|
+
|
58
|
+
def file_required?
|
59
|
+
@file_required
|
60
|
+
end
|
61
|
+
|
62
|
+
def image_uploader
|
63
|
+
ActiveAdmin::Cms::Uploaders::ContentImageUploader
|
64
|
+
end
|
65
|
+
|
66
|
+
def display_preview?
|
67
|
+
@display_preview
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
module Cms
|
3
|
+
module ContentTypes
|
4
|
+
class Image < Cms::ContentType
|
5
|
+
|
6
|
+
@image_allowed = true
|
7
|
+
@image_required = true
|
8
|
+
|
9
|
+
@input_field = :image
|
10
|
+
@input_opts = {:as => :file}
|
11
|
+
|
12
|
+
@display_preview = true
|
13
|
+
@preview_options = {:version => :small}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
module Cms
|
3
|
+
module ContentTypes
|
4
|
+
class LargeImage < Cms::ContentType
|
5
|
+
|
6
|
+
@image_allowed = true
|
7
|
+
@image_required = true
|
8
|
+
|
9
|
+
@input_field = :image
|
10
|
+
@input_opts = {:as => :file}
|
11
|
+
|
12
|
+
@display_preview = true
|
13
|
+
@preview_options = {:version => :small}
|
14
|
+
|
15
|
+
def self.image_uploader
|
16
|
+
ActiveAdmin::Cms::Uploaders::LargeImageUploader
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
module Cms
|
3
|
+
module ControllerExtensions
|
4
|
+
module ClassMethods
|
5
|
+
include ActiveAdmin::Cms::Utility::ClassLevelInheritableAttributes
|
6
|
+
cattr_inheritable :current_page_class
|
7
|
+
|
8
|
+
def cms_for page_class
|
9
|
+
@current_page_class = page_class
|
10
|
+
end
|
11
|
+
|
12
|
+
def current_page_class
|
13
|
+
@current_page_class ||= ActiveAdmin::Cms::Page
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module InstanceMethods
|
18
|
+
def current_page
|
19
|
+
@current_page ||= self.class.current_page_class::for_url request.path
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
ActionController::Base.send :extend, ActiveAdmin::Cms::ControllerExtensions::ClassMethods
|
27
|
+
ActionController::Base.send :include, ActiveAdmin::Cms::ControllerExtensions::InstanceMethods
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
module Cms
|
3
|
+
module CmsHelper
|
4
|
+
def cms_content page, content_key, options = {}
|
5
|
+
raise Exceptions::MissingPage if !page
|
6
|
+
#debugger
|
7
|
+
page.content_for(content_key).to_html(options).html_safe if page.content_for(content_key)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
ActionView::Base.send :include, ActiveAdmin::Cms::CmsHelper
|