cambium 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -1
  3. data/Rakefile +0 -1
  4. data/bin/cambium +20 -0
  5. data/cambium.gemspec +24 -1
  6. data/lib/cambium/engine.rb +6 -0
  7. data/lib/cambium/version.rb +1 -1
  8. data/lib/cambium.rb +1 -1
  9. data/lib/docs/notes.md +4 -0
  10. data/lib/generators/cambium/setup/config_generator.rb +185 -0
  11. data/lib/generators/cambium/setup/controllers_generator.rb +95 -0
  12. data/lib/generators/cambium/setup/devise_generator.rb +78 -0
  13. data/lib/generators/cambium/setup/helpers_generator.rb +71 -0
  14. data/lib/generators/cambium/setup/javascripts_generator.rb +111 -0
  15. data/lib/generators/cambium/setup/models_generator.rb +116 -0
  16. data/lib/generators/cambium/setup/stylesheets_generator.rb +86 -0
  17. data/lib/generators/cambium/setup/utilities_generator.rb +87 -0
  18. data/lib/generators/cambium/setup/views_generator.rb +86 -0
  19. data/lib/generators/cambium/templates/Gemfile.erb +41 -0
  20. data/lib/generators/cambium/templates/app/assets/javascripts/.DS_Store +0 -0
  21. data/lib/generators/cambium/templates/app/assets/javascripts/admin/admin.js +12 -0
  22. data/lib/generators/cambium/templates/app/assets/javascripts/admin/backbone/admin.js.coffee +22 -0
  23. data/lib/generators/cambium/templates/app/assets/javascripts/admin/backbone/models/.gitkeep +0 -0
  24. data/lib/generators/cambium/templates/app/assets/javascripts/admin/backbone/routers/router.js.coffee +12 -0
  25. data/lib/generators/cambium/templates/app/assets/javascripts/admin/backbone/templates/paginator_controls.jst.ejs +8 -0
  26. data/lib/generators/cambium/templates/app/assets/javascripts/admin/backbone/templates/paginator_nav.jst.ejs +11 -0
  27. data/lib/generators/cambium/templates/app/assets/javascripts/admin/backbone/views/accordion.js.coffee +33 -0
  28. data/lib/generators/cambium/templates/app/assets/javascripts/admin/backbone/views/counter.js.coffee +25 -0
  29. data/lib/generators/cambium/templates/app/assets/javascripts/admin/backbone/views/dropdown_toggle.js.coffee +16 -0
  30. data/lib/generators/cambium/templates/app/assets/javascripts/admin/backbone/views/init_counter.js.coffee +13 -0
  31. data/lib/generators/cambium/templates/app/assets/javascripts/admin/backbone/views/paginator.js.coffee +86 -0
  32. data/lib/generators/cambium/templates/app/assets/javascripts/admin/backbone/views/publishable.js.coffee +12 -0
  33. data/lib/generators/cambium/templates/app/assets/javascripts/admin/backbone/views/wysiwyg.js.coffee +10 -0
  34. data/lib/generators/cambium/templates/app/assets/javascripts/admin/wysihtml5.js +9521 -0
  35. data/lib/generators/cambium/templates/app/assets/javascripts/application.js +7 -0
  36. data/lib/generators/cambium/templates/app/assets/javascripts/backbone/app.js.coffee +22 -0
  37. data/lib/generators/cambium/templates/app/assets/javascripts/backbone/routers/router.js.coffee +23 -0
  38. data/lib/generators/cambium/templates/app/assets/javascripts/backbone/views/default_helpers.js.coffee +16 -0
  39. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/admin.scss +14 -0
  40. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/bones/bones-config/__default.scss +14 -0
  41. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/bones/bones-config/_buttons.scss +21 -0
  42. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/bones/bones-config/_colors.scss +93 -0
  43. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/bones/bones-config/_components.scss +4 -0
  44. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/bones/bones-config/_forms.scss +28 -0
  45. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/bones/bones-config/_helpers.scss +31 -0
  46. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/bones/bones-config/_images.scss +23 -0
  47. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/bones/bones-config/_nav.scss +117 -0
  48. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/bones/bones-config/_tables.scss +12 -0
  49. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/bones/bones-config/_typography.scss +83 -0
  50. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/bones/bones-config/_wireframe.scss +18 -0
  51. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/bones/bones.scss +68 -0
  52. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/partials/_content.scss +88 -0
  53. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/partials/_form.scss +470 -0
  54. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/partials/_globals.scss +39 -0
  55. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/partials/_header.scss +121 -0
  56. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/partials/_icons.scss +5194 -0
  57. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/partials/_nav.scss +45 -0
  58. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/partials/_wireframe.scss +24 -0
  59. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/wysihtml5.css +7 -0
  60. data/lib/generators/cambium/templates/app/assets/stylesheets/application.scss +9 -0
  61. data/lib/generators/cambium/templates/app/controllers/admin/users_controller.rb +13 -0
  62. data/lib/generators/cambium/templates/app/controllers/admin_controller.rb +88 -0
  63. data/lib/generators/cambium/templates/app/controllers/application_controller.rb +15 -0
  64. data/lib/generators/cambium/templates/app/helpers/admin_helper.rb +120 -0
  65. data/lib/generators/cambium/templates/app/models/concerns/idx.rb +28 -0
  66. data/lib/generators/cambium/templates/app/models/concerns/name.rb +7 -0
  67. data/lib/generators/cambium/templates/app/models/concerns/publishable.rb +50 -0
  68. data/lib/generators/cambium/templates/app/models/concerns/slug.rb +52 -0
  69. data/lib/generators/cambium/templates/app/models/concerns/tags.rb +28 -0
  70. data/lib/generators/cambium/templates/app/models/concerns/title.rb +7 -0
  71. data/lib/generators/cambium/templates/app/models/user.rb +14 -0
  72. data/lib/generators/cambium/templates/app/views/admin/_buttons.html.erb +5 -0
  73. data/lib/generators/cambium/templates/app/views/admin/_form.html.erb +11 -0
  74. data/lib/generators/cambium/templates/app/views/admin/_title.html.erb +1 -0
  75. data/lib/generators/cambium/templates/app/views/admin/edit.html.erb +2 -0
  76. data/lib/generators/cambium/templates/app/views/admin/index.html.erb +50 -0
  77. data/lib/generators/cambium/templates/app/views/admin/new.html.erb +2 -0
  78. data/lib/generators/cambium/templates/app/views/admin/shared/_footer.html.erb +2 -0
  79. data/lib/generators/cambium/templates/app/views/admin/shared/_header.html.erb +2 -0
  80. data/lib/generators/cambium/templates/app/views/admin/shared/_nav.html.erb +12 -0
  81. data/lib/generators/cambium/templates/app/views/admin/shared/_status.html.erb +3 -0
  82. data/lib/generators/cambium/templates/app/views/admin/shared/forms/_editor.html.erb +54 -0
  83. data/lib/generators/cambium/templates/app/views/admin/shared/forms/_form_column_left.html.erb +9 -0
  84. data/lib/generators/cambium/templates/app/views/admin/shared/forms/_form_column_right.html.erb +9 -0
  85. data/lib/generators/cambium/templates/app/views/admin/shared/forms/_form_page.html.erb +18 -0
  86. data/lib/generators/cambium/templates/app/views/admin/shared/forms/_form_section.html.erb +8 -0
  87. data/lib/generators/cambium/templates/app/views/admin/shared/forms/_publishable.html.erb +33 -0
  88. data/lib/generators/cambium/templates/app/views/admin/users/_form.html.erb +11 -0
  89. data/lib/generators/cambium/templates/app/views/application/_status.html.erb +3 -0
  90. data/lib/generators/cambium/templates/app/views/layouts/.DS_Store +0 -0
  91. data/lib/generators/cambium/templates/app/views/layouts/admin.html.erb +44 -0
  92. data/lib/generators/cambium/templates/app/views/layouts/application.html.erb +24 -0
  93. data/lib/generators/cambium/templates/config/application.rb +15 -0
  94. data/lib/generators/cambium/templates/config/database.mysql2.yml.erb +15 -0
  95. data/lib/generators/cambium/templates/config/database.pg.yml.erb +14 -0
  96. data/lib/generators/cambium/templates/config/database.sqlite3.yml.erb +18 -0
  97. data/lib/generators/cambium/templates/config/initializers/_settings.rb +11 -0
  98. data/lib/generators/cambium/templates/config/initializers/assets.rb +1 -0
  99. data/lib/generators/cambium/templates/config/routes.rb.erb +33 -0
  100. data/lib/generators/cambium/templates/config/settings.yml +15 -0
  101. data/lib/generators/cambium/templates/config/settings_private.sample.yml +15 -0
  102. data/lib/generators/cambium/templates/config/settings_private.yml +13 -0
  103. data/lib/generators/cambium/templates/db/seeds.rb +25 -0
  104. data/lib/generators/cambium/templates/gitignore +29 -0
  105. data/lib/generators/cambium/templates/lib/.DS_Store +0 -0
  106. data/lib/generators/cambium/templates/lib/tasks/db.rake +22 -0
  107. data/lib/generators/cambium/templates/lib/tasks/rename.rake +28 -0
  108. data/lib/generators/cambium/templates/vendor/assets/javascripts/modernizr.js +4 -0
  109. data/lib/generators/cambium/templates/vendor/assets/stylesheets/normalize.scss +406 -0
  110. data/lib/help/cambium +7 -0
  111. metadata +375 -4
