cambium 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (218) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +339 -15
  4. data/{lib/generators/cambium/templates/app/assets/javascripts/admin/admin.js.coffee → app/assets/javascripts/cambium/admin/application.js.coffee} +4 -10
  5. data/app/assets/javascripts/cambium/admin/routers/router.js.coffee +25 -0
  6. data/app/assets/javascripts/cambium/admin/users.js +2 -0
  7. data/app/assets/javascripts/cambium/admin/views/dropdown_menu.js.coffee +24 -0
  8. data/app/assets/javascripts/cambium/admin/views/pickadate.js.coffee +15 -0
  9. data/app/assets/stylesheets/cambium/admin/application.scss +27 -0
  10. data/{lib/generators/cambium/templates/app/assets/stylesheets → app/assets/stylesheets/cambium}/admin/bones/bones-config/_colors.scss +7 -7
  11. data/{lib/generators/cambium/templates/app/assets/stylesheets → app/assets/stylesheets/cambium}/admin/bones/bones.scss +18 -18
  12. data/app/assets/stylesheets/cambium/admin/partials/_globals.scss +21 -0
  13. data/app/assets/stylesheets/cambium/admin/partials/activity.scss +52 -0
  14. data/app/assets/stylesheets/cambium/admin/partials/components.scss +64 -0
  15. data/app/assets/stylesheets/cambium/admin/partials/dashboard.scss +48 -0
  16. data/app/assets/stylesheets/cambium/admin/partials/forms.scss +107 -0
  17. data/app/assets/stylesheets/cambium/admin/partials/header.scss +113 -0
  18. data/app/assets/stylesheets/cambium/admin/partials/page_title.scss +42 -0
  19. data/app/assets/stylesheets/cambium/admin/partials/sidebar.scss +41 -0
  20. data/app/assets/stylesheets/cambium/admin/partials/tables.scss +80 -0
  21. data/app/assets/stylesheets/cambium/admin/partials/typography.scss +5 -0
  22. data/app/assets/stylesheets/cambium/admin/partials/wireframe.scss +52 -0
  23. data/app/assets/stylesheets/cambium/admin/users.css +4 -0
  24. data/app/controllers/cambium/admin/dashboard_controller.rb +12 -0
  25. data/app/controllers/cambium/admin/search_controller.rb +9 -0
  26. data/app/controllers/cambium/admin/users_controller.rb +30 -0
  27. data/app/controllers/cambium/admin_controller.rb +90 -0
  28. data/app/helpers/cambium/cambium_helper.rb +205 -0
  29. data/app/presenters/cambium/admin_presenter.rb +127 -0
  30. data/app/views/cambium/admin/_activity.html.erb +6 -0
  31. data/app/views/cambium/admin/_header.html.erb +41 -0
  32. data/app/views/cambium/admin/_sidebar.html.erb +19 -0
  33. data/app/views/cambium/admin/_status.html.erb +5 -0
  34. data/app/views/cambium/admin/dashboard/show.html.erb +5 -0
  35. data/app/views/cambium/admin/edit.html.erb +7 -0
  36. data/app/views/cambium/admin/index.html.erb +7 -0
  37. data/app/views/cambium/admin/new.html.erb +7 -0
  38. data/app/views/cambium/admin/paper_trail/versions/_version.html.erb +20 -0
  39. data/app/views/cambium/admin/search/index.html.erb +38 -0
  40. data/app/views/layouts/admin.html.erb +25 -0
  41. data/bin/rails +12 -0
  42. data/cambium.gemspec +19 -15
  43. data/config/routes.rb +10 -0
  44. data/lib/cambium/configuration.rb +28 -0
  45. data/lib/cambium/engine.rb +2 -1
  46. data/lib/cambium/version.rb +1 -1
  47. data/lib/cambium.rb +12 -1
  48. data/lib/generators/cambium/admin_generator.rb +104 -0
  49. data/lib/generators/cambium/app_generator.rb +205 -0
  50. data/lib/generators/cambium/controller_generator.rb +81 -0
  51. data/lib/generators/cambium/gemfile_generator.rb +36 -0
  52. data/lib/generators/cambium/install_generator.rb +19 -0
  53. data/lib/generators/cambium/user_generator.rb +40 -0
  54. data/lib/generators/{cambium/helpers → helpers}/generators_helper.rb +32 -24
  55. data/lib/generators/templates/Gemfile.erb +79 -0
  56. data/lib/generators/{cambium/templates/app/assets/javascripts/backbone/app.js.coffee → templates/app/assets/javascripts/application.js.coffee} +9 -1
  57. data/lib/generators/templates/app/assets/javascripts/views/default_helpers.js.coffee +16 -0
  58. data/lib/generators/templates/app/assets/stylesheets/admin/admin.scss +3 -0
  59. data/lib/generators/templates/app/controllers/admin/controller.rb.erb +2 -0
  60. data/lib/generators/{cambium/templates → templates}/app/controllers/application_controller.rb +1 -5
  61. data/lib/generators/{cambium/templates → templates}/app/models/user.rb +4 -4
  62. data/lib/generators/templates/app/views/application/_status.html.erb +3 -0
  63. data/lib/generators/{cambium/templates → templates}/app/views/layouts/application.html.erb +1 -1
  64. data/lib/generators/templates/config/admin/controller.yml.erb +24 -0
  65. data/lib/generators/templates/config/admin/sidebar.yml +9 -0
  66. data/lib/generators/templates/config/admin/users.yml +31 -0
  67. data/lib/generators/{cambium/templates → templates}/config/application.rb +6 -4
  68. data/lib/generators/templates/config/initializers/_hash.rb +23 -0
  69. data/lib/generators/templates/config/initializers/_settings.rb +18 -0
  70. data/lib/generators/templates/config/initializers/assets.rb +1 -0
  71. data/lib/generators/templates/config/initializers/cambium.rb +16 -0
  72. data/lib/generators/templates/config/private.yml +16 -0
  73. data/lib/generators/templates/config/routes.rb +54 -0
  74. data/lib/generators/templates/config/settings.yml +16 -0
  75. data/lib/generators/{cambium/templates → templates}/gitignore +1 -1
  76. data/lib/help/cambium_prereqs.txt +13 -0
  77. data/lib/help/pg_search_post_install.txt +13 -0
  78. data/lib/{generators/cambium/templates/lib/tasks → tasks}/db.rake +2 -2
  79. data/lib/{generators/cambium/templates/lib/tasks → tasks}/rename.rake +1 -1
  80. data/test/controllers/cambium/admin/dashboard_controller_test.rb +9 -0
  81. data/test/controllers/cambium/admin/users_controller_test.rb +9 -0
  82. data/test/controllers/cambium/admin_controller_test.rb +9 -0
  83. metadata +192 -152
  84. data/bin/cambium +0 -16
  85. data/lib/generators/cambium/helpers/dependencies_helper.rb +0 -58
  86. data/lib/generators/cambium/install/admin_generator.rb +0 -110
  87. data/lib/generators/cambium/install/app_generator.rb +0 -162
  88. data/lib/generators/cambium/install/config_generator.rb +0 -182
  89. data/lib/generators/cambium/install/utilities_generator.rb +0 -57
  90. data/lib/generators/cambium/model/image_generator.rb +0 -67
  91. data/lib/generators/cambium/model/page_generator.rb +0 -131
  92. data/lib/generators/cambium/model/post_generator.rb +0 -71
  93. data/lib/generators/cambium/model/tag_generator.rb +0 -40
  94. data/lib/generators/cambium/model/user_generator.rb +0 -78
  95. data/lib/generators/cambium/templates/Gemfile +0 -43
  96. data/lib/generators/cambium/templates/Gemfile.erb +0 -40
  97. data/lib/generators/cambium/templates/_partials/pages/admin_icon.rb +0 -6
  98. data/lib/generators/cambium/templates/app/assets/javascripts/.DS_Store +0 -0
  99. data/lib/generators/cambium/templates/app/assets/javascripts/admin/collections/.gitkeep +0 -0
  100. data/lib/generators/cambium/templates/app/assets/javascripts/admin/models/.gitkeep +0 -0
  101. data/lib/generators/cambium/templates/app/assets/javascripts/admin/models/image.js.coffee +0 -14
  102. data/lib/generators/cambium/templates/app/assets/javascripts/admin/models/tag.js.coffee +0 -14
  103. data/lib/generators/cambium/templates/app/assets/javascripts/admin/parser_rules/custom.js +0 -552
  104. data/lib/generators/cambium/templates/app/assets/javascripts/admin/routers/router.js.coffee +0 -37
  105. data/lib/generators/cambium/templates/app/assets/javascripts/admin/tag.jst.ejs +0 -7
  106. data/lib/generators/cambium/templates/app/assets/javascripts/admin/templates/image.jst.ejs +0 -3
  107. data/lib/generators/cambium/templates/app/assets/javascripts/admin/templates/paginator_controls.jst.ejs +0 -8
  108. data/lib/generators/cambium/templates/app/assets/javascripts/admin/templates/paginator_nav.jst.ejs +0 -11
  109. data/lib/generators/cambium/templates/app/assets/javascripts/admin/templates/post_tag.jst.ejs +0 -1
  110. data/lib/generators/cambium/templates/app/assets/javascripts/admin/views/accordion.js.coffee +0 -33
  111. data/lib/generators/cambium/templates/app/assets/javascripts/admin/views/counter.js.coffee +0 -25
  112. data/lib/generators/cambium/templates/app/assets/javascripts/admin/views/dropdown_toggle.js.coffee +0 -16
  113. data/lib/generators/cambium/templates/app/assets/javascripts/admin/views/image_upload.js.coffee +0 -28
  114. data/lib/generators/cambium/templates/app/assets/javascripts/admin/views/init_counter.js.coffee +0 -13
  115. data/lib/generators/cambium/templates/app/assets/javascripts/admin/views/paginator.js.coffee +0 -86
  116. data/lib/generators/cambium/templates/app/assets/javascripts/admin/views/publishable.js.coffee +0 -12
  117. data/lib/generators/cambium/templates/app/assets/javascripts/admin/views/tags.js.coffee +0 -158
  118. data/lib/generators/cambium/templates/app/assets/javascripts/admin/views/wysiwyg.js.coffee +0 -87
  119. data/lib/generators/cambium/templates/app/assets/javascripts/admin/wysihtml5.js +0 -9521
  120. data/lib/generators/cambium/templates/app/assets/javascripts/application.js +0 -10
  121. data/lib/generators/cambium/templates/app/assets/javascripts/backbone/templates/.keep +0 -0
  122. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/admin.scss +0 -14
  123. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/partials/_content.scss +0 -88
  124. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/partials/_form.scss +0 -470
  125. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/partials/_globals.scss +0 -39
  126. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/partials/_header.scss +0 -121
  127. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/partials/_nav.scss +0 -45
  128. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/partials/_wireframe.scss +0 -24
  129. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/wysihtml5.css +0 -7
  130. data/lib/generators/cambium/templates/app/controllers/admin/images_controller.rb +0 -45
  131. data/lib/generators/cambium/templates/app/controllers/admin/pages_controller.rb +0 -42
  132. data/lib/generators/cambium/templates/app/controllers/admin/posts_controller.rb +0 -39
  133. data/lib/generators/cambium/templates/app/controllers/admin/taggings_controller.rb +0 -69
  134. data/lib/generators/cambium/templates/app/controllers/admin/tags_controller.rb +0 -11
  135. data/lib/generators/cambium/templates/app/controllers/admin/users_controller.rb +0 -13
  136. data/lib/generators/cambium/templates/app/controllers/admin_controller.rb +0 -97
  137. data/lib/generators/cambium/templates/app/controllers/images_controller.rb +0 -45
  138. data/lib/generators/cambium/templates/app/controllers/pages_controller.rb +0 -12
  139. data/lib/generators/cambium/templates/app/controllers/posts_controller.rb +0 -11
  140. data/lib/generators/cambium/templates/app/helpers/admin/pages_controller.rb +0 -47
  141. data/lib/generators/cambium/templates/app/helpers/admin_helper.rb +0 -121
  142. data/lib/generators/cambium/templates/app/models/concerns/name.rb +0 -7
  143. data/lib/generators/cambium/templates/app/models/concerns/title.rb +0 -7
  144. data/lib/generators/cambium/templates/app/models/image.rb +0 -43
  145. data/lib/generators/cambium/templates/app/models/page.rb +0 -81
  146. data/lib/generators/cambium/templates/app/models/post.rb +0 -45
  147. data/lib/generators/cambium/templates/app/models/tag.rb +0 -33
  148. data/lib/generators/cambium/templates/app/models/tagging.rb +0 -20
  149. data/lib/generators/cambium/templates/app/uploaders/image_uploader.rb +0 -91
  150. data/lib/generators/cambium/templates/app/views/admin/_buttons.html.erb +0 -5
  151. data/lib/generators/cambium/templates/app/views/admin/_form.html.erb +0 -11
  152. data/lib/generators/cambium/templates/app/views/admin/_title.html.erb +0 -1
  153. data/lib/generators/cambium/templates/app/views/admin/edit.html.erb +0 -2
  154. data/lib/generators/cambium/templates/app/views/admin/images/_image.html.erb +0 -1
  155. data/lib/generators/cambium/templates/app/views/admin/images/create.js.erb +0 -7
  156. data/lib/generators/cambium/templates/app/views/admin/images/index.json.jbuilder +0 -4
  157. data/lib/generators/cambium/templates/app/views/admin/index.html.erb +0 -50
  158. data/lib/generators/cambium/templates/app/views/admin/new.html.erb +0 -2
  159. data/lib/generators/cambium/templates/app/views/admin/pages/_form.html.erb +0 -26
  160. data/lib/generators/cambium/templates/app/views/admin/posts/_form.html.erb +0 -40
  161. data/lib/generators/cambium/templates/app/views/admin/shared/_footer.html.erb +0 -2
  162. data/lib/generators/cambium/templates/app/views/admin/shared/_header.html.erb +0 -2
  163. data/lib/generators/cambium/templates/app/views/admin/shared/_insert_image.html.erb +0 -12
  164. data/lib/generators/cambium/templates/app/views/admin/shared/_nav.html.erb +0 -12
  165. data/lib/generators/cambium/templates/app/views/admin/shared/_status.html.erb +0 -3
  166. data/lib/generators/cambium/templates/app/views/admin/shared/forms/_editor.html.erb +0 -54
  167. data/lib/generators/cambium/templates/app/views/admin/shared/forms/_form_column_left.html.erb +0 -9
  168. data/lib/generators/cambium/templates/app/views/admin/shared/forms/_form_column_right.html.erb +0 -9
  169. data/lib/generators/cambium/templates/app/views/admin/shared/forms/_form_page.html.erb +0 -22
  170. data/lib/generators/cambium/templates/app/views/admin/shared/forms/_form_section.html.erb +0 -8
  171. data/lib/generators/cambium/templates/app/views/admin/shared/forms/_publishable.html.erb +0 -33
  172. data/lib/generators/cambium/templates/app/views/admin/users/_form.html.erb +0 -11
  173. data/lib/generators/cambium/templates/app/views/application/_status.html.erb +0 -3
  174. data/lib/generators/cambium/templates/app/views/layouts/.DS_Store +0 -0
  175. data/lib/generators/cambium/templates/app/views/layouts/admin.html.erb +0 -44
  176. data/lib/generators/cambium/templates/app/views/page_templates/default.html.erb +0 -2
  177. data/lib/generators/cambium/templates/app/views/posts/_post.html.erb +0 -4
  178. data/lib/generators/cambium/templates/app/views/posts/index.html.erb +0 -1
  179. data/lib/generators/cambium/templates/app/views/posts/show.html.erb +0 -10
  180. data/lib/generators/cambium/templates/config/app_routes.rb +0 -77
  181. data/lib/generators/cambium/templates/config/database.mysql2.yml.erb +0 -15
  182. data/lib/generators/cambium/templates/config/database.pg.yml.erb +0 -14
  183. data/lib/generators/cambium/templates/config/database.sqlite3.yml.erb +0 -18
  184. data/lib/generators/cambium/templates/config/initializers/_settings.rb +0 -11
  185. data/lib/generators/cambium/templates/config/initializers/assets.rb +0 -1
  186. data/lib/generators/cambium/templates/config/routes.rb.erb +0 -42
  187. data/lib/generators/cambium/templates/config/settings.yml +0 -15
  188. data/lib/generators/cambium/templates/config/settings_private.sample.yml +0 -15
  189. data/lib/generators/cambium/templates/config/settings_private.yml +0 -13
  190. data/lib/generators/cambium/templates/db/migrate/create_pages.rb.erb +0 -24
  191. data/lib/generators/cambium/templates/db/migrate/create_posts.rb +0 -19
  192. data/lib/generators/cambium/templates/lib/.DS_Store +0 -0
  193. data/lib/help/cambium +0 -7
  194. /data/{lib/generators/cambium/templates/app/assets/javascripts/backbone/collections → app/assets/javascripts/cambium/admin/templates}/.keep +0 -0
  195. /data/{lib/generators/cambium/templates/app/assets/javascripts/backbone → app/assets/javascripts/cambium/admin}/views/default_helpers.js.coffee +0 -0
  196. /data/{lib/generators/cambium/templates/app/assets/stylesheets → app/assets/stylesheets/cambium}/admin/bones/bones-config/__default.scss +0 -0
  197. /data/{lib/generators/cambium/templates/app/assets/stylesheets → app/assets/stylesheets/cambium}/admin/bones/bones-config/_buttons.scss +0 -0
  198. /data/{lib/generators/cambium/templates/app/assets/stylesheets → app/assets/stylesheets/cambium}/admin/bones/bones-config/_components.scss +0 -0
  199. /data/{lib/generators/cambium/templates/app/assets/stylesheets → app/assets/stylesheets/cambium}/admin/bones/bones-config/_forms.scss +0 -0
  200. /data/{lib/generators/cambium/templates/app/assets/stylesheets → app/assets/stylesheets/cambium}/admin/bones/bones-config/_helpers.scss +0 -0
  201. /data/{lib/generators/cambium/templates/app/assets/stylesheets → app/assets/stylesheets/cambium}/admin/bones/bones-config/_images.scss +0 -0
  202. /data/{lib/generators/cambium/templates/app/assets/stylesheets → app/assets/stylesheets/cambium}/admin/bones/bones-config/_nav.scss +0 -0
  203. /data/{lib/generators/cambium/templates/app/assets/stylesheets → app/assets/stylesheets/cambium}/admin/bones/bones-config/_tables.scss +0 -0
  204. /data/{lib/generators/cambium/templates/app/assets/stylesheets → app/assets/stylesheets/cambium}/admin/bones/bones-config/_typography.scss +0 -0
  205. /data/{lib/generators/cambium/templates/app/assets/stylesheets → app/assets/stylesheets/cambium}/admin/bones/bones-config/_wireframe.scss +0 -0
  206. /data/{lib/generators/cambium/templates/app → app}/models/concerns/idx.rb +0 -0
  207. /data/{lib/generators/cambium/templates/app → app}/models/concerns/image_cropper.rb +0 -0
  208. /data/{lib/generators/cambium/templates/app → app}/models/concerns/publishable.rb +0 -0
  209. /data/{lib/generators/cambium/templates/app → app}/models/concerns/slug.rb +0 -0
  210. /data/{lib/generators/cambium/templates/app → app}/models/concerns/tags.rb +0 -0
  211. /data/lib/generators/{cambium/helpers → helpers}/_autoloader.rb +0 -0
  212. /data/lib/generators/{cambium/templates/app/assets/javascripts/backbone → templates/app/assets/javascripts}/routers/router.js.coffee +0 -0
  213. /data/lib/generators/{cambium/templates/app/assets/javascripts/backbone/models → templates/app/assets/javascripts/templates}/.keep +0 -0
  214. /data/lib/generators/{cambium/templates → templates}/app/assets/stylesheets/application.scss +0 -0
  215. /data/lib/generators/{cambium/templates → templates}/app/views/home/index.html.erb +0 -0
  216. /data/lib/generators/{cambium/templates → templates}/db/seeds.rb +0 -0
  217. /data/{lib/generators/cambium/templates/vendor → vendor}/assets/javascripts/modernizr.js +0 -0
  218. /data/{lib/generators/cambium/templates/vendor → vendor}/assets/stylesheets/normalize.scss +0 -0
