cmsimple 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. data/.gitignore +31 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +16 -0
  4. data/Gemfile +20 -0
  5. data/Gemfile.ci +5 -0
  6. data/LICENSE +19 -0
  7. data/README.md +118 -0
  8. data/Rakefile +47 -0
  9. data/app/assets/javascripts/cmsimple.js +61 -0
  10. data/app/assets/javascripts/cmsimple/controllers/editor.coffee +102 -0
  11. data/app/assets/javascripts/cmsimple/lib/namespaces.coffee +3 -0
  12. data/app/assets/javascripts/cmsimple/lib/support.coffee +4 -0
  13. data/app/assets/javascripts/cmsimple/mercury/config.js +462 -0
  14. data/app/assets/javascripts/cmsimple/mercury/handlers.coffee +9 -0
  15. data/app/assets/javascripts/cmsimple/models/image.coffee +49 -0
  16. data/app/assets/javascripts/cmsimple/models/page.coffee +106 -0
  17. data/app/assets/javascripts/cmsimple/models/path.coffee +31 -0
  18. data/app/assets/javascripts/cmsimple/models/version.coffee +29 -0
  19. data/app/assets/javascripts/cmsimple/panels/images/index.coffee +2 -0
  20. data/app/assets/javascripts/cmsimple/panels/images/list.coffee +48 -0
  21. data/app/assets/javascripts/cmsimple/panels/images/panel.coffee +69 -0
  22. data/app/assets/javascripts/cmsimple/panels/images/selection.coffee +52 -0
  23. data/app/assets/javascripts/cmsimple/panels/page_metadata.coffee +42 -0
  24. data/app/assets/javascripts/cmsimple/panels/publish.coffee +32 -0
  25. data/app/assets/javascripts/cmsimple/panels/redirects/form.coffee +51 -0
  26. data/app/assets/javascripts/cmsimple/panels/redirects/index.coffee +2 -0
  27. data/app/assets/javascripts/cmsimple/panels/redirects/list.coffee +34 -0
  28. data/app/assets/javascripts/cmsimple/panels/redirects/panel.coffee +39 -0
  29. data/app/assets/javascripts/cmsimple/panels/sitemap/index.coffee +2 -0
  30. data/app/assets/javascripts/cmsimple/panels/sitemap/panel.coffee +40 -0
  31. data/app/assets/javascripts/cmsimple/panels/sitemap/sortable.coffee +55 -0
  32. data/app/assets/javascripts/cmsimple/panels/sitemap/tree.coffee +61 -0
  33. data/app/assets/javascripts/cmsimple/panels/versions/index.coffee +2 -0
  34. data/app/assets/javascripts/cmsimple/panels/versions/list.coffee +51 -0
  35. data/app/assets/javascripts/cmsimple/panels/versions/panel.coffee +53 -0
  36. data/app/assets/javascripts/cmsimple/views/image_library/_item.jst.hamlc +24 -0
  37. data/app/assets/javascripts/cmsimple/views/image_library/list.jst.hamlc +8 -0
  38. data/app/assets/javascripts/cmsimple/views/redirects/_path.jst.hamlc +6 -0
  39. data/app/assets/javascripts/cmsimple/views/redirects/list.jst.hamlc +19 -0
  40. data/app/assets/javascripts/cmsimple/views/sitemap/_page.jst.hamlc +9 -0
  41. data/app/assets/javascripts/cmsimple/views/sitemap/tree.jst.hamlc +5 -0
  42. data/app/assets/javascripts/cmsimple/views/versions/_item.jst.hamlc +6 -0
  43. data/app/assets/javascripts/cmsimple/views/versions/list.jst.hamlc +4 -0
  44. data/app/assets/stylesheets/cmsimple.css +15 -0
  45. data/app/assets/stylesheets/cmsimple/forms.css +10 -0
  46. data/app/assets/stylesheets/cmsimple/panels.css +399 -0
  47. data/app/assets/stylesheets/cmsimple/toolbar-images.css +27 -0
  48. data/app/assets/stylesheets/mercury_overrides.css +2 -0
  49. data/app/controllers/cmsimple/front_controller.rb +38 -0
  50. data/app/controllers/cmsimple/images_controller.rb +28 -0
  51. data/app/controllers/cmsimple/mercury_controller.rb +7 -0
  52. data/app/controllers/cmsimple/pages_controller.rb +89 -0
  53. data/app/controllers/cmsimple/paths_controller.rb +23 -0
  54. data/app/controllers/cmsimple/snippets_controller.rb +23 -0
  55. data/app/controllers/cmsimple/versions_controller.rb +17 -0
  56. data/app/helpers/cmsimple/regions_helper.rb +38 -0
  57. data/app/models/cmsimple/image.rb +19 -0
  58. data/app/models/cmsimple/page.rb +203 -0
  59. data/app/models/cmsimple/path.rb +63 -0
  60. data/app/models/cmsimple/region.rb +43 -0
  61. data/app/models/cmsimple/snippet.rb +64 -0
  62. data/app/models/cmsimple/version.rb +18 -0
  63. data/app/uploaders/image_attachment_uploader.rb +53 -0
  64. data/app/views/cmsimple/images/_form.html.haml +13 -0
  65. data/app/views/cmsimple/images/new.html.haml +5 -0
  66. data/app/views/cmsimple/pages/_form.html.haml +49 -0
  67. data/app/views/cmsimple/pages/_form_extras.html.haml +2 -0
  68. data/app/views/cmsimple/pages/edit.html.haml +3 -0
  69. data/app/views/cmsimple/pages/new.html.haml +3 -0
  70. data/app/views/cmsimple/pages/publish.html.haml +12 -0
  71. data/app/views/cmsimple/snippets/index.html.haml +5 -0
  72. data/app/views/cmsimple/templates/default.html.haml +4 -0
  73. data/app/views/layouts/editor.html.haml +12 -0
  74. data/app/views/layouts/panel.html.haml +9 -0
  75. data/cmsimple.gemspec +44 -0
  76. data/config.ru +4 -0
  77. data/config/application.rb +1 -0
  78. data/config/cucumber.yml +8 -0
  79. data/config/environment.rb +2 -0
  80. data/config/routes.rb +34 -0
  81. data/db/migrate/20120201221410_create_cmsimple_pages.rb +10 -0
  82. data/db/migrate/20120222185901_add_title_parent_id_and_position_to_pages.rb +10 -0
  83. data/db/migrate/20120229185214_add_slug_to_pages.rb +7 -0
  84. data/db/migrate/20120323200439_add_is_root_to_page.rb +5 -0
  85. data/db/migrate/20120328174339_add_meta_info_to_cmsimple_pages.rb +9 -0
  86. data/db/migrate/20120329172857_create_cmsimple_path.rb +11 -0
  87. data/db/migrate/20120407024752_create_cmsimple_images.rb +13 -0
  88. data/db/migrate/20120410041105_add_timestamps_to_cmsimple_pages.rb +7 -0
  89. data/db/migrate/20120425211937_add_published_at_to_cmsimple_pages.rb +6 -0
  90. data/db/migrate/20120430175047_create_cmsimple_versions.rb +13 -0
  91. data/db/migrate/20120831233927_rename_path_to_current_uri_on_paths.rb +5 -0
  92. data/features/create.feature +18 -0
  93. data/features/delete.feature +12 -0
  94. data/features/edit.feature +54 -0
  95. data/features/publishing.feature +31 -0
  96. data/features/redirects.feature +27 -0
  97. data/features/step_definitions/mercury_steps.rb +440 -0
  98. data/features/step_definitions/page_steps.rb +269 -0
  99. data/features/step_definitions/web_steps.rb +254 -0
  100. data/features/support/env.rb +77 -0
  101. data/features/support/mercury_content.rb +25 -0
  102. data/features/support/mercury_selectors.rb +148 -0
  103. data/features/support/paths.rb +16 -0
  104. data/features/support/selectors.rb +26 -0
  105. data/features/support/utils.rb +18 -0
  106. data/features/versioning.feature +27 -0
  107. data/features/visit.feature +7 -0
  108. data/lib/cmsimple.rb +22 -0
  109. data/lib/cmsimple/configuration.rb +65 -0
  110. data/lib/cmsimple/exts/to_bool.rb +25 -0
  111. data/lib/cmsimple/page_responder.rb +46 -0
  112. data/lib/cmsimple/rails.rb +5 -0
  113. data/lib/cmsimple/regions_proxy.rb +32 -0
  114. data/lib/cmsimple/template_resolver.rb +14 -0
  115. data/lib/cmsimple/template_responder.rb +12 -0
  116. data/lib/cmsimple/version.rb +3 -0
  117. data/lib/generators/cmsimple/install/install_generator.rb +46 -0
  118. data/lib/generators/cmsimple/install/templates/default.html.erb +10 -0
  119. data/lib/generators/cmsimple/install/templates/default.html.haml +6 -0
  120. data/lib/generators/cmsimple/install/templates/initializer.rb +22 -0
  121. data/lib/generators/cmsimple/snippet/snippet_generator.rb +56 -0
  122. data/lib/generators/cmsimple/snippet/templates/cell.rb +18 -0
  123. data/lib/generators/cmsimple/snippet/templates/display.html.erb +14 -0
  124. data/lib/generators/cmsimple/snippet/templates/display.html.haml +11 -0
  125. data/lib/generators/cmsimple/snippet/templates/options.html.erb +18 -0
  126. data/lib/generators/cmsimple/snippet/templates/options.html.haml +12 -0
  127. data/script/app +2 -0
  128. data/script/migrate +2 -0
  129. data/script/rails +8 -0
  130. data/spec/fixtures/rails.png +0 -0
  131. data/spec/helpers/regions_helper_spec.rb +62 -0
  132. data/spec/javascripts/controllers/editor_spec.coffee +57 -0
  133. data/spec/javascripts/models/image_geometry_spec.coffee +64 -0
  134. data/spec/javascripts/models/image_spec.coffee +4 -0
  135. data/spec/javascripts/models/page_spec.coffee +121 -0
  136. data/spec/javascripts/models/path_spec.coffee +39 -0
  137. data/spec/javascripts/models/version_spec.coffee +31 -0
  138. data/spec/javascripts/panels/images/selection_spec.coffee +104 -0
  139. data/spec/javascripts/panels/sitemap/panel_spec.coffee +10 -0
  140. data/spec/javascripts/panels/sitemap/sortable_spec.coffee +63 -0
  141. data/spec/javascripts/panels/sitemap/tree_spec.coffee +62 -0
  142. data/spec/javascripts/spec_helper.coffee +25 -0
  143. data/spec/javascripts/support/stubs.coffee +16 -0
  144. data/spec/lib/page_responder_spec.rb +58 -0
  145. data/spec/lib/regions_proxy_spec.rb +47 -0
  146. data/spec/models/image_spec.rb +46 -0
  147. data/spec/models/page_spec.rb +237 -0
  148. data/spec/models/path_spec.rb +71 -0
  149. data/spec/models/region_spec.rb +14 -0
  150. data/spec/models/snippet_spec.rb +57 -0
  151. data/spec/models/version_spec.rb +7 -0
  152. data/spec/rails_app/.gitignore +33 -0
  153. data/spec/rails_app/Rakefile +7 -0
  154. data/spec/rails_app/app/assets/images/rails.png +0 -0
  155. data/spec/rails_app/app/assets/javascripts/application.js +9 -0
  156. data/spec/rails_app/app/assets/stylesheets/application.css +7 -0
  157. data/spec/rails_app/app/cells/example/display.html.haml +2 -0
  158. data/spec/rails_app/app/cells/example/options.html.haml +15 -0
  159. data/spec/rails_app/app/cells/example_cell.rb +19 -0
  160. data/spec/rails_app/app/cells/image_example/display.html.haml +4 -0
  161. data/spec/rails_app/app/cells/image_example/options.html.haml +15 -0
  162. data/spec/rails_app/app/cells/image_example_cell.rb +18 -0
  163. data/spec/rails_app/app/controllers/application_controller.rb +3 -0
  164. data/spec/rails_app/app/helpers/application_helper.rb +2 -0
  165. data/spec/rails_app/app/mailers/.gitkeep +0 -0
  166. data/spec/rails_app/app/models/.gitkeep +0 -0
  167. data/spec/rails_app/app/views/cmsimple/_snippet_list.html.haml +8 -0
  168. data/spec/rails_app/app/views/cmsimple/templates/default.html.haml +19 -0
  169. data/spec/rails_app/app/views/cmsimple/templates/test.html.haml +2 -0
  170. data/spec/rails_app/app/views/layouts/application.html.haml +13 -0
  171. data/spec/rails_app/config.ru +4 -0
  172. data/spec/rails_app/config/application.rb +65 -0
  173. data/spec/rails_app/config/boot.rb +9 -0
  174. data/spec/rails_app/config/database.example.yml +22 -0
  175. data/spec/rails_app/config/database.travis.yml +8 -0
  176. data/spec/rails_app/config/environment.rb +5 -0
  177. data/spec/rails_app/config/environments/development.rb +30 -0
  178. data/spec/rails_app/config/environments/test.rb +39 -0
  179. data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  180. data/spec/rails_app/config/initializers/cells.rb +1 -0
  181. data/spec/rails_app/config/initializers/cmsimple.rb +3 -0
  182. data/spec/rails_app/config/initializers/inflections.rb +10 -0
  183. data/spec/rails_app/config/initializers/mime_types.rb +5 -0
  184. data/spec/rails_app/config/initializers/secret_token.rb +7 -0
  185. data/spec/rails_app/config/initializers/session_store.rb +8 -0
  186. data/spec/rails_app/config/initializers/teabag.rb +58 -0
  187. data/spec/rails_app/config/initializers/wrap_parameters.rb +14 -0
  188. data/spec/rails_app/config/locales/en.yml +5 -0
  189. data/spec/rails_app/config/routes.rb +61 -0
  190. data/spec/rails_app/db/seeds.rb +11 -0
  191. data/spec/rails_app/lib/assets/.gitkeep +0 -0
  192. data/spec/rails_app/lib/tasks/.gitkeep +0 -0
  193. data/spec/rails_app/public/404.html +26 -0
  194. data/spec/rails_app/public/422.html +26 -0
  195. data/spec/rails_app/public/500.html +26 -0
  196. data/spec/rails_app/public/robots.txt +5 -0
  197. data/spec/rails_app/script/rails +6 -0
  198. data/spec/rails_app/vendor/assets/stylesheets/.gitkeep +0 -0
  199. data/spec/rails_app/vendor/plugins/.gitkeep +0 -0
  200. data/spec/spec_helper.rb +31 -0
  201. data/spec/support/active_model_lint_example.rb +14 -0
  202. data/spec/teabag_env.rb +28 -0
  203. data/vendor/assets/images/sitemap/has-changes.png +0 -0
  204. data/vendor/assets/images/sitemap/published.png +0 -0
  205. data/vendor/assets/images/sitemap/unpublished.png +0 -0
  206. data/vendor/assets/images/toolbar/metadata.png +0 -0
  207. data/vendor/assets/images/toolbar/publish.png +0 -0
  208. data/vendor/assets/images/toolbar/redirect.png +0 -0
  209. data/vendor/assets/images/toolbar/sitemap.png +0 -0
  210. data/vendor/assets/images/toolbar/snippets.png +0 -0
  211. data/vendor/assets/images/toolbar/unpublished.png +0 -0
  212. data/vendor/assets/images/tree-line-horizontal-last.png +0 -0
  213. data/vendor/assets/images/tree-line-horizontal.png +0 -0
  214. data/vendor/assets/images/tree-line-vertical.png +0 -0
  215. data/vendor/assets/javascripts/jquery-serializeObject.js +107 -0
  216. data/vendor/assets/javascripts/jquery.to-json.js +74 -0
  217. data/vendor/assets/javascripts/jquery.ui.nestedSortable-1.3.4.js +391 -0
  218. data/vendor/assets/javascripts/moment-1.6.2.js +918 -0
  219. data/vendor/assets/javascripts/underscore-1.3.1.js +31 -0
  220. data/vendor/assets/stylesheets/jasmine-modified.css +216 -0
  221. metadata +686 -0
