honey-cms 0.3.8 → 0.3.9
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.
- data/app/controllers/cms/base_controller.rb +78 -0
- data/app/controllers/cms/root_controller.rb +23 -0
- data/app/views/cms/root/description.html.haml +10 -0
- data/app/views/cms/root/index.html.haml +0 -0
- data/app/views/layouts/_flash.html.haml +13 -0
- data/app/views/layouts/cms.html.haml +38 -0
- data/lib/cms.rb +1 -0
- data/lib/cms/attribute.rb +1 -1
- data/lib/cms/configuration.rb +1 -1
- data/lib/cms/engine.rb +7 -1
- data/lib/cms/orderable.rb +11 -2
- data/lib/cms/template.rb +27 -0
- data/lib/cms/type.rb +4 -0
- data/lib/generators/cms/admin_area_generator.rb +1 -1
- data/lib/generators/cms/templates/type_model.rb +1 -1
- data/lib/generators/cms/templates/views/_fields.html.haml +16 -0
- data/lib/generators/cms/templates/views/edit.html.haml +1 -16
- data/lib/generators/cms/templates/views/new.html.haml +1 -16
- metadata +10 -2
@@ -0,0 +1,78 @@
|
|
1
|
+
class CMS::BaseController < ApplicationController
|
2
|
+
before_filter :admin!
|
3
|
+
before_filter :set_active
|
4
|
+
layout 'cms'
|
5
|
+
|
6
|
+
before_filter :find_record, only: [:show, :edit, :update, :destroy]
|
7
|
+
before_filter :set_element_variable, only: [:show, :edit, :update, :destroy]
|
8
|
+
respond_to :html, :json
|
9
|
+
|
10
|
+
def index
|
11
|
+
@records = if params[:search].blank?
|
12
|
+
subject.order('id asc') .page(params[:page]).per(100)
|
13
|
+
else
|
14
|
+
subject.search(params[:search]).page(params[:page]).per(100)
|
15
|
+
end
|
16
|
+
|
17
|
+
set_collection_variable
|
18
|
+
respond_with(@records)
|
19
|
+
end
|
20
|
+
|
21
|
+
def new
|
22
|
+
@record = subject.new
|
23
|
+
set_element_variable
|
24
|
+
respond_with(@record)
|
25
|
+
end
|
26
|
+
|
27
|
+
def create
|
28
|
+
@record = subject.create(params[subject.model_name.element])
|
29
|
+
set_element_variable
|
30
|
+
respond_with @record
|
31
|
+
end
|
32
|
+
|
33
|
+
def show
|
34
|
+
respond_with @record
|
35
|
+
end
|
36
|
+
|
37
|
+
def edit
|
38
|
+
respond_with @record
|
39
|
+
end
|
40
|
+
|
41
|
+
def update
|
42
|
+
@record.update_attributes params[subject.model_name.element]
|
43
|
+
respond_with @record
|
44
|
+
end
|
45
|
+
|
46
|
+
def destroy
|
47
|
+
@record.destroy
|
48
|
+
respond_with @record
|
49
|
+
end
|
50
|
+
|
51
|
+
protected
|
52
|
+
|
53
|
+
def respond_with object
|
54
|
+
super [:cms, object]
|
55
|
+
end
|
56
|
+
|
57
|
+
def find_record
|
58
|
+
@record = subject.find(params[:id])
|
59
|
+
end
|
60
|
+
|
61
|
+
def set_collection_variable
|
62
|
+
instance_variable_set :"@#{subject.model_name.collection}", @records
|
63
|
+
end
|
64
|
+
|
65
|
+
def set_element_variable
|
66
|
+
instance_variable_set :"@#{subject.model_name.element}", @record
|
67
|
+
end
|
68
|
+
|
69
|
+
def admin!
|
70
|
+
unless signed_in? && current_user.role.admin?
|
71
|
+
auth_failed
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def set_active
|
76
|
+
@active_page = /cms/
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class CMS::RootController < ApplicationController
|
2
|
+
before_filter :admin!
|
3
|
+
before_filter :set_active
|
4
|
+
layout 'cms'
|
5
|
+
|
6
|
+
def description
|
7
|
+
end
|
8
|
+
|
9
|
+
def index
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def admin!
|
15
|
+
unless signed_in? && current_user.role.admin?
|
16
|
+
auth_failed
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def set_active
|
21
|
+
@active_page = /cms/
|
22
|
+
end
|
23
|
+
end
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
.alerts
|
2
|
+
- if flash[:notice]
|
3
|
+
.alert.alert-info
|
4
|
+
<button type="button" class="close" data-dismiss="alert">×</button>
|
5
|
+
= flash[:notice]
|
6
|
+
- if flash[:success]
|
7
|
+
.alert.alert-success
|
8
|
+
<button type="button" class="close" data-dismiss="alert">×</button>
|
9
|
+
= flash[:success]
|
10
|
+
- if flash[:error] || flash[:alert]
|
11
|
+
.alert.alert-error
|
12
|
+
<button type="button" class="close" data-dismiss="alert">×</button>
|
13
|
+
= flash[:error] || flash[:alert]
|
@@ -0,0 +1,38 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
= stylesheet_link_tag 'cms', media: 'all'
|
5
|
+
= javascript_include_tag 'application'
|
6
|
+
= stylesheet_link_tag 'codemirror'
|
7
|
+
= javascript_include_tag 'cms'
|
8
|
+
= csrf_meta_tags
|
9
|
+
|
10
|
+
%body.cms
|
11
|
+
.navbar.navbar-fixed-top.main-navigation
|
12
|
+
.navbar-inner
|
13
|
+
.container
|
14
|
+
%button.btn.btn-navbar{type: 'button', :'data-toggle' => 'collapse', :'data-target' => '.nav-collapse'}
|
15
|
+
%span.icon-bar
|
16
|
+
%span.icon-bar
|
17
|
+
%span.icon-bar
|
18
|
+
|
19
|
+
.nav-collapse.collapse
|
20
|
+
%ul.nav
|
21
|
+
%li= link_to 'Home', root_path
|
22
|
+
%ul.nav.pull-right
|
23
|
+
%li= link_to 'Sign out', session_path, method: 'delete', class: 'session'
|
24
|
+
|
25
|
+
.container
|
26
|
+
= render partial: 'layouts/flash', locals: { flash: flash }
|
27
|
+
|
28
|
+
.row
|
29
|
+
.span3
|
30
|
+
%h5 CMS
|
31
|
+
%ul.nav.nav-list
|
32
|
+
- CMS::Configuration.types.each do |type|
|
33
|
+
%li{class: "#{if defined?(subject) && type.subject == subject.name then 'active' end}"}
|
34
|
+
= link_to send("cms_#{type.model_name.collection}_path") do
|
35
|
+
%i.icon-chevron-right
|
36
|
+
= type.model_name.human.pluralize
|
37
|
+
|
38
|
+
.span9= yield
|
data/lib/cms.rb
CHANGED
data/lib/cms/attribute.rb
CHANGED
data/lib/cms/configuration.rb
CHANGED
data/lib/cms/engine.rb
CHANGED
@@ -2,6 +2,12 @@ require 'cms/inflections'
|
|
2
2
|
|
3
3
|
module CMS
|
4
4
|
class Engine < ::Rails::Engine
|
5
|
-
|
5
|
+
initializer 'cms.markdown' do |app|
|
6
|
+
::Markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,
|
7
|
+
autolink: true,
|
8
|
+
space_after_headers: true,
|
9
|
+
superscript: true,
|
10
|
+
tables: true)
|
11
|
+
end
|
6
12
|
end
|
7
13
|
end
|
data/lib/cms/orderable.rb
CHANGED
@@ -2,13 +2,18 @@ module CMS::Orderable
|
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
4
|
def order_scope
|
5
|
-
self.class
|
5
|
+
if self.class.order_scope && (scoped = send(self.class.order_scope))
|
6
|
+
scoped.send(self.class.model_name.collection)
|
7
|
+
else
|
8
|
+
self.class
|
9
|
+
end
|
6
10
|
end
|
7
11
|
|
8
12
|
module ClassMethods
|
9
|
-
def orderable name
|
13
|
+
def orderable name, options
|
10
14
|
default_scope order(name)
|
11
15
|
after_save :"order_#{name}"
|
16
|
+
if options[:order_scope] then order_scope(options[:order_scope]) end
|
12
17
|
|
13
18
|
define_method :"order_#{name}" do
|
14
19
|
order_scope.where("#{name} >= #{send(name)}").where("id != #{id}").select(:id).select(name).inject(send(name)) do |i, record|
|
@@ -20,5 +25,9 @@ module CMS::Orderable
|
|
20
25
|
end
|
21
26
|
end
|
22
27
|
end
|
28
|
+
|
29
|
+
def order_scope scope = false
|
30
|
+
if scope then @order_scope = scope else @order_scope end
|
31
|
+
end
|
23
32
|
end
|
24
33
|
end
|
data/lib/cms/template.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module CMS::Template
|
2
|
+
extend self
|
3
|
+
|
4
|
+
class InvalidOptionKey < Exception ; end
|
5
|
+
|
6
|
+
def inject_options options
|
7
|
+
"".tap { |s| options.each { |k,v| s << ", #{_validate_option_key(k)}: #{v.inspect}" } }
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_comma content
|
11
|
+
if content.strip.present?
|
12
|
+
", #{content}"
|
13
|
+
else
|
14
|
+
content
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def _validate_option_key key
|
21
|
+
unless key =~ /^[a-z0-9_]+$/
|
22
|
+
raise CMS::Template::InvalidOptionKey, "Key #{key} is not valid."
|
23
|
+
end
|
24
|
+
|
25
|
+
key
|
26
|
+
end
|
27
|
+
end
|
data/lib/cms/type.rb
CHANGED
@@ -19,7 +19,7 @@ module CMS
|
|
19
19
|
template 'type_controller.rb', "app/controllers/cms/#{@name.collection}_controller.rb"
|
20
20
|
template 'type_model.rb', "app/models/cms/#{@name.element}.rb"
|
21
21
|
|
22
|
-
%w(index new show edit).each do |view|
|
22
|
+
%w(index new show edit _fields).each do |view|
|
23
23
|
template "views/#{view}.html.haml", "app/views/cms/#{@name.collection}/#{view}.html.haml"
|
24
24
|
end
|
25
25
|
end
|
@@ -11,7 +11,7 @@ class CMS::<%= @name %> < ActiveRecord::Base
|
|
11
11
|
attr_accessible <%= @type.accessible_attributes.map {|a| ":#{a.field_name}" }.sort.join(', ') %>
|
12
12
|
<% if @type.orderable? -%>
|
13
13
|
include CMS::Orderable
|
14
|
-
orderable(:<%= @type.order_attribute.name %>)
|
14
|
+
orderable(:<%= @type.order_attribute.name %><%= @type.order_options %>)
|
15
15
|
<% end -%>
|
16
16
|
<% @type.file_attributes.each do |attribute| -%>
|
17
17
|
mount_uploader :<%= attribute.name %>, CMS::Uploader
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<% @type.attributes.each do |attribute| -%>
|
2
|
+
.control-group
|
3
|
+
= f.label :<%= attribute.field_name %>, class: 'control-label'
|
4
|
+
<% if attribute.orderable? -%>
|
5
|
+
.controls
|
6
|
+
= f.<%= attribute.form_type %> :<%= attribute.name %>, 1.upto(f.object.order_scope.count + 1).to_a
|
7
|
+
<% elsif attribute.reference? -%>
|
8
|
+
.controls
|
9
|
+
= f.<%= attribute.form_type %> :<%= attribute.field_name %>, CMS::<%= attribute.reference_to %>.all.collect {|r| [ r.<%= attribute.options['reference_label'] %>, r.id ] }
|
10
|
+
<% else -%>
|
11
|
+
.controls
|
12
|
+
= f.<%= attribute.form_type %> :<%= attribute.name %>
|
13
|
+
<% end -%>
|
14
|
+
<% end -%>
|
15
|
+
.form-actions
|
16
|
+
= f.submit 'Save', class: 'btn btn-primary', :'data-disable-with' => 'Saving...'
|
@@ -1,19 +1,4 @@
|
|
1
1
|
%h2 Edit <%= @name.human.downcase %>
|
2
2
|
|
3
3
|
= form_for @<%= @name.element %>, url: cms_<%= @name.element %>_path(@<%= @name.element %>), html: {class: 'form-horizontal'} do |f|
|
4
|
-
|
5
|
-
.control-group
|
6
|
-
= f.label :<%= attribute.field_name %>, class: 'control-label'
|
7
|
-
<% if attribute.orderable? -%>
|
8
|
-
.controls
|
9
|
-
= f.<%= attribute.form_type %> :<%= attribute.name %>, 1.upto(CMS::<%= @name %>.count).to_a
|
10
|
-
<% elsif attribute.reference? -%>
|
11
|
-
.controls
|
12
|
-
= f.<%= attribute.form_type %> :<%= attribute.field_name %>, CMS::<%= attribute.reference_to %>.all.collect {|r| [ r.<%= attribute.options['reference_label'] %>, r.id ] }
|
13
|
-
<% else -%>
|
14
|
-
.controls
|
15
|
-
= f.<%= attribute.form_type %> :<%= attribute.name %>
|
16
|
-
<% end -%>
|
17
|
-
<% end -%>
|
18
|
-
.form-actions
|
19
|
-
= f.submit 'Save', class: 'btn btn-primary', :'data-disable-with' => 'Saving...'
|
4
|
+
= render partial: 'fields', locals: { f: f }
|
@@ -1,19 +1,4 @@
|
|
1
1
|
%h2 New <%= @name.human.downcase %>
|
2
2
|
|
3
3
|
= form_for @<%= @name.element %>, url: cms_<%= @name.collection %>_path, html: {class: 'form-horizontal'} do |f|
|
4
|
-
|
5
|
-
.control-group
|
6
|
-
= f.label :<%= attribute.field_name %>, class: 'control-label'
|
7
|
-
<% if attribute.orderable? -%>
|
8
|
-
.controls
|
9
|
-
= f.<%= attribute.form_type %> :<%= attribute.name %>, 1.upto(CMS::<%= @name %>.count + 1).to_a
|
10
|
-
<% elsif attribute.reference? -%>
|
11
|
-
.controls
|
12
|
-
= f.<%= attribute.form_type %> :<%= attribute.field_name %>, CMS::<%= attribute.reference_to %>.all.collect {|r| [ r.<%= attribute.options['reference_label'] %>, r.id ] }
|
13
|
-
<% else -%>
|
14
|
-
.controls
|
15
|
-
= f.<%= attribute.form_type %> :<%= attribute.name %>
|
16
|
-
<% end -%>
|
17
|
-
<% end -%>
|
18
|
-
.form-actions
|
19
|
-
= f.submit 'Save', class: 'btn btn-primary', :'data-disable-with' => 'Saving...'
|
4
|
+
= render partial: 'fields', locals: { f: f }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: honey-cms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-08 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Some CMS functionality
|
15
15
|
email: quinn@tastehoneyco.com
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- lib/cms/orderable.rb
|
45
45
|
- lib/cms/page.rb
|
46
46
|
- lib/cms/routes.rb
|
47
|
+
- lib/cms/template.rb
|
47
48
|
- lib/cms/type.rb
|
48
49
|
- lib/cms/uploader.rb
|
49
50
|
- lib/cms/view_tags.rb
|
@@ -59,14 +60,21 @@ files:
|
|
59
60
|
- lib/generators/cms/templates/migration.rb
|
60
61
|
- lib/generators/cms/templates/type_controller.rb
|
61
62
|
- lib/generators/cms/templates/type_model.rb
|
63
|
+
- lib/generators/cms/templates/views/_fields.html.haml
|
62
64
|
- lib/generators/cms/templates/views/edit.html.haml
|
63
65
|
- lib/generators/cms/templates/views/index.html.haml
|
64
66
|
- lib/generators/cms/templates/views/new.html.haml
|
65
67
|
- lib/generators/cms/templates/views/show.html.haml
|
66
68
|
- lib/generators/cms/USAGE
|
67
69
|
- lib/honey-cms.rb
|
70
|
+
- app/controllers/cms/base_controller.rb
|
68
71
|
- app/controllers/cms/pages_controller.rb
|
72
|
+
- app/controllers/cms/root_controller.rb
|
69
73
|
- app/views/cms/pages/show.html.haml
|
74
|
+
- app/views/cms/root/description.html.haml
|
75
|
+
- app/views/cms/root/index.html.haml
|
76
|
+
- app/views/layouts/_flash.html.haml
|
77
|
+
- app/views/layouts/cms.html.haml
|
70
78
|
homepage: https://github.com/honeyco/honey-cms
|
71
79
|
licenses: []
|
72
80
|
post_install_message:
|