@@ -0,0 +1,205 @@
1
+ module Cambium
2
+ module CambiumHelper
3
+
4
+ def not_found
5
+ raise ActionController::RoutingError.new('Not Found')
6
+ end
7
+
8
+ def avatar(user, size = 100, klass = nil)
9
+ gravatar_id = Digest::MD5.hexdigest(user.email.downcase)
10
+ content_tag(:div, :class => "avatar-container #{klass}") do
11
+ image_tag "http://gravatar.com/avatar/#{gravatar_id}.png?s=#{size}&d=mm",
12
+ :class => 'avatar'
13
+ end
14
+ end
15
+
16
+ def admin
17
+ @admin ||= Cambium::AdminPresenter.new(self)
18
+ end
19
+
20
+ def admin_view
21
+ @admin_view ||= admin.view(controller_name)
22
+ end
23
+
24
+ def admin_table
25
+ @admin_table ||= admin_view.nil? ? nil : admin_view.table
26
+ end
27
+
28
+ def admin_form
29
+ @admin_form ||= begin
30
+ if action_name == 'new' || action_name == 'create'
31
+ admin_view.form.new
32
+ else
33
+ admin_view.form.edit
34
+ end
35
+ end
36
+ end
37
+
38
+ def admin_routes
39
+ @admin_routes ||= admin.routes(@object)
40
+ end
41
+
42
+ def admin_model
43
+ @admin_model ||= admin_view.model.constantize
44
+ end
45
+
46
+ def cambium_page_title(title)
47
+ content_tag(:div, :id => 'title-bar') do
48
+ o = content_tag(:h2, title, :class => 'page-title')
49
+ if is_index? && has_new_form?
50
+ o += link_to(
51
+ admin_view.form.new.title,
52
+ admin_routes.new,
53
+ :class => 'button new'
54
+ )
55
+ end
56
+ if is_index? && admin_view.export.present?
57
+ o += link_to(
58
+ admin_view.export.button || "Export #{admin_table.title}",
59
+ "#{admin_routes.index}.csv",
60
+ :class => 'button export'
61
+ )
62
+ end
63
+ o.html_safe
64
+ end
65
+ end
66
+
67
+ def cambium_table(collection, columns)
68
+ obj_methods = []
69
+ content_tag(:section, :class => 'data-table') do
70
+ p = content_tag(:table) do
71
+ o = content_tag(:thead) do
72
+ content_tag(:tr) do
73
+ o2 = ''
74
+ columns.to_h.each do |col|
75
+ obj_methods << col.first.to_s
76
+ o2 += content_tag(:th, col.last.heading)
77
+ end
78
+ o2 += content_tag(:th, nil)
79
+ o2.html_safe
80
+ end
81
+ end
82
+ o += content_tag(:tbody) do
83
+ o2 = ''
84
+ collection.each do |obj|
85
+ o2 += content_tag(:tr) do
86
+ o3 = ''
87
+ obj_methods.each do |method|
88
+ o3 += content_tag(:td, obj.send(method))
89
+ end
90
+ path = "edit_admin_#{controller_name.singularize}_path"
91
+ begin
92
+ route = cambium.send(path, obj)
93
+ rescue
94
+ route = main_app.send(path, obj)
95
+ end
96
+ o3 += content_tag(:td, link_to('', route), :class => 'actions')
97
+ o3.html_safe
98
+ end
99
+ end
100
+ o2.html_safe
101
+ end
102
+ o.html_safe
103
+ end
104
+ p += paginate(collection)
105
+ end
106
+ end
107
+
108
+ def cambium_form(obj, fields)
109
+ content_tag(:section, :class => 'form') do
110
+ simple_form_for [:admin, obj] do |f|
111
+ o = ''
112
+ fields.to_h.each do |data|
113
+ attr = data.first.to_s
114
+ options = data.last
115
+ if ['select','check_boxes','radio_buttons'].include?(options.type)
116
+ o += f.input(
117
+ attr.to_sym,
118
+ :as => options.type,
119
+ :collection => options.options
120
+ )
121
+ elsif ['date','time'].include?(options.type)
122
+ if obj.send(attr).present?
123
+ val = (options.type == 'date') ?
124
+ obj.send(attr).strftime("%d %B, %Y") :
125
+ obj.send(attr).strftime("%l:%M %p")
126
+ end
127
+ o += f.input(
128
+ attr.to_sym,
129
+ :as => :string,
130
+ :input_html => {
131
+ :class => "picka#{options.type}",
132
+ :value => val.nil? ? nil : val
133
+ }
134
+ )
135
+ elsif options.type == 'datetime'
136
+ o += content_tag(:div, :class => 'input string pickadatetime') do
137
+ o2 = content_tag(:label, attr.to_s.humanize.titleize)
138
+ o2 += content_tag(
139
+ :input,
140
+ '',
141
+ :placeholder => 'Date',
142
+ :type => 'text',
143
+ :class => 'pickadatetime-date',
144
+ :value => obj.send(attr).present? ?
145
+ obj.send(attr).strftime("%d %B, %Y") : ''
146
+ )
147
+ o2 += content_tag(
148
+ :input,
149
+ '',
150
+ :placeholder => 'Time',
151
+ :type => 'text',
152
+ :class => 'pickadatetime-time',
153
+ :value => obj.send(attr).present? ?
154
+ obj.send(attr).strftime("%l:%M %p") : ''
155
+ )
156
+ o2 += f.input(
157
+ attr.to_sym,
158
+ :as => :hidden,
159
+ :wrapper => false,
160
+ :label => false,
161
+ :input_html => { :class => 'pickadatetime' }
162
+ )
163
+ end
164
+ elsif options.type == 'markdown'
165
+ o += content_tag(:div, :class => "input text optional #{attr}") do
166
+ o2 = content_tag(:label, attr.titleize, :for => attr)
167
+ o2 += content_tag(
168
+ :div,
169
+ f.markdown(attr.to_sym),
170
+ :class => 'markdown'
171
+ )
172
+ end
173
+ else
174
+ o += f.input(
175
+ attr.to_sym,
176
+ :as => options.type
177
+ )
178
+ end
179
+ end
180
+ o += f.submit
181
+ o.html_safe
182
+ end
183
+ end
184
+ end
185
+
186
+ def cambium_edit_route(obj)
187
+ controller = obj.class.to_s.humanize.singularize.downcase
188
+ path = "admin_#{controller}_path"
189
+ begin
190
+ cambium.send(path, obj)
191
+ rescue
192
+ main_app.send(path, obj)
193
+ end
194
+ end
195
+
196
+ def is_index?
197
+ action_name == 'index'
198
+ end
199
+
200
+ def has_new_form?
201
+ admin_view.form.present? && admin_view.form.new.present?
202
+ end
203
+
204
+ end
205
+ end
@@ -0,0 +1,127 @@
1
+ require 'csv'
2
+
3
+ module Cambium
4
+ class AdminPresenter
5
+
6
+ def initialize(action_view)
7
+ @view = action_view
8
+ end
9
+
10
+ # Resolves the values from config/admin/sidebar.yml and
11
+ # puts them in an array
12
+ #
13
+ def sidebar
14
+ @sidebar ||= begin
15
+ sidebar = []
16
+ load_config('sidebar').each { |k, attrs| sidebar << attrs.to_ostruct }
17
+ sidebar.each do |attrs|
18
+ # resolve route
19
+ path = "#{attrs.route.split('.').last}_path"
20
+ if attrs.route.split('.').first == 'cambium'
21
+ attrs.route = @view.cambium.send(path)
22
+ else
23
+ attrs.route = @view.main_app.send(path)
24
+ end
25
+ # figure out if it's active
26
+ attrs.active = false
27
+ if(
28
+ (
29
+ attrs.controllers &&
30
+ attrs.controllers.include?(@view.controller_name)
31
+ ) || @view.request.path == attrs.route
32
+ )
33
+ attrs.active = true
34
+ end
35
+ end
36
+ sidebar
37
+ end
38
+ end
39
+
40
+ # Gets all the data from the desired config file, which
41
+ # are further broken up in other methods
42
+ #
43
+ def view(name)
44
+ load_config(name).nil? ? nil : load_config(name).to_ostruct
45
+ end
46
+
47
+ # Resolve the routes for the given controller
48
+ #
49
+ def routes(object)
50
+ begin
51
+ n = @view.cambium
52
+ @view.cambium.send("admin_#{@view.controller_name.pluralize}_path")
53
+ rescue
54
+ n = @view.main_app
55
+ end
56
+ r = {
57
+ :index => n.send("admin_#{@view.controller_name.pluralize}_path"),
58
+ :new => n.send("new_admin_#{@view.controller_name.singularize}_path")
59
+ }
60
+ if !object.nil? && object.id.present?
61
+ r[:edit] = n.send(
62
+ "edit_admin_#{@view.controller_name.singularize}_path",
63
+ object
64
+ )
65
+ r[:show] = n.send(
66
+ "admin_#{@view.controller_name.singularize}_path",
67
+ object
68
+ )
69
+ end
70
+ r.to_ostruct
71
+ end
72
+
73
+ # Export a collection of objects to csv, based on the
74
+ # configuration
75
+ #
76
+ def to_csv(collection)
77
+ config = view(@view.controller_name).export
78
+ output = CSV.generate do |csv|
79
+ # Grab headings and methods
80
+ headings = []
81
+ methods = []
82
+ config.columns.each_pair do |key, data|
83
+ if data.label.nil?
84
+ headings << key.to_s.titleize
85
+ else
86
+ headings << data.label
87
+ end
88
+ if data.output.nil?
89
+ methods << key.to_s
90
+ else
91
+ methods << data.output
92
+ end
93
+ end
94
+ csv << headings
95
+
96
+ # Get the data
97
+ collection.each do |obj|
98
+ vals = []
99
+ methods.each do |m|
100
+ chain = m.split('.').reject(&:blank?)
101
+ if chain.size > 1
102
+ val = obj
103
+ chain.each do |c|
104
+ args = c[/\(.*?\)/]
105
+ args = args.nil? ? [] : args[1..-2].split(',').map { |s| eval(s) }
106
+ method = c.split('(').first
107
+ val = args.size > 0 ? val.send(method, *args) : val.send(method)
108
+ end
109
+ vals << val
110
+ else
111
+ vals << obj.send(m)
112
+ end
113
+ end
114
+ csv << vals
115
+ end
116
+ end
117
+ end
118
+
119
+ private
120
+
121
+ def load_config(filename)
122
+ file = File.join(Rails.root,'config','admin',"#{filename}.yml")
123
+ File.exists?(file) ? YAML.load_file(file) : nil
124
+ end
125
+
126
+ end
127
+ end
@@ -0,0 +1,6 @@
1
+ <aside id="activity">
2
+ <%= render(
3
+ :partial => 'cambium/admin/paper_trail/versions/version',
4
+ :collection => @activities
5
+ ) %>
6
+ </aside>
@@ -0,0 +1,41 @@
1
+ <header>
2
+ <div class="logo">
3
+ <%= link_to Cambium.configuration.app_title, cambium.admin_dashboard_path %>
4
+ </div>
5
+
6
+ <div class="user dropdown-container">
7
+ <%= link_to('#', :class => 'dropdown-trigger') do %>
8
+ <%= content_tag(
9
+ :span,
10
+ current_user.name.blank? ? current_user.email : current_user.name,
11
+ :class => 'name'
12
+ ) %>
13
+ <%= avatar(current_user, 84) %>
14
+ <% end %>
15
+ <div class="dropdown-menu">
16
+ <ul>
17
+ <%= content_tag(
18
+ :li,
19
+ link_to(
20
+ 'Edit Profile',
21
+ cambium.edit_admin_user_path(current_user)
22
+ )
23
+ ) %>
24
+ <%= content_tag(
25
+ :li,
26
+ link_to(
27
+ 'Sign Out',
28
+ main_app.destroy_user_session_path,
29
+ )
30
+ ) %>
31
+ </ul>
32
+ </div>
33
+ </div>
34
+
35
+ <div class="search-box">
36
+ <form action="<%= cambium.admin_search_path %>">
37
+ <input type="text" name="q" placeholder="search ...">
38
+ </form>
39
+ </div>
40
+
41
+ </header>
@@ -0,0 +1,19 @@
1
+ <aside id="nav">
2
+ <nav>
3
+ <ul>
4
+ <% admin.sidebar.each do |item| %>
5
+ <%= content_tag(
6
+ :li,
7
+ link_to(
8
+ item.route,
9
+ :class => item.active == true ? 'active' : nil
10
+ ) {
11
+ "#{content_tag(
12
+ :i, nil, :class => "icon-#{item.icon}"
13
+ )} #{item.label}".html_safe
14
+ }
15
+ ) %>
16
+ <% end %>
17
+ </ul>
18
+ </nav>
19
+ </aside>
@@ -0,0 +1,5 @@
1
+ <div class="status">
2
+ <% flash.each do |lvl, msg| %>
3
+ <%= content_tag(:p, msg, :class => lvl) %>
4
+ <% end %>
5
+ </div>
@@ -0,0 +1,5 @@
1
+ <%= cambium_page_title('Latest Activity') %>
2
+
3
+ <div id="page-content" class="dashboard">
4
+ <%= content_tag(:section, render(@activities)) %>
5
+ </div>
@@ -0,0 +1,7 @@
1
+ <%= cambium_page_title(admin_form.title) %>
2
+
3
+ <%= content_tag(
4
+ :div,
5
+ cambium_form(@object, admin_form.fields),
6
+ :id => 'page-content'
7
+ ) %>
@@ -0,0 +1,7 @@
1
+ <%= cambium_page_title(admin_table.title) %>
2
+
3
+ <%= content_tag(
4
+ :div,
5
+ cambium_table(@collection, admin_table.columns),
6
+ :id => 'page-content'
7
+ ) %>
@@ -0,0 +1,7 @@
1
+ <%= cambium_page_title(admin_form.title) %>
2
+
3
+ <%= content_tag(
4
+ :div,
5
+ cambium_form(@object, admin_form.fields),
6
+ :id => 'page-content'
7
+ ) %>
@@ -0,0 +1,20 @@
1
+ <% if version.whodunnit.present? %>
2
+ <% user = @users.select { |u| u.id == version.whodunnit.to_i }.first %>
3
+ <article>
4
+ <%= avatar(user, 72) %>
5
+ <div class="content">
6
+ <p class="date">
7
+ <%= "#{time_ago_in_words(version.created_at)} ago" %>
8
+ </p>
9
+ <p class="action">
10
+ <%= content_tag(:strong, user.name) %>
11
+ <%= "#{version.event}d" %>
12
+ <%= version.item_type.downcase %>
13
+ <%= content_tag(
14
+ :strong,
15
+ link_to(version.item.to_s, cambium_edit_route(version.item))
16
+ ) %>
17
+ </p>
18
+ </div>
19
+ </article>
20
+ <% end %>
@@ -0,0 +1,38 @@
1
+ <div id="title-bar">
2
+ <h2 class="page-title">Search Results for &ldquo;<%= params[:q] %>&rdquo;</h2>
3
+ </div>
4
+
5
+ <div id="page-content">
6
+ <section class="data-table">
7
+ <table>
8
+ <thead>
9
+ <tr>
10
+ <th></th>
11
+ <th></th>
12
+ <th></th>
13
+ </tr>
14
+ </thead>
15
+ <tbody>
16
+ <% if @collection.size > 0 %>
17
+ <% @collection.each do |item| %>
18
+ <tr>
19
+ <%= content_tag(:td, item.searchable_type, :class => 'search-type') %>
20
+ <%= content_tag(:td, item.searchable.to_s) %>
21
+ <%= content_tag(
22
+ :td,
23
+ link_to('', cambium_edit_route(item.searchable)),
24
+ :class => 'actions'
25
+ ) %>
26
+ </tr>
27
+ <% end %>
28
+ <% else %>
29
+ <tr>
30
+ <td colspan="3" class="no-results">
31
+ No items matched your search results.
32
+ </td>
33
+ </tr>
34
+ <% end %>
35
+ </tbody>
36
+ </table>
37
+ </section>
38
+ </div>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html class="public">
3
+ <head>
4
+ <title>Cambium</title>
5
+ <meta charset="utf-8">
6
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
7
+ <meta name="robots" content="noindex, nofollow">
8
+ <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0">
9
+ <meta name="apple-mobile-web-app-capable" content="yes">
10
+ <meta name="format-detection" content="telephone=no">
11
+ <%= stylesheet_link_tag 'cambium/admin/application', :media => 'all' %>
12
+ <%= javascript_include_tag "modernizr" %>
13
+ <%= csrf_meta_tags %>
14
+ </head>
15
+ <body class="cambium admin <%= 'dashboard' if controller_name == 'dashboard' %>">
16
+
17
+ <%= render 'cambium/admin/status' %>
18
+ <%= render 'cambium/admin/header' %>
19
+ <%= render 'cambium/admin/sidebar' %>
20
+ <%= content_tag(:div, yield, :id => 'container') %>
21
+ <%= render 'cambium/admin/activity' unless controller_name == 'dashboard' %>
22
+
23
+ <%= javascript_include_tag 'cambium/admin/application' %>
24
+ </body>
25
+ </html>
data/bin/rails ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
3
+
4
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
+ ENGINE_PATH = File.expand_path('../../lib/cambium/engine', __FILE__)
6
+
7
+ # Set up gems listed in the Gemfile.
8
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
9
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
10
+
11
+ require 'rails/all'
12
+ require 'rails/engine/commands'
data/cambium.gemspec CHANGED
@@ -6,8 +6,8 @@ require 'cambium/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "cambium"
8
8
  spec.version = Cambium::VERSION