@@ -0,0 +1,46 @@
1
+ module Cmsimple
2
+ class PageResponder
3
+ def initialize(controller)
4
+ @controller = controller
5
+ @request = @controller.request
6
+ @params = @request.params
7
+ @page = @controller.current_page
8
+ end
9
+
10
+ def respond
11
+ @controller.respond_with page_for_context
12
+ end
13
+
14
+ def page_for_context
15
+ raise ActiveRecord::RecordNotFound unless current_page_is_viewable?
16
+
17
+ return published_context? ||
18
+ version_context? ||
19
+ draft_context?
20
+ end
21
+
22
+ def published_context?
23
+ unless is_currently_editable?
24
+ return @page if @page.as_published!
25
+ end
26
+ end
27
+
28
+ def version_context?
29
+ if @params[:version].present?
30
+ return @page if @page.at_version!(@params[:version])
31
+ end
32
+ end
33
+
34
+ def draft_context?
35
+ @page
36
+ end
37
+
38
+ def current_page_is_viewable?
39
+ is_currently_editable? || @page.published?
40
+ end
41
+
42
+ def is_currently_editable?
43
+ @controller.in_editor_iframe?
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,5 @@
1
+ module Cmsimple
2
+ class Engine < Rails::Engine
3
+ isolate_namespace Cmsimple
4
+ end
5
+ end
@@ -0,0 +1,32 @@
1
+ module Cmsimple
2
+ class RegionsProxy
3
+ attr_accessor :regions_hash
4
+
5
+ def initialize(regions_hash)
6
+ if regions_hash.is_a?(Hash)
7
+ @regions_hash = ActiveSupport::HashWithIndifferentAccess.new(regions_hash.dup)
8
+ define_regions
9
+ end
10
+ end
11
+
12
+ def snippets_hash
13
+ return {} unless @regions_hash.present?
14
+ @regions_hash.inject(ActiveSupport::HashWithIndifferentAccess.new){|h, (k,v)| h.merge(v[:snippets].presence || {})}
15
+ end
16
+
17
+ def define_regions
18
+ mod = Module.new
19
+ extend mod
20
+
21
+ region_methods = @regions_hash.collect do |key, value|
22
+ %{def #{key}() Cmsimple::Region.new(@regions_hash[:#{key}]); end}
23
+ end
24
+
25
+ mod.module_eval region_methods.join("\n"), __FILE__, __LINE__ + 1
26
+ end
27
+
28
+ def method_missing method, *args, &block
29
+ Region.new {}
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,14 @@
1
+ module Cmsimple
2
+ class TemplateResolver
3
+ def self.all
4
+ templates = []
5
+ ActionController::Base.view_paths.each do |path|
6
+ template_directory = File.join(path, Cmsimple.configuration.template_path)
7
+ Dir[File.join(template_directory, "*.*")].each do |file|
8
+ templates << File.basename(file).split('.').first
9
+ end
10
+ end
11
+ templates.uniq
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ module Cmsimple
2
+ class TemplateResponder < ActionController::Responder
3
+ def default_render
4
+ if controller.action_name == 'show'
5
+ template = File.join Cmsimple.configuration.template_path, (@resource.template.presence || 'default')
6
+ controller.render template, @resource.template_render_options
7
+ else
8
+ super
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module Cmsimple
2
+ VERSION = "0.2.0"
3
+ end
@@ -0,0 +1,46 @@
1
+ require 'rails/generators'
2
+
3
+ class Cmsimple::InstallGenerator < Rails::Generators::Base
4
+ class_option :template_engine
5
+ class_option :test_framework
6
+ source_root File.expand_path("../templates", __FILE__)
7
+
8
+ def create_initializer
9
+ template 'initializer.rb', 'config/initializers/cmsimple.rb'
10
+ end
11
+
12
+ def add_routes
13
+ route %Q{#this route should always be last
14
+ mount Cmsimple::Engine => '/'}
15
+ end
16
+
17
+ def create_default_template
18
+ file = "default.html.#{handler}"
19
+ template file, "app/views/cmsimple/templates/#{file}"
20
+ end
21
+
22
+ def create_snippets_list
23
+ create_file "app/views/cmsimple/_snippet_list.html.#{handler}", "Run the snippet generator to add a snippet"
24
+ end
25
+
26
+ def add_to_seeds_file
27
+ seed = <<-SEED
28
+ unless Cmsimple::Page.where(is_root: true).first
29
+ page = Cmsimple::Page.create is_root: true, title: 'Home', template: 'default'
30
+ page.publish!
31
+ end
32
+ SEED
33
+ append_to_file 'db/seeds.rb', seed
34
+ end
35
+
36
+ def install_migrations
37
+ rake('cmsimple:install:migrations')
38
+ rake('db:migrate')
39
+ rake('db:seed')
40
+ end
41
+
42
+ private
43
+ def handler
44
+ options[:template_engine]
45
+ end
46
+ end
@@ -0,0 +1,10 @@
1
+ <h2 id='header' data-mercury='simple'>
2
+ <%= render_region :header do -%>
3
+ Header
4
+ <% end -%>
5
+ </h2>
6
+ <section id='content' class="container">
7
+ <%= render_region :content, tag: :article do %>
8
+ Add content here
9
+ <% end %>
10
+ </section>
@@ -0,0 +1,6 @@
1
+ %h2#header(data-mercury='simple')><
2
+ = render_region :header do
3
+ Header
4
+ %section#content.container
5
+ = render_region :content, tag: :article do
6
+ Add content here
@@ -0,0 +1,22 @@
1
+ Cmsimple.configure do |cmsimple|
2
+ #the parent controller for all the page CRUD activities
3
+ # cmsimple.parent_controller = 'ApplicationController'
4
+
5
+ # the parent controller for the page rendering
6
+ # cmsimple.parent_front_controller = 'ApplicationController'
7
+
8
+ # the path the templates are loaded from
9
+ # cmsimple.template_path = 'cmsimple/templates'
10
+
11
+ # the path carrierwave will use to store image assets
12
+ # self.asset_path = 'uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}'
13
+
14
+ # stylesheets to be included in the editor layout page
15
+ # self.editor_stylesheets << 'cmsimple_overrides'
16
+
17
+ # javascripts to be included in the editor layout page
18
+ # self.editor_javascripts << 'cmsimple_overrides'
19
+
20
+ # set this to change layouts or pass other params into rendering a template
21
+ # self.template_render_options = {}
22
+ end
@@ -0,0 +1,56 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/named_base'
3
+
4
+ class Cmsimple::SnippetGenerator < Rails::Generators::NamedBase
5
+ class_option :template_engine
6
+ class_option :test_framework
7
+ class_option :base_snippet_class, :type => :string, :default => "Cell::Rails"
8
+ argument :fields, :type => :array, :default => [:name], :banner => "field field"
9
+ source_root File.expand_path("../templates", __FILE__)
10
+
11
+ def create_cell_file
12
+ template 'cell.rb', "#{base_path}_cell.rb"
13
+ end
14
+
15
+ def create_view_files
16
+ file = "display.html.#{handler}"
17
+ @path = File.join(base_path, file)
18
+ template file, @path
19
+
20
+ @fields = fields
21
+ file = "options.html.#{handler}"
22
+ @path = File.join(base_path, file)
23
+ template file, @path
24
+ end
25
+
26
+ # this is gross need to write something that acts like template but just returns the result
27
+ def add_to_snippet_list
28
+ html = ''
29
+ if handler.to_sym == :haml
30
+ html = <<-HTML
31
+ %li(data-filter="#{class_name.underscore}, snippet, name")
32
+ %img(alt="#{class_name.humanize} Snippet" data-snippet="#{class_name.underscore}" src="/assets/toolbar/snippets.png")
33
+ %h4>#{class_name.humanize}
34
+ .description A one or two line long description of what this snippet does.
35
+ HTML
36
+ elsif handler.to_sym == :erb
37
+ html = <<-HTML
38
+ <li data-filter="#{class_name.underscore}, snippet, name">
39
+ <img alt="#{class_name.humanize} Snippet" data-snippet="#{class_name.underscore}" src="/assets/toolbar/snippets.png">
40
+ <h4>#{class_name.humanize}</h4>
41
+ <div class="description"> A one or two line long description of what this snippet does.</div>
42
+ </li>
43
+ HTML
44
+ end
45
+ append_to_file "app/views/cmsimple/_snippet_list.html.#{handler}", html
46
+ end
47
+
48
+ private
49
+ def base_path
50
+ File.join('app/cells', class_path, file_name)
51
+ end
52
+
53
+ def handler
54
+ options[:template_engine]
55
+ end
56
+ end
@@ -0,0 +1,18 @@
1
+ class <%= class_name %>Cell < <%= options.base_snippet_class %>
2
+
3
+ def display(snippet)
4
+ <%- @fields.each do |field| -%>
5
+ @<%= field %> = snippet.<%= field %>
6
+ <%- end -%>
7
+ render view: :display
8
+ end
9
+
10
+ def preview(snippet)
11
+ display(snippet)
12
+ end
13
+
14
+ def options(snippet)
15
+ @snippet = snippet
16
+ render
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ <h1>
2
+ <%= class_name %>#display
3
+ </h1>
4
+ <p>
5
+ Find me in <%= @path %>
6
+ </p>
7
+
8
+ <%- @fields.each do |field| -%>
9
+ <p>
10
+ <%= field %>
11
+ <br/>
12
+ <%%= @<%= field %> %>
13
+ </p>
14
+ <%- end -%>
@@ -0,0 +1,11 @@
1
+ %h1
2
+ <%= class_name %>#display
3
+ %p
4
+ Find me in <%= @path %>
5
+
6
+ <%- @fields.each do |field| -%>
7
+ %p
8
+ <%= field.humanize %>
9
+ %br
10
+ = @<%= field %>
11
+ <%- end -%>
@@ -0,0 +1,18 @@
1
+ <div class="mercury-display-pane" style='width: 500px'>
2
+ <%%= form_for @snippet, :url => '#', html: { class: 'form-horizontal' } do |f| %>
3
+ <fieldset>
4
+ <legend><%= class_name %> Snippet</legend>
5
+ <%- @fields.each do |field| -%>
6
+ <div class="control-group">
7
+ <%%= f.label :<%= field %>, class: 'control-label' %>
8
+ <div class="controls">
9
+ <%%= f.input :<%= field %> %>
10
+ </div>
11
+ </div>
12
+ <%- end -%>
13
+ </fieldset>
14
+ <div class="form-actions mercury-display-controls">
15
+ <%%= f.submit class: 'btn btn=primary' %>
16
+ </div>
17
+ <%% end %>
18
+ </div>
@@ -0,0 +1,12 @@
1
+ .mercury-display-pane(style='width: 500px')
2
+ = form_for @snippet, :url => '#', html: { class: 'form-horizontal'} do |f|
3
+ %fieldset
4
+ %legend <%= class_name %> Snippet
5
+ <%- @fields.each do |field| -%>
6
+ .control-group
7
+ = f.label :<%= field %>, class: 'control-label'
8
+ .controls
9
+ = f.text_field :<%= field %>
10
+ <%- end -%>
11
+ .form-actions.mercury-display-controls
12
+ = f.submit class: 'btn btn-primary'
@@ -0,0 +1,2 @@
1
+ #!/bin/bash
2
+ cd spec/rails_app && $@
@@ -0,0 +1,2 @@
1
+ #!/bin/bash
2
+ cd spec/rails_app && rake cmsimple:install:migrations && rake db:migrate && rake db:test:prepare
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
+ ENGINE_PATH = File.expand_path('../../lib/cmsimple/rails', __FILE__)
6
+
7
+ require 'rails/all'
8
+ require 'rails/engine/commands'
Binary file
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+ require 'cell/test_case'
3
+ describe Cmsimple::RegionsHelper do
4
+ include Cell::TestCase::TestMethods
5
+
6
+ it 'returns the value of the region' do
7
+ region_content(Cmsimple::Region.new value: '<h1>blah</h1>').should == '<h1>blah</h1>'
8
+ end
9
+
10
+ describe 'rendering a region' do
11
+ before do
12
+ @region = Cmsimple::Region.new(value: "<div>some content</div><div>[snippet_0/0]</div>",
13
+ snippets: {snippet_0: {name: 'example',
14
+ options: { first_name: 'Fred',
15
+ last_name: 'Flinstone'
16
+ }}})
17
+ @page = mock('page', :regions => mock('regions', :body => @region, :heading => Cmsimple::Region.new({})))
18
+ end
19
+
20
+ it 'renders without a wrapper tag if no tag provided' do
21
+ content = render_region(:body)
22
+ content.should have_selector('h1', content: 'Fred Flinstone')
23
+ end
24
+
25
+ it 'renders block if region has no content' do
26
+ content = render_region(:heading) do
27
+ 'blah'
28
+ end
29
+ content.should == 'blah'
30
+ end
31
+
32
+ it 'renders the region with a wrapper if a tag is specified' do
33
+ content = render_region(:body, tag: :section)
34
+ content.should have_selector('h1', content: 'Fred Flinstone')
35
+ content.should have_selector("section[data-mercury='full']")
36
+ content.should have_selector('section#body')
37
+ end
38
+
39
+ it 'renders the region with a wrapper and set class and region type from options' do
40
+ content = render_region(:body, tag: :section, html: {class: 'blah'}, region_type: 'snippets')
41
+ content.should have_selector('h1', content: 'Fred Flinstone')
42
+ content.should have_selector('section.blah')
43
+ content.should have_selector("section[data-mercury='snippets']")
44
+ content.should have_selector('section#body')
45
+ end
46
+ end
47
+
48
+ describe 'snippets' do
49
+ before do
50
+ @region = Cmsimple::Region.new(value: "<div>some content</div><div>[snippet_0/0]</div>",
51
+ snippets: {snippet_0: {name: 'example',
52
+ options: { first_name: 'Fred',
53
+ last_name: 'Flinstone'
54
+ }}})
55
+ end
56
+
57
+ it 'renders the snippets when present' do
58
+ rendered_region = region_content(@region)
59
+ rendered_region.should have_selector('h1', content: 'Fred Flinstone')
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,57 @@
1
+ #= require cmsimple
2
+
3
+ describe 'CMSimple.Editor', ->
4
+ beforeEach ->
5
+ @page = new CMSimple.Page slug: 'about'
6
+ spyOn(CMSimple.Editor::, 'initializeMercury')
7
+ @editor = new CMSimple.Editor @page
8
+ @editor.mercury =
9
+ iframe:
10
+ data: (->)
11
+ loadIframeSrc: ((path)-> @path = path)
12
+
13
+ describe 'initialization', ->
14
+
15
+ it 'calls loadMercury', ->
16
+ expect(CMSimple.Editor::initializeMercury).toHaveBeenCalled()
17
+
18
+ it 'sets CMSimple.Editor.current_page to the page passed to the constructor', ->
19
+ expect(CMSimple.Editor.current_page).toEqual(@page)
20
+ expect(@editor.current_page).toEqual(@page)
21
+
22
+ describe 'reloading with page changes', ->
23
+
24
+ it 'returns true when the path argument does not match the window.location', ->
25
+ spyOn(String::, 'match').andCallFake(-> ['http://cmsimple.dev/editor/about_us', '/editor/about_us'])
26
+ expect(@editor.pathChange('/editor/contact_us')).toEqual(true)
27
+
28
+ it 'calls navigate if the path does not match the current page path on a reload call', ->
29
+ spyOn(String::, 'match').andCallFake(-> ['http://cmsimple.dev/editor/about_us', '/editor/about_us'])
30
+ spyOn(@editor, 'navigate')
31
+ @editor.reload()
32
+ expect(@editor.navigate).toHaveBeenCalled()
33
+
34
+ it 'calls loadPath if the path does match the current page path on a reload call', ->
35
+ spyOn(String::, 'match').andCallFake(-> ['http://cmsimple.dev/editor/about', '/editor/about'])
36
+ spyOn(@editor, 'loadPath')
37
+ @editor.reload()
38
+ expect(@editor.loadPath).toHaveBeenCalled()
39
+
40
+ describe 'loading a new page', ->
41
+ beforeEach ->
42
+ @otherPage = new CMSimple.Page slug: 'contact'
43
+ @otherPage.save ajax: false
44
+ spyOn(Mercury.Snippet, 'clearAll').andCallThrough()
45
+ spyOn(Mercury.Snippet, 'load')
46
+ @editor.loadNewPageFromPath('/contact')
47
+
48
+ it 'sets the current page to the page with the matching path', ->
49
+ expect(@editor.current_page).toEqual(@otherPage)
50
+
51
+ it 'reloads the snippets', ->
52
+ expect(Mercury.Snippet.clearAll).toHaveBeenCalled()
53
+ expect(Mercury.Snippet.load).toHaveBeenCalled()
54
+
55
+ it 'loads the new path in mercury', ->
56
+ expect(@editor.mercury.path).toEqual(@otherPage.path())
57
+