@@ -0,0 +1,45 @@
1
+ nav#sidebar {
2
+
3
+ ul {
4
+
5
+ li {
6
+
7
+ a {
8
+ box-sizing: border-box;
9
+ width: $sidebar-width;
10
+ padding: 12.5px 0;
11
+ text-align: center;
12
+
13
+ span {
14
+ display: block;
15
+ margin: 5px 0;
16
+ color: $color-light-darkest;
17
+ }
18
+
19
+ i {
20
+ font-size: 28px;
21
+ color: $color-light-darkest;
22
+ }
23
+
24
+ &:hover {
25
+ background: $color-1;
26
+
27
+ span, i {
28
+ color: $color-light;
29
+ }
30
+ }
31
+ }
32
+
33
+ &.active {
34
+
35
+ a {
36
+ background: $color-1;
37
+
38
+ span, i {
39
+ color: $color-light;
40
+ }
41
+ }
42
+ }
43
+ }
44
+ }
45
+ }
@@ -0,0 +1,24 @@
1
+ #admin {
2
+ position: relative;
3
+ min-height: 100%;
4
+
5
+ //////////////////////////////// nav
6
+
7
+ aside.nav {
8
+ position: fixed;
9
+ top: 0;
10
+ left: 0;
11
+ width: $sidebar-width;
12
+ height: 100%;
13
+ background: $color-dark-lighter;
14
+ }
15
+
16
+ //////////////////////////////// content
17
+
18
+ section.container {
19
+ box-sizing: border-box;
20
+ max-width: none;
21
+ margin-left: $sidebar-width;
22
+ padding: 0;
23
+ }
24
+ }
@@ -0,0 +1,7 @@
1
+ a {
2
+ color: #00ade2;
3
+ text-decoration: none;
4
+ }
5
+ a:hover {
6
+ text-decoration: underline;
7
+ }
@@ -0,0 +1,9 @@
1
+
2
+ // ------------------------------------------ Vendor
3
+
4
+ @import 'bourbon';
5
+ @import 'normalize';
6
+
7
+ // ------------------------------------------ Partials
8
+
9
+ // @import 'partials/globals';
@@ -0,0 +1,13 @@
1
+ class Admin::UsersController < AdminController
2
+
3
+ private
4
+ def set_defaults
5
+ super
6
+ @model = User
7
+ @columns = ['email']
8
+ end
9
+
10
+ def create_params
11
+ params.require(:user).permit(:email, :password, :password_confirmation)
12
+ end
13
+ end
@@ -0,0 +1,88 @@
1
+ class AdminController < ActionController::Base
2
+
3
+ include AdminHelper
4
+
5
+ before_filter :authenticate_admin
6
+ before_action :set_defaults, :except => [:dashboard]
7
+ before_action :set_routes, :except => [:dashboard]
8
+ protect_from_forgery :with => :exception
9
+
10
+ def dashboard
11
+ redirect_to admin_users_path
12
+ end
13
+
14
+ def index
15
+ @items = @model.all
16
+ end
17
+
18
+ def new
19
+ @item = @model.new
20
+ @url = @routes[:index]
21
+ end
22
+
23
+ def edit
24
+ @url = @routes[:show]
25
+ end
26
+
27
+ def create
28
+ @item = @model.new(create_params)
29
+ convert_dates if @item.attributes.has_key?('active_at')
30
+ @item = @model.new(create_params)
31
+ if @item.attributes.has_key? 'slug' && !create_params[:slug].blank?
32
+ @item.slug = @item.make_slug_unique(create_params[:slug])
33
+ end
34
+ if @item.save
35
+ redirect_to @routes[:index], :notice => "#{@model.to_s} was successfully created."
36
+ else
37
+ render :action => "new"
38
+ end
39
+ end
40
+
41
+ def update
42
+ convert_dates if @item.attributes.has_key?('active_at')
43
+ update_params ||= create_params
44
+ if @item.attributes.has_key? 'slug' && !update_params[:slug].blank?
45
+ update_params[:slug] = @item.make_slug_unique(update_params[:slug])
46
+ end
47
+ if @item.update(update_params)
48
+ @routes[:edit] = send("edit_admin_#{model_table_singular}_path", @item)
49
+ redirect_to @routes[:edit], :notice => "#{@model.to_s} was updated successfully."
50
+ else
51
+ render :action => "edit"
52
+ end
53
+ end
54
+
55
+ def destroy
56
+ @item.destroy
57
+ redirect_to @routes[:index], :notice => "#{@model.to_s} was deleted successfully."
58
+ end
59
+
60
+ private
61
+
62
+ def authenticate_admin
63
+ authenticate_user!
64
+ redirect_to root_path unless current_user.is_admin?
65
+ end
66
+
67
+ def set_defaults
68
+ @columns = ['title']
69
+ @actions = [:edit, :delete]
70
+ end
71
+
72
+ def convert_dates
73
+ p = params[@model.to_s.downcase.to_sym]
74
+ p[:active_time] = Time.now.strftime("%l:%M %p") if p[:active_date].blank?
75
+ p[:inactive_time] = '12:00 AM' if p[:active_time].blank?
76
+ if p[:active_date].blank?
77
+ p[:active_at] = nil
78
+ else
79
+ p[:active_at] = DateTime.parse("#{p[:active_date]} #{p[:active_time]}")
80
+ end
81
+ if p[:inactive_date].blank?
82
+ p[:inactive_at] = nil
83
+ else
84
+ p[:inactive_at] = DateTime.parse("#{p[:inactive_date]} #{p[:inactive_time]}")
85
+ end
86
+ end
87
+
88
+ end
@@ -0,0 +1,15 @@
1
+
2
+
3
+ # redirect to admin dashboard after signing in
4
+ def after_sign_in_path_for(user)
5
+ if current_user.is_admin?
6
+ admin_dashboard_path
7
+ else
8
+ root_path
9
+ end
10
+ end
11
+
12
+ # redirect back to sign in form when signed out
13
+ def after_sign_out_path_for(user)
14
+ root_path
15
+ end
@@ -0,0 +1,120 @@
1
+ module AdminHelper
2
+
3
+ # --------------------------------- Inflectors
4
+
5
+ def model_plural
6
+ @model.to_s.tableize.humanize.titleize
7
+ end
8
+
9
+ def model_singular
10
+ model_plural.singularize
11
+ end
12
+
13
+ def model_table
14
+ @model.to_s.tableize
15
+ end
16
+
17
+ def model_table_singular
18
+ model_table.singularize
19
+ end
20
+
21
+ # --------------------------------- Routes
22
+
23
+ def set_routes
24
+ @routes = {
25
+ :index => send("admin_#{model_table}_path"),
26
+ :new => send("new_admin_#{model_table_singular}_path")
27
+ }
28
+ unless params[:id].nil?
29
+ @item = @model.find_by_id(params[:id])
30
+ @item = @model.find_by_slug(params[:id]) if @item.nil?
31
+ @routes.merge!(
32
+ :show => send("admin_#{model_table_singular}_path", @item),
33
+ :edit => send("edit_admin_#{model_table_singular}_path", @item)
34
+ )
35
+ end
36
+ end
37
+
38
+ # --------------------------------- Forms
39
+
40
+ def form_page(options = {})
41
+ render :partial => 'admin/shared/forms/form_page', :locals => options
42
+ end
43
+
44
+ def form_section(title, options = {}, &block)
45
+ state = options[:open].nil? ? true : options[:open]
46
+ render :partial => 'admin/shared/forms/form_section', :locals => {
47
+ :title => title, :open => state, :content => capture(&block) }
48
+ end
49
+
50
+ def form_column(title, side = 'left', &block)
51
+ side ||= 'left'
52
+ render :partial => "admin/shared/forms/form_column_#{side}", :locals => {
53
+ :title => title, :content => capture(&block) }
54
+ end
55
+
56
+ def wysiwyg(form, field = :body)
57
+ render :partial => 'admin/shared/forms/editor', :locals => { :f => form, :field => field }
58
+ end
59
+
60
+ def publishable_fields(form)
61
+ render :partial => 'admin/shared/forms/publishable', :locals => { :f => form }
62
+ end
63
+
64
+ def wysihtml5_icon(cmd,icon = cmd,options = {})
65
+ options[:cmd] = "data-wysihtml5-command-value='#{options[:cmd]}'" unless options[:cmd] == ''
66
+ "<a data-wysihtml5-command='#{cmd}' #{options[:cmd]} id='#{options[:id]}'
67
+ class='#{options[:class]}'>
68
+ <i class='icon-#{icon}'></i>
69
+ </a>".html_safe
70
+ end
71
+
72
+ def wysihtml5_link(cmd,val=cmd,options={})
73
+ options[:cmd] = "data-wysihtml5-command-value='#{options[:cmd]}'" unless options[:cmd] == ''
74
+ "<a data-wysihtml5-command='#{cmd}' #{options[:cmd]} id='#{options[:id]}' class='#{options[:class]}'>
75
+ #{val}
76
+ </a>".html_safe
77
+ end
78
+
79
+ # --------------------------------- Nav
80
+
81
+ def admin_nav_items
82
+ [
83
+ {
84
+ :label => 'Users',
85
+ :icon => 'user',
86
+ :path => admin_users_path,
87
+ :controllers => ['users']
88
+ },
89
+ {
90
+ :label => 'Visit Site',
91
+ :icon => 'home',
92
+ :path => root_path,
93
+ :target => :blank
94
+ },
95
+ {
96
+ :label => 'Logout',
97
+ :icon => 'exit',
98
+ :path => destroy_user_session_path
99
+ }
100
+ ]
101
+ end
102
+
103
+ def nav_active?(controllers)
104
+ unless controllers.nil?
105
+ controllers.each do |controller|
106
+ return true if controller_name == controller
107
+ end
108
+ end
109
+ false
110
+ end
111
+
112
+ # --------------------------------- Misc
113
+
114
+ def icon_to(icon, path, options = {})
115
+ link_to path, :class => options[:class] do
116
+ "<i class='icon-#{icon}'></i>".html_safe
117
+ end
118
+ end
119
+
120
+ end
@@ -0,0 +1,28 @@
1
+ module Idx
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+
6
+ # ------------------------------------------ Scopes
7
+
8
+ scope :by_idx, -> { reorder('idx asc') }
9
+
10
+ # ------------------------------------------ Callbacks
11
+
12
+ after_create :create_idx
13
+
14
+ end
15
+
16
+ # ------------------------------------------ Instance Methods
17
+
18
+ def to_param
19
+ idx.to_s
20
+ end
21
+
22
+ def create_idx
23
+ last_obj = self.idx_class.send(self.class.table_name).by_idx.last
24
+ idx = last_obj.idx + 1
25
+ update_columns(:idx => idx)
26
+ end
27
+
28
+ end
@@ -0,0 +1,7 @@
1
+ module Name
2
+
3
+ def name
4
+ title
5
+ end
6
+
7
+ end
@@ -0,0 +1,50 @@
1
+ module Publishable
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+
6
+ # --------------------------------- Attributes
7
+
8
+ attr_accessor :active, :active_date, :active_time, :inactive_date,
9
+ :inactive_time
10
+
11
+ # --------------------------------- Scopes
12
+
13
+ scope :published, -> { where("(active_at <= ? AND inactive_at > ?) OR
14
+ (active_at <= ? AND inactive_at IS ?)",
15
+ Time.now, Time.now, Time.now, nil) }
16
+ scope :unpublished, -> { where("active_at > ? OR inactive_at < ? OR
17
+ (active_at IS ? AND inactive_at IS ?)",
18
+ Time.now, Time.now, nil, nil) }
19
+
20
+ end
21
+
22
+ # --------------------------------- Instance Methods
23
+
24
+ def published?
25
+ return false if active_at.nil?
26
+ (active_at <= Time.now and inactive_at == nil) or
27
+ (active_at <= Time.now and inactive_at >= Time.now)
28
+ end
29
+
30
+ def formatted_active_date
31
+ return '' if active_at.nil?
32
+ active_at.strftime("%d %B, %Y")
33
+ end
34
+
35
+ def formatted_inactive_date
36
+ return '' if inactive_at.nil?
37
+ inactive_at.strftime("%d %B, %Y")
38
+ end
39
+
40
+ def formatted_active_time
41
+ return '' if active_at.nil?
42
+ active_at.strftime("%l:%M %p")
43
+ end
44
+
45
+ def formatted_inactive_time
46
+ return '' if inactive_at.nil?
47
+ inactive_at.strftime("%l:%M %p")
48
+ end
49
+
50
+ end
@@ -0,0 +1,52 @@
1
+ module Slug
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ after_save :sluggify_slug
6
+ end
7
+
8
+ def sluggify_slug
9
+ if slug.blank?
10
+ update_column(:slug, create_slug)
11
+ else
12
+ new_slug = slug.gsub(/[^a-zA-Z0-9 \-]/, "") # remove all bad characters
13
+ new_slug.gsub!(/\ /, "-") # replace spaces with underscores
14
+ new_slug.gsub!(/\-+/, "-") # replace repeating underscores
15
+ update_column(:slug, new_slug) unless slug == new_slug
16
+ end
17
+ end
18
+
19
+ def create_slug
20
+ slug = self.title.downcase.gsub(/\&/, ' and ') # & -> and
21
+ slug.gsub!(/[^a-zA-Z0-9 \-]/, "") # remove all bad characters
22
+ slug.gsub!(/\ /, "-") # replace spaces with underscores
23
+ slug.gsub!(/\-+/, "-") # replace repeating underscores
24
+
25
+ dups = self.class.name.constantize.where(:slug => slug)
26
+ if dups.count == 1 and dups.first != self
27
+ if self.idx.present?
28
+ slug = "#{slug}-#{self.idx}"
29
+ else
30
+ slug = "#{slug}-#{self.id}"
31
+ end
32
+ end
33
+ slug
34
+ end
35
+
36
+ def make_slug_unique(slug)
37
+ dups = self.class.name.constantize.where(:slug => slug)
38
+ if dups.count == 1 and dups.first != self
39
+ if self.idx.present?
40
+ slug = "#{slug}-#{self.idx}"
41
+ else
42
+ slug = "#{slug}-#{self.id}"
43
+ end
44
+ end
45
+ slug
46
+ end
47
+
48
+ def to_param
49
+ slug
50
+ end
51
+
52
+ end
@@ -0,0 +1,28 @@
1
+ module Tags
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ has_many :taggings, :as => :taggable
6
+ has_many :tags, :through => :taggings
7
+
8
+ attr_accessor :tag_list
9
+
10
+ after_save :update_tags!
11
+ end
12
+
13
+ def update_tags!
14
+ unless tag_list.nil?
15
+ self.tags = []
16
+ used_tags = []
17
+ tag_list.split(',').each do |name|
18
+ name.strip!
19
+ if !used_tags.include?(name) && name.present?
20
+ used_tags << name
21
+ tag = Tag.find_or_create_by(:name => name)
22
+ self.tags << tag
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,7 @@
1
+ module Title
2
+
3
+ def title
4
+ name
5
+ end
6
+
7
+ end
@@ -0,0 +1,14 @@
1
+ class User < ActiveRecord::Base
2
+
3
+ # ------------------------------------------ Devise
4
+
5
+ # Include default devise modules. Others available are:
6
+ # :lockable, :timeoutable, :omniauthable, :confirmable, :registerable
7
+ devise :database_authenticatable, :recoverable, :rememberable, :trackable,
8
+ :validatable
9
+
10
+ # ------------------------------------------ Scopes
11
+
12
+ scope :admins, -> { where(:is_admin => true) }
13
+
14
+ end
@@ -0,0 +1,5 @@
1
+ <%= link_to send("new_admin_#{model_table_singular}_path"),
2
+ :class => "button-color-1 new float-right" do %>
3
+ <i class="icon-plus margin-right-medium"></i>
4
+ <span><%= "New #{model_singular}" %></span>
5
+ <% end %>
@@ -0,0 +1,11 @@
1
+ <%= simple_form_for @item, :url => @url do |f| %>
2
+
3
+ <% content = capture do %>
4
+ <%= f.input @columns.first.to_sym %>
5
+ <% end %>
6
+
7
+ <%= form_section :title => 'overview', :content => content %>
8
+
9
+ <%= f.button :submit %>
10
+
11
+ <% end %>
@@ -0,0 +1 @@
1
+ <h1><%= model_plural %></h1>
@@ -0,0 +1,2 @@
1
+ <%= form_page :classname => @model.to_s, :index => @routes[:index],
2
+ :title => "Edit #{@item.title.to_s}" %>
@@ -0,0 +1,50 @@
1
+ <section id="pages">
2
+ <header>
3
+ <%= render :partial => 'buttons' %>
4
+ <%= render :partial => 'title' %>
5
+ </header>
6
+
7
+ <div class="table-container">
8
+
9
+ <%= render :partial => 'admin/shared/status' %>
10
+
11
+ <table>
12
+ <thead>
13
+ <tr>
14
+ <% @columns.each do |col| %>
15
+ <th><%= col.titleize %></th>
16
+ <% end %>
17
+ <% if @actions %>
18
+ <th class="actions">Actions</th>
19
+ <% end %>
20
+ </tr>
21
+ </thead>
22
+
23
+ <tbody>
24
+ <% @items.each do |item| %>
25
+ <tr>
26
+ <% @columns.each do |col| %>
27
+ <td><%= item.send(col) %></td>
28
+ <% end %>
29
+ <% if @actions %>
30
+ <td class="actions">
31
+ <% if @actions.include?(:edit) %>
32
+ <%= link_to [:edit, :admin, item] do %>
33
+ <i class="icon-pencil"></i>&nbsp;Edit
34
+ <% end %>
35
+ <% end %>
36
+ <% if @actions.include?(:delete) %>
37
+ <%= link_to [:admin, item], :method => :delete, :data => { :confirm => "Are you sure?" } do %>
38
+ <i class="icon-remove"></i>&nbsp;Delete
39
+ <% end %>
40
+ <% end %>
41
+ </td>
42
+ <% end %>
43
+ </tr>
44
+ <% end %>
45
+ </tbody>
46
+ </table>
47
+
48
+ </div>
49
+
50
+ </section>
@@ -0,0 +1,2 @@
1
+ <%= form_page :classname => @model.to_s, :index => @routes[:index],
2
+ :title => "New #{model_singular}" %>
@@ -0,0 +1,12 @@
1
+ <nav id="sidebar" class="vertical">
2
+ <ul>
3
+ <% admin_nav_items.each do |item| %>
4
+ <li <%= "class=active" if nav_active?(item[:controllers]) %>>
5
+ <%= link_to item[:path], :target => item[:target] do %>
6
+ <span class="icon"><i class="icon-<%= item[:icon] %>"></i></span>
7
+ <span class="title"><%= item[:label] %></span>
8
+ <% end %>
9
+ </li>
10
+ <% end %>
11
+ </ul>
12
+ </nav>
@@ -0,0 +1,3 @@
1
+ <% flash.each do |level,message| %>
2
+ <p class="<%= level %>"><%= message %></p>
3
+ <% end %>