9
- spec.authors = ["Sean C Davis","Warren Harrison"]
10
- spec.email = ["scdavis41@gmail.com","warren@hungry-media.com"]
9
+ spec.authors = ["Sean C Davis", "Warren Harrison"]
10
+ spec.email = ["scdavis41@gmail.com", "warren@hungry-media.com"]
11
11
  spec.summary = %q{Rails generators to facilitate development.}
12
12
  spec.description = %q{}
13
13
  spec.homepage = ""
@@ -19,30 +19,34 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.6"
22
- spec.add_dependency "rake"
23
- spec.add_dependency "rails"
24
22
 
25
- # [
26
- # 'ancestry',
23
+ [
24
+ 'kaminari',
25
+ 'mark_it_zero',
26
+ 'paper_trail',
27
+ 'pg_search',
28
+ 'pickadate-rails',
29
+ 'rails',
30
+ 'rake',
31
+ 'superslug',
32
+ # 'ancestry',
27
33
  # 'annotate', all models
28
34
  # 'backbone-on-rails', install:app
29
- # 'bones-rails',
35
+ # 'bones-rails',
30
36
  # 'bourbon', install:app
31
37
  # 'coffee-rails', install:app
32
38
  # 'devise', model:user
33
- # 'factory_girl_rails',
34
- # 'faker',
35
- # 'hirb',
36
- # 'jbuilder',
39
+ # 'factory_girl_rails',
40
+ # 'faker',
41
+ # 'hirb',
42
+ # 'jbuilder',
37
43
  # 'jquery-rails', install:app
38
44
  # 'jquery-fileupload-rails',
39
- # 'kaminari',
40
- # 'pickadate-rails',
41
45
  # 'sass-rails', install:app
42
- # 'simple_form',
46
+ # 'simple_form',
43
47
  # 'uglifier', install:app
44
48
  # 'unicorn-rails', install:app
45
49
  # 'wysihtml5-rails',
46
- # ].each { |g| spec.add_dependency g }
50
+ ].each { |g| spec.add_dependency g }
47
51
 
48
52
  end
data/config/routes.rb ADDED
@@ -0,0 +1,10 @@
1
+ Cambium::Engine.routes.draw do
2
+
3
+ namespace :admin do
4
+ get '/' => 'dashboard#index', :as => :root
5
+ get 'dashboard' => 'dashboard#show', :as => :dashboard
6
+ get 'search' => 'search#index', :as => :search
7
+ resources :users
8
+ end
9
+
10
+ end
@@ -0,0 +1,28 @@
1
+ module Cambium
2
+ class Configuration
3
+
4
+ attr_accessor \
5
+ :development_url,
6
+ :production_url,
7
+ :app_title,
8
+
9
+ def initialize
10
+ @development_url = 'localhost:3000'
11
+ @production_url = 'example.com'
12
+ @app_title = 'Cambium'
13
+ end
14
+
15
+ end
16
+
17
+ def self.configuration
18
+ @configuration ||= Configuration.new
19
+ end
20
+
21
+ def self.configuration=(config)
22
+ @configuration = config
23
+ end
24
+
25
+ def self.configure
26
+ yield configuration
27
+ end
28
+ end
@@ -1,6 +1,7 @@
1
1
  require 'rails'
2
2
 
3
3
  module Cambium
4
- class Engine < Rails::Engine
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace Cambium
5
6
  end
6
7
  end
@@ -1,3 +1,3 @@
1
1
  module Cambium
2
- VERSION = "0.3.0"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/cambium.rb CHANGED
@@ -1,4 +1,15 @@
1
- require "cambium/version"
1
+ # Cambium classes
2
+ require 'cambium/version'
3
+ require 'cambium/configuration'
4
+
5
+ # Gem to load by default (in case they are removed from
6
+ # Gemfile)
7
+ require 'kaminari'
8
+ require 'mark_it_zero'
9
+ require 'paper_trail'
10
+ require 'pg_search'
11
+ require 'pickadate-rails'
12
+ require 'superslug'
2
13
 
3
14
  module Cambium
4
15
  require 'cambium/engine' if defined?(Rails)