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,31 @@
1
+ .DS_Store
2
+ .bundle
3
+ .idea
4
+ .rake_tasks
5
+ .rvmrc
6
+ .powenv
7
+ REVISION
8
+ vendor/bundle
9
+ .rake_tasks~
10
+ mkmf.log
11
+
12
+ # Local config files
13
+ database.yml
14
+ schema.rb
15
+
16
+ # Logs
17
+ log
18
+ log/*.log
19
+ log/*.pid
20
+
21
+ # Tempfiles
22
+ tmp/**/*
23
+ tmp/
24
+ coverage
25
+ capybara*
26
+
27
+ # test app
28
+ spec/rails_app/db/migrate/**.cmsimple.rb
29
+ spec/rails_app/public/uploads/
30
+
31
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,16 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+ gemfile: Gemfile.ci
5
+ before_script:
6
+ - mysql -e 'create database cmsimple_test;'
7
+ - 'cp spec/rails_app/config/database.travis.yml spec/rails_app/config/database.yml'
8
+ - bundle exec rake db:migrate
9
+ - 'sh -e /etc/init.d/xvfb start'
10
+ env:
11
+ - DISPLAY=':99.0' CUCUMBER_OPTS='-f progress' CI_WAIT_TIME=10
12
+ script: bundle exec rake --trace
13
+ notifications:
14
+ email:
15
+ - cmsimple@modeset.com
16
+
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source :rubygems
2
+
3
+ gem 'mysql2'
4
+ gem 'jquery-rails'
5
+
6
+ gem 'multi_json', '>= 1.3.4'
7
+
8
+ # gem 'mercury-rails', :path => '~/work/libraries/ruby/gems/mercury'
9
+ gem 'mercury-rails', git: 'git://github.com/jejacks0n/mercury.git', ref: '227df218e4f28d797ecf42da73452b8073a672b7'
10
+
11
+ # Gems used only for assets and not required
12
+ # in production environments by default.
13
+ group :assets do
14
+ gem 'sass-rails'
15
+ gem 'coffee-rails'
16
+ gem 'uglifier'
17
+ end
18
+
19
+ # Specify your gem's dependencies in ..gemspec
20
+ gemspec
@@ -0,0 +1,5 @@
1
+ eval File.read(File.join(File.dirname(__FILE__), 'Gemfile'))
2
+
3
+ group :test do
4
+ gem "phantomjs-linux"
5
+ end
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2013 Mode Set, LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1,118 @@
1
+ # CMSimple
2
+
3
+ [![Build Status](https://secure.travis-ci.org/modeset/cmsimple.png?branch=master)](http://travis-ci.org/modeset/cmsimple)
4
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/modeset/cmsimple)
5
+
6
+ CMSimple is an easy-to-use but extensible CMS wrapped around the Mercury editor (https://github.com/jejacks0n/mercury), written as a Rails engine.
7
+
8
+ ## Getting Started
9
+
10
+ Add the gem to your Gemfile
11
+
12
+ ```ruby
13
+ gem 'cmsimple', github: 'modeset/cmsimple'
14
+ ```
15
+
16
+ Run the install generator
17
+
18
+ ```shell
19
+ rails g cmsimple:install
20
+ ```
21
+
22
+ ## Templates
23
+
24
+ CMSimple templates are just views. They get rendered from the Cmsimple::FrontController inside the CMSimple engine. The core of a view is the render_region helper which indicates where in the dom a region is rendered and which region to render. There are two ways to invoke the region. The first is by just telling it what region you want to render. With this method you still have to tell Mercury how to find and associate the region. Below is an example:
25
+
26
+ ```erb
27
+ <h1 id='page_title' class="page-heading" data-mercury='full'>
28
+ <%= render_region :page_title do %>
29
+ Placeholder
30
+ <% end %>
31
+ </h1>
32
+ ```
33
+
34
+ Above we are using an h1 as the region container for our content. And we are telling Mercury to use a "full" region. Please note that the id of the element must match the region name passed into the helper in this use case as the id is how Mercury references regions.
35
+
36
+ You can also tell the helper to render the container by providing the tag: :element argument in the options hash. The options hash also takes the region type (:full, :snippets, :simple are supported) and an html option which gets handed to the content_tag helper so you can provide options for building out the content_tag container.
37
+
38
+ ```erb
39
+ <%= render_region :aside_navigation, region_type: :snippets, tag: :div, html: {class: 'aside'} do %>
40
+ <% end %>
41
+ ```
42
+
43
+ ### Notes
44
+
45
+ There are a couple of things to keep in mind as you maintain and augment templates. The first is that you should try to keep regions consistently named. If a user changes the template that they want to use if the regions are not named the same the content will not display in the new template. Of course this isn't always possible, for example the home page template is very different from any of the content templates.
46
+
47
+ Another item to note about this behavior is that if a user switches a template in draft mode and saves the content, if they attempt to revert back to the previous template they may permanently loose content in regions where the names are not available between templates. This is not the case if a user has published a page as they can then just revert to a previous version of the page to regain the content.
48
+
49
+ Regions must always be contained by block level elements (i.e. the tag: :div declaration). This is actually a limitation of the browser. A specifically onerous element is the &lt;p&gt; tag. Since the W3C spec indicates that no block level elements can be children of the &lt;p&gt; tag, the browser will attempt to correct the content by moving it outside the tag. This results in a lot of confusion and strange looking rendered content.
50
+
51
+ ## Snippets
52
+
53
+ [Cells](https://github.com/apotonick/cells) are how CMSimple implement Mercury's idea of snippets. Snippets are meant to be a way for authors to be able to utilize content that requires more complicated html to render. In general authors don't want to learn html, but often a design for a template can require a very specific html markup with associated classes in order for the css to be able to layout the page properly. Snippets provide this framework.
54
+
55
+ Snippets have 3 required parts in order to provide basic functionality, the *_cell.rb Cell class (which is essentially like a mini controller), the display view and the options view
56
+
57
+ * The cell class has three "actions", or states as cells calls them, display, preview, and options. Display is used to render the snippet into the template. Preview is used when a new snippet is added to a region via Mercury. It makes an ajax request for the preview so that the author can see the snippet in real time. 99% of the time preview just calls through to display. Options is where we create the form where the author will provide the content for a snippet.
58
+
59
+ * The display view is just a normal rails view where you render your snippet. The best practice is to map all of the snippet options as instance variables in your action so that the view doesn't need to refer to a snippet. This allows easy updating and keeps the views simple.
60
+
61
+ * The options view is where you create your form for telling Mercury what options are to be persisted for a given snippet. It is important to note that Mercury will only save options that exist in the form (more on this later). We are currently using Formtastic to create all the forms in this project.
62
+
63
+ ### Snippet options
64
+
65
+ Snippet options are the most complex part of a snippet. This stems from trying to understand how Mercury serializes snippets and how they get re-rendered. Essentially Mercury can only persist what is in an options form. This means that _any_ data that needs to be captured and maintained throughout a snippets life must have an input in the form.
66
+
67
+ * Changing the wrapper element of a snippet
68
+
69
+ In order to change the wrapper tag (it defaults to a div) you need to provide a hidden input into the options form called "wrapperTag".
70
+
71
+ ```erb
72
+ <%= hidden_field_tag :wrapperTag, 'li' %>
73
+ ```
74
+ The above sets the wrapper tag to be an li instead of a div.
75
+
76
+ ### Images in snippets
77
+
78
+ CMSimple has an image library where you can manage all of your images and then insert them into a region. From an authors standpoint setting an image in a snippet is no different. However on the development side it is not as clear cut. The reasoning for this is that CMSimple has to know which images are editable in a snippet and which are not. This is determined by a data attribute data-snippet-image. This attribute contains the name of the snippet option where the url to the image will be stored. Normally this is just "image" (see the content highlight snippet for an example). In a simple case this is all that is required to configure CMSimple to be able to update an image in a snippet. See the example
79
+ code below.
80
+
81
+ ```erb
82
+ <img data-snippet-image="image" data-image-geometry="<150x<80" src="<%= @image.presence || 'http://placehold.it/60x80/' %>" alt="alt" />
83
+ ```
84
+
85
+ The code above obviously does a bit more than set the image reference. This is two fold, first we want to provide the author a placeholder image that is an appropriate size so they know which image to replace (the img tag has to exist for this all to work). We accomplish this by checking if the image option has been set and if not we just a place holder image. The second attribute you see is the data-image-geometry attribute. This is used to automatically filter the image library by images that are of "recommended" size. We don't ever restrict an author from using an image we just suggest what was originally intended.
86
+
87
+ ### Creating snippets
88
+
89
+ Beyond the items mentioned above the only other requirement for creating snippets is telling Mercury that they exist. This happens via the app/views/cmsimple/_snippet_list.html.erb partial. You need to add a new li with an img that has a data attribute data-snippet="name_of_snippet" the attribute name has to match the name of the cell. I can hear you saying "that sounds like a lot to remember". Well that is why there is a generator for creating snippets.
90
+
91
+ ```shell
92
+ rails g cmsimple:snippet snippet_name field1 field2
93
+ ```
94
+
95
+ Field1 and field2 are the options you want the author to be able to enter data for. The generator will create the cell and the display and options view as well as add itself to the snippet_list partial.
96
+
97
+
98
+ ## Contributing
99
+
100
+ To run the test suite for CMSimple, you will need to do the following:
101
+
102
+ 1. Setup the DB for testing
103
+ 1. Configure a `database.yml` in the demo rails app6 (see spec/rails_app/config/database.example.yml)
104
+ 2. Run setup tasks: `rake app:db:setup` and `rake app:db:test:prepare`
105
+ 2. Run specs
106
+ 1. `rake spec`
107
+ 2. Wait.
108
+
109
+
110
+ ## License
111
+
112
+ Licensed under the [MIT License](http://creativecommons.org/licenses/MIT/)
113
+
114
+ Copyright 2012 [Mode Set](https://github.com/modeset)
115
+
116
+
117
+ ## Make Code Not War
118
+ ![crest](https://secure.gravatar.com/avatar/aa8ea677b07f626479fd280049b0e19f?s=75)
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'CMSimple'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/rails_app/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ # Rspec
29
+ require 'rspec/core/rake_task'
30
+
31
+ # Teabag
32
+ desc "Run the javascript specs"
33
+ task :teabag => "app:teabag"
34
+
35
+ # Cucumber
36
+ require 'cucumber/rake/task'
37
+
38
+ Cucumber::Rake::Task.new(:cucumber) do |t|
39
+ # t.cucumber_opts = "features --format pretty"
40
+ end
41
+ RSpec::Core::RakeTask.new(:spec) do |t|
42
+ t.pattern = "./spec/**/*_spec.rb"
43
+ end
44
+
45
+ # Default should run all three
46
+ task :default => [:spec, :teabag, :cucumber]
47
+
@@ -0,0 +1,61 @@
1
+ /* CMSimple / Mercury manifest
2
+ *
3
+ * Vendor dependencies
4
+ *
5
+ * Minimum jQuery requirements are 1.7
6
+ *= require jquery-1.7
7
+ *= require jquery_ujs
8
+ *
9
+ *= require jquery.to-json
10
+ *
11
+ * Underscore.js
12
+ *= require underscore-1.3.1
13
+ *
14
+ * Moment.js
15
+ *= require moment-1.6.2
16
+ *
17
+ * Spine.js (spine-rails)
18
+ *= require spine
19
+ *= require spine/ajax
20
+ *= require spine/relation
21
+ *= require spine/route
22
+ *
23
+ * Haml Coffee Templates
24
+ *= require hamlcoffee
25
+ *
26
+ * Mercury specifics
27
+ *
28
+ * Add all requires for the support libraries that integrate nicely with Mercury Editor.
29
+ * require mercury/support/history
30
+ *
31
+ * Mercury configuration
32
+ *= require cmsimple/mercury/config
33
+ *
34
+ * Require Mercury Editor itself.
35
+ *= require mercury/mercury
36
+ *
37
+ *= require jquery.ui.nestedSortable-1.3.4
38
+ *= require jquery-serializeObject
39
+ *
40
+ * Require any localizations you wish to support
41
+ * Example: es.locale, or fr.locale -- regional dialects are in each language file so never en_US for instance.
42
+ * require mercury/locales/swedish_chef.locale
43
+ *
44
+ * Custom Mercury handlers for CMSimple
45
+ *= require cmsimple/mercury/handlers
46
+ *
47
+ * CMSimple Editor
48
+ *
49
+ *= require cmsimple/lib/namespaces
50
+ *= require cmsimple/lib/support
51
+ *
52
+ *= require cmsimple/panels/page_metadata
53
+ *= require cmsimple/panels/publish
54
+ *= require cmsimple/panels/sitemap
55
+ *= require cmsimple/panels/redirects
56
+ *= require cmsimple/panels/images
57
+ *= require cmsimple/panels/versions
58
+ *
59
+ *= require cmsimple/controllers/editor
60
+ *
61
+ */
@@ -0,0 +1,102 @@
1
+ #= require cmsimple/models/page
2
+
3
+ class CMSimple.Editor extends Spine.Controller
4
+ el: 'body'
5
+ constructor: (page)->
6
+ super()
7
+ @setCurrentPage(page)
8
+ @initializeMercury()
9
+
10
+ @routes
11
+ '/editor/*path': (params)=>
12
+ path = "/#{params.match[1]}"
13
+ @routeToPath(path)
14
+ '/editor': (params)=>
15
+ @routeToPath('/')
16
+
17
+ @bind 'pathLoaded', @proxy @ensureProperState
18
+ @bind 'pathLoaded', =>
19
+ @checkPublishedState()
20
+
21
+ CMSimple.Page.bind 'refresh', @proxy @checkPublishedState
22
+
23
+ @initialLoad ->
24
+ Spine.Route.setup(history: true)
25
+
26
+ initialLoad: (callback)->
27
+ @initializing = true
28
+ callback.call()
29
+ @initializing = false
30
+
31
+ routeToPath: (path)->
32
+ if @current_page and @current_page.path() is path
33
+ @loadPath(path)
34
+ else
35
+ @loadNewPageFromPath(path)
36
+
37
+ setCurrentPage: (page)->
38
+ return unless page
39
+ @current_page.unbind() if @current_page
40
+ @current_page = page
41
+ CMSimple.Editor.current_page = @current_page
42
+ @current_page.save(ajax: false) if @current_page.isNew()
43
+ @current_page.bind 'reload', @proxy @reload
44
+ @current_page.bind 'version', @proxy @viewVersion
45
+
46
+ loadNewPageFromPath: (path)->
47
+ @setCurrentPage(CMSimple.Page.forPath(path))
48
+ @loadCurrentSnippets()
49
+ @loadPath(path)
50
+
51
+ initializeMercury: ->
52
+ @mercury = new Mercury.PageEditor(null, saveStyle: 'json')
53
+
54
+ Mercury.on 'saved', =>
55
+ CMSimple.Page.fetch(id: @current_page.id)
56
+ Mercury.one 'ready', =>
57
+ @checkPublishedState()
58
+
59
+ @loadCurrentSnippets()
60
+
61
+ loadCurrentSnippets: ->
62
+ Mercury.Snippet.clearAll()
63
+ Mercury.Snippet.load(@current_page.snippets())
64
+
65
+ reload: ->
66
+ if @pathChange(@current_page.editPath())
67
+ @navigate @current_page.editPath()
68
+ else
69
+ @loadPath @current_page.path()
70
+
71
+ viewVersion: (page, version)->
72
+ @navigate "#{page.editPath()}?version=#{version}"
73
+
74
+ loadPath: (path)->
75
+ return unless path
76
+ if @initializing
77
+ #spine doesn't proxy the queryparams through when loading so we have to grab it ourselves
78
+ queryParams = window.location.search.replace('?', '')
79
+ else
80
+ [path, queryParams] = path.split('?')
81
+ @mercury.loadIframeSrc _([path, queryParams]).compact().join('?')
82
+ @trigger 'pathLoaded', path, queryParams
83
+
84
+ pathChange: (path)->
85
+ matches = window.location.href.match(/[http|https]:\/\/.[^\/]*(\/editor\/?.*)/)
86
+ currentPath = matches[1]
87
+ currentPath isnt path
88
+
89
+ ensureProperState: (path, queryParams)->
90
+ if queryParams?.match(/version=/)
91
+ $('.mercury-button').not('.mercury-historyPanel-button').addClass('disabled')
92
+ Mercury.one 'ready', -> Mercury.trigger('focus:window')
93
+ else
94
+ $('.mercury-button').not('.mercury-historyPanel-button').removeClass('disabled')
95
+
96
+ checkPublishedState: (record)->
97
+ publishButton = $('.mercury-publish-button')
98
+ if @current_page.reinflate().unpublished_changes
99
+ publishButton.addClass('unpublished')
100
+ else
101
+ publishButton.removeClass('unpublished')
102
+
@@ -0,0 +1,3 @@
1
+ window.CMSimple ?= {}
2
+ CMSimple.Panels ?= {}
3
+
@@ -0,0 +1,4 @@
1
+
2
+ $.ajaxSetup
3
+ cache: false
4
+
@@ -0,0 +1,462 @@
1
+ /*!
2
+ * Mercury Editor is a CoffeeScript and jQuery based WYSIWYG editor. Documentation and other useful information can be
3
+ * found at https://github.com/jejacks0n/mercury
4
+ *
5
+ * Supported browsers:
6
+ * - Firefox 4+
7
+ * - Chrome 10+
8
+ * - Safari 5+
9
+ *
10
+ * Copyright (c) 2011 Jeremy Jackson
11
+ *
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
14
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
15
+ * persons to whom the Software is furnished to do so, subject to the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
18
+ * Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
21
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
22
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ */
26
+ window.Mercury = {
27
+
28
+ // # Mercury Configuration
29
+ config: {
30
+ // ## Toolbars
31
+ //
32
+ // This is where you can customize the toolbars by adding or removing buttons, or changing them and their
33
+ // behaviors. Any top level object put here will create a new toolbar. Buttons are simply nested inside the
34
+ // toolbars, along with button groups.
35
+ //
36
+ // Some toolbars are custom (the snippets toolbar for instance), and to denote that use _custom: true. You can
37
+ // then build the toolbar yourself with it's own behavior.
38
+ //
39
+ // Buttons can be grouped, and a button group is simply a way to wrap buttons for styling -- they can also handle
40
+ // enabling or disabling all the buttons within it by using a context. The table button group is a good example
41
+ // of this.
42
+ //
43
+ // It's important to note that each of the button names (keys), in each toolbar object must be unique, regardless
44
+ // of if it's in a button group, or nested, etc. This is because styling is applied to them by name, and because
45
+ // their name is used in the event that's fired when you click on them.
46
+ //
47
+ // Button format: `[label, description, {type: action, type: action, etc}]`
48
+ //
49
+ // ### The available button types are:
50
+ //
51
+ // - toggle: toggles on or off when clicked, otherwise behaves like a button
52
+ // - modal: opens a modal window, expects the action to be one of:
53
+ // 1. a string url
54
+ // 2. a function that returns a string url
55
+ // - lightview: opens a lightview window (like modal, but different UI), expects the action to be one of:
56
+ // 1. a string url
57
+ // 2. a function that returns a string url
58
+ // - panel: opens a panel dialog, expects the action to be one of:
59
+ // 1. a string url
60
+ // 2. a function that returns a string url
61
+ // - palette: opens a palette window, expects the action to be one of:
62
+ // 1. a string url
63
+ // 2. a function that returns a string url
64
+ // - select: opens a pulldown style window, expects the action to be one of:
65
+ // 1. a string url
66
+ // 2. a function that returns a string url
67
+ // - context: calls a callback function, expects the action to be:
68
+ // 1. a function that returns a boolean to highlight the button
69
+ // note: if a function isn't provided, the key will be passed to the contextHandler, in which case a default
70
+ // context will be used (for more info read the Contexts section below)
71
+ // - mode: toggle a given mode in the editor, expects the action to be:
72
+ // 1. a string, denoting the name of the mode
73
+ // note: it's assumed that when a specific mode is turned on, all other modes will be turned off, which happens
74
+ // automatically, thus putting the editor into a specific "state"
75
+ // - regions: allows buttons to be enabled/disabled based on what region type has focus, expects the action to be:
76
+ // 1. an array of region types (eg. ['full', 'markdown'])
77
+ // - preload: allows some dialog views to be loaded when the button is created instead of on first open, expects:
78
+ // 1. a boolean true / false
79
+ // note: this is only used by panels, selects, and palettes
80
+ //
81
+ // Separators are any "button" that's not an array, and are expected to be a string. You can use two different
82
+ // separator styles: line ('-'), and spacer (' ').
83
+ //
84
+ // ### Adding Contexts
85
+ //
86
+ // Contexts are used callback functions used for highlighting and disabling/enabling buttons and buttongroups. When
87
+ // the cursor enters an element within an html region for instance we want to disable or highlight buttons based on
88
+ // the properties of the given node. You can see examples of contexts in, and add your own to:
89
+ // `Mercury.Toolbar.Button.contexts` and `Mercury.Toolbar.ButtonGroup.contexts`
90
+ toolbars: {
91
+ primary: {
92
+ save: ['Save', 'Save this page'],
93
+ preview: ['Preview', 'Preview this page', { toggle: true, mode: true }],
94
+ publish: ['Publishing', 'Manage the publishing of this page'],
95
+ sep1: ' ',
96
+ undoredo: {
97
+ undo: ['Undo', 'Undo your last action'],
98
+ redo: ['Redo', 'Redo your last action'],
99
+ sep: ' '
100
+ },
101
+ insertLink: ['Link', 'Insert Link', { modal: '/mercury/modals/link.html', regions: ['full', 'markdown'] }],
102
+ insertMedia: ['Images', 'Insert Media (images and videos)', {panel: function(){ return new CMSimple.Panels.ImageLibrary('media'); }}],
103
+ insertTable: ['Table', 'Insert Table', { modal: '/mercury/modals/table.html', regions: ['full', 'markdown'] }],
104
+ insertCharacter: ['Character', 'Special Characters', { modal: '/mercury/modals/character.html', regions: ['full', 'markdown'] }],
105
+ snippetPanel: ['Snippet', 'Snippet Panel', { panel: '/cmsimple/snippets' }],
106
+ sep2: ' ',
107
+ editMetadata: ['Page Info', 'Edit Page Metadata'],
108
+ historyPanel: ['History', 'Page Version History', {panel: function(){ return new CMSimple.Panels.Versions('history'); }}],
109
+ sep4: ' ',
110
+ sitemap: ['Site Map', 'List of pages in the site', {panel: function(){ return new CMSimple.Panels.Sitemap('sitemap'); }}],
111
+ redirects: ['Redirects', 'List of redirects in the site', {panel: function(){ return new CMSimple.Panels.Redirects('redirects'); }}],
112
+ // sep4: ' ',
113
+ // notesPanel: ['Notes', 'Page Notes', { panel: '/mercury/panels/notes.html' }]
114
+ },
115
+
116
+ editable: {
117
+ _regions: ['full', 'markdown', 'snippets'],
118
+ predefined: {
119
+ style: ['Style', null, { select: '/mercury/selects/style.html', preload: true }],
120
+ sep1: ' ',
121
+ formatblock: ['Block Format', null, { select: '/mercury/selects/formatblock.html', preload: true }],
122
+ sep2: '-'
123
+ },
124
+ colors: {
125
+ backColor: ['Background Color', null, { palette: '/mercury/palettes/backcolor.html', context: true, preload: true, regions: ['full'] }],
126
+ sep1: ' ',
127
+ foreColor: ['Text Color', null, { palette: '/mercury/palettes/forecolor.html', context: true, preload: true, regions: ['full'] }],
128
+ sep2: '-'
129
+ },
130
+ decoration: {
131
+ bold: ['Bold', null, { context: true }],
132
+ italic: ['Italicize', null, { context: true }],
133
+ overline: ['Overline', null, { context: true, regions: ['full'] }],
134
+ strikethrough: ['Strikethrough', null, { context: true, regions: ['full'] }],
135
+ underline: ['Underline', null, { context: true, regions: ['full'] }],
136
+ sep: '-'
137
+ },
138
+ script: {
139
+ subscript: ['Subscript', null, { context: true }],
140
+ superscript: ['Superscript', null, { context: true }],
141
+ sep: '-'
142
+ },
143
+ justify: {
144
+ justifyLeft: ['Align Left', null, { context: true, regions: ['full'] }],
145
+ justifyCenter: ['Center', null, { context: true, regions: ['full'] }],
146
+ justifyRight: ['Align Right', null, { context: true, regions: ['full'] }],
147
+ justifyFull: ['Justify Full', null, { context: true, regions: ['full'] }],
148
+ sep: '-'
149
+ },
150
+ list: {
151
+ insertUnorderedList: ['Unordered List', null, { context: true }],
152
+ insertOrderedList: ['Numbered List', null, { context: true }],
153
+ sep: '-'
154
+ },
155
+ indent: {
156
+ outdent: ['Decrease Indentation'],
157
+ indent: ['Increase Indentation'],
158
+ sep: '-'
159
+ },
160
+ table: {
161
+ _context: true,
162
+ insertRowBefore: ['Insert Table Row', 'Insert a table row before the cursor', { regions: ['full'] }],
163
+ insertRowAfter: ['Insert Table Row', 'Insert a table row after the cursor', { regions: ['full'] }],
164
+ deleteRow: ['Delete Table Row', 'Delete this table row', { regions: ['full'] }],
165
+ insertColumnBefore: ['Insert Table Column', 'Insert a table column before the cursor', { regions: ['full'] }],
166
+ insertColumnAfter: ['Insert Table Column', 'Insert a table column after the cursor', { regions: ['full'] }],
167
+ deleteColumn: ['Delete Table Column', 'Delete this table column', { regions: ['full'] }],
168
+ sep1: ' ',
169
+ increaseColspan: ['Increase Cell Columns', 'Increase the cells colspan'],
170
+ decreaseColspan: ['Decrease Cell Columns', 'Decrease the cells colspan and add a new cell'],
171
+ increaseRowspan: ['Increase Cell Rows', 'Increase the cells rowspan'],
172
+ decreaseRowspan: ['Decrease Cell Rows', 'Decrease the cells rowspan and add a new cell'],
173
+ sep2: '-'
174
+ },
175
+ rules: {
176
+ horizontalRule: ['Horizontal Rule', 'Insert a horizontal rule'],
177
+ sep1: '-'
178
+ },
179
+ formatting: {
180
+ removeFormatting: ['Remove Formatting', 'Remove formatting for the selection', { regions: ['full'] }],
181
+ sep2: ' '
182
+ },
183
+ editors: {
184
+ htmlEditor: ['Edit HTML', 'Edit the HTML content', { regions: ['full'] }]
185
+ }
186
+ },
187
+
188
+ snippets: {
189
+ _custom: true,
190
+ actions: {
191
+ editSnippet: ['Edit Snippet Settings'],
192
+ sep1: ' ',
193
+ removeSnippet: ['Remove Snippet']
194
+ }
195
+ }
196
+ },
197
+
198
+
199
+ // ## Region Options
200
+ //
201
+ // You can customize some aspects of how regions are found, identified, and saved.
202
+ //
203
+ // className: Mercury identifies editable regions by a className. This classname has to be added in your HTML in
204
+ // advance, and is the only real code/naming exposed in the implementation of Mercury. To allow this to be as
205
+ // configurable as possible, you can set the name of the class. When switching to preview mode, this configuration
206
+ // is also used to generate a class to indicate that Mercury is in preview mode by appending it with '-preview' (so
207
+ // by default it would be mercury-region-preview)
208
+ //
209
+ // identifier: This is used as a unique identifier for any given region (and thus should be unique to the page).
210
+ // By default this is the id attribute but can be changed to a data attribute should you want to use something
211
+ // custom instead.
212
+ //
213
+ // dataAttributes: The dataAttributes is an array of data attributes that will be serialized and returned to the
214
+ // server upon saving. These attributes, when applied to a Mercury region element, will be automatically serialized
215
+ // and submitted with the AJAX request sent when a page is saved. These are expected to be HTML5 data attributes,
216
+ // and 'data-' will automatically be prepended to each item in this directive. (ex. ['scope', 'version'])
217
+ regions: {
218
+ attribute: 'data-mercury',
219
+ identifier: 'id',
220
+ dataAttributes: []
221
+ // determineType: function(region){},
222
+ },
223
+
224
+
225
+ // ## Snippet Options / Preview
226
+ //
227
+ // When a user drags a snippet onto the page they'll be prompted to enter options for the given snippet. The server
228
+ // is expected to respond with a form. Once the user submits this form, an Ajax request is sent to the server with
229
+ // the options provided; this preview request is expected to respond with the rendered markup for the snippet.
230
+ //
231
+ // method: The HTTP method used when submitting both the options and the preview. We use POST by default because a
232
+ // snippet options form may contain large text inputs and we don't want that to be truncated when sent to the
233
+ // server.
234
+ //
235
+ // optionsUrl: The url that the options form will be loaded from.
236
+ //
237
+ // previewUrl: The url that the options will be submitted to, and will return the rendered snippet markup.
238
+ //
239
+ // **Note:** `:name` will be replaced with the snippet name in the urls (eg. /mercury/snippets/example/options.html)
240
+ snippets: {
241
+ method: 'POST',
242
+ optionsUrl: '/cmsimple/snippets/:name/options',
243
+ previewUrl: '/cmsimple/snippets/:name/preview'
244
+ },
245
+
246
+
247
+ // ## Image Uploading
248
+ //
249
+ // If you drag images from your desktop into regions that support it, it will be uploaded to the server and inserted
250
+ // into the region. You can disable or enable this feature, the accepted mime-types, file size restrictions, and
251
+ // other things related to uploading.
252
+ //
253
+ // **Note:** Image uploading is only supported in some region types, and some browsers.
254
+ //
255
+ // enabled: You can set this to true, or false if you want to disable the feature entirely.
256
+ //
257
+ // allowedMimeTypes: You can restrict the types of files that can be uploaded by providing a list of allowed mime
258
+ // types.
259
+ //
260
+ // maxFileSize: You can restrict large files by setting the maxFileSize (in bytes).
261
+ //
262
+ // inputName: When uploading, a form is generated and submitted to the server via Ajax. If your server would prefer
263
+ // a different name for how the image comes through, you can change the inputName.
264
+ //
265
+ // url: The url that the image upload will be submitted to.
266
+ //
267
+ // handler: You can use false to let Mercury handle it for you, or you can provide a handler function that can
268
+ // modify the response from the server. This can be useful if your server doesn't respond the way Mercury expects.
269
+ // The handler function should take the response from the server and return an object that matches:
270
+ // `{image: {url: '[your provided url]'}`
271
+ uploading: {
272
+ enabled: false,
273
+ allowedMimeTypes: ['image/jpeg', 'image/gif', 'image/png'],
274
+ maxFileSize: 1235242880,
275
+ inputName: 'image[image]',
276
+ url: '/mercury/images',
277
+ handler: false
278
+ },
279
+
280
+
281
+ // ## Localization / I18n
282
+ //
283
+ // Include the .locale files you want to support when loading Mercury. The files are always named by the language,
284
+ // and not the regional dialect (eg. en.locale.js) because the regional dialects are nested within the primary
285
+ // locale files.
286
+ //
287
+ // The client locale will be used first, and if no proper locale file is found for their language then the fallback
288
+ // preferredLocale configuration will be used. If one isn't provided, and the client locale isn't included, the
289
+ // strings will remain untranslated.
290
+ //
291
+ // enabled: Set to false to disable, true to enable.
292
+ //
293
+ // preferredLocale: If a client doesn't support the locales you've included, this is used as a fallback.
294
+ localization: {
295
+ enabled: false,
296
+ preferredLocale: 'swedish_chef-BORK'
297
+ },
298
+
299
+
300
+ // ## Behaviors
301
+ //
302
+ // Behaviors are used to change the default behaviors of a given region type when a given button is clicked. For
303
+ // example, you may prefer to add HR tags using an HR wrapped within a div with a classname (for styling). You
304
+ // can add your own complex behaviors here and they'll be shared across all regions.
305
+ //
306
+ // If you want to add behaviors to specific region types, you can mix them into the actions property of any region
307
+ // type.
308
+ //
309
+ // Mercury.Regions.Editable.actions.htmlEditor = function() {}
310
+ //
311
+ // You can see how the behavior matches up directly with the button names. It's also important to note that the
312
+ // callback functions are executed within the scope of the given region, so you have access to all it's methods.
313
+ behaviors: {
314
+ //foreColor: function(selection, options) { selection.wrap('<span style="color:' + options.value.toHex() + '">', true) },
315
+ htmlEditor: function() { Mercury.modal('/mercury/modals/htmleditor.html', { title: 'HTML Editor', fullHeight: true, handler: 'htmlEditor' }); }
316
+ },
317
+
318
+
319
+ // ## Global Behaviors
320
+ //
321
+ // Global behaviors are much like behaviors, but are more "global". Things like save, exit, etc. can be included
322
+ // here. They'll only be called once, and execute within the scope of whatever editor is instantiated (eg.
323
+ // PageEditor).
324
+ //
325
+ // An example of changing how saving works:
326
+ //
327
+ // save: function() {
328
+ // var data = top.JSON.stringify(this.serialize(), null, ' ');
329
+ // var content = '<textarea style="width:500px;height:200px" wrap="off">' + data + '</textarea>';
330
+ // Mercury.modal(null, {title: 'Saving', closeButton: true, content: content})
331
+ // }
332
+ //
333
+ // This is a nice way to add functionality, when the behaviors aren't region specific. These can be triggered by a
334
+ // button, or manually with `Mercury.trigger('action', {action: 'barrelRoll'})`
335
+ globalBehaviors: {
336
+ exit: function() { window.location.href = this.iframeSrc() },
337
+ newPage: function(){ Mercury.modal('/pages/new', { title: 'Create a New Page', handler: 'newPage' }); },
338
+ editMetadata: function() { Mercury.modal('/pages/'+ CMSimple.Editor.current_page.id + '/edit', { title: 'Page Metadata', handler: 'editMetadata' }); },
339
+ publish: function() { Mercury.modal('/pages/'+ CMSimple.Editor.current_page.id + '/publish', { title: 'Publish Page', handler: 'publish' }); }
340
+ },
341
+
342
+
343
+ // ## Ajax and CSRF Headers
344
+ //
345
+ // Some server frameworks require that you provide a specific header for Ajax requests. The values for these CSRF
346
+ // tokens are typically stored in the rendered DOM. By default, Mercury will look for the Rails specific meta tag,
347
+ // and provide the X-CSRF-Token header on Ajax requests, but you can modify this configuration if the system you're
348
+ // using doesn't follow the same standard.
349
+ csrfSelector: 'meta[name="csrf-token"]',
350
+ csrfHeader: 'X-CSRF-Token',
351
+
352
+ // ## Editor URLs
353
+ //
354
+ // When loading a given page, you may want to tweak this regex. It's to allow the url to differ from the page
355
+ // you're editing, and the url at which you access it.
356
+ editorUrlRegEx: /([http|https]:\/\/.[^\/]*)\/editor\/?(.*)/i,
357
+
358
+ // ## Hijacking Links & Forms
359
+ //
360
+ // Mercury will hijack links and forms that don't have a target set, or the target is set to _self and will set it
361
+ // to _parent. This is because the target must be set properly for Mercury to not get in the way of some
362
+ // functionality, like proper page loads on form submissions etc. Mercury doesn't do this to links or forms that
363
+ // are within editable regions because it doesn't want to impact the html that's saved. With that being explained,
364
+ // you can add classes to links or forms that you don't want this behavior added to. Let's say you have links that
365
+ // open a lightbox style window, and you don't want the targets of these to be set to _parent. You can add classes
366
+ // to this array, and they will be ignored when the hijacking is applied.
367
+ nonHijackableClasses: [],
368
+
369
+
370
+ // ## Pasting & Sanitizing
371
+ //
372
+ // When pasting content into Mercury it may sometimes contain HTML tags and attributes. This markup is used to
373
+ // style the content and makes the pasted content look (and behave) the same as the original content. This can be a
374
+ // desired feature or an annoyance, so you can enable various sanitizing methods to clean the content when it's
375
+ // pasted.
376
+ //
377
+ // sanitize: Can be any of the following:
378
+ // - false: no sanitizing is done, the content is pasted the exact same as it was copied by the user
379
+ // - 'whitelist': content is cleaned using the settings specified in the tag white list (described below)
380
+ // - 'text': all html is stripped before pasting, leaving only the raw text
381
+ //
382
+ // whitelist: The white list allows you to specify tags and attributes that are allowed when pasting content. Each
383
+ // item in this object should contain the allowed tag, and an array of attributes that are allowed on that tag. If
384
+ // the allowed attributes array is empty, all attributes will be removed. If a tag is not present in this list, it
385
+ // will be removed, but without removing any of the text or tags inside it.
386
+ //
387
+ // **Note:** Content is *always* sanitized if looks like it's from MS Word or similar editors regardless of this
388
+ // configuration.
389
+ pasting: {
390
+ sanitize: 'whitelist',
391
+ whitelist: {
392
+ h1: [],
393
+ h2: [],
394
+ h3: [],
395
+ h4: [],
396
+ h5: [],
397
+ h6: [],
398
+ table: [],
399
+ thead: [],
400
+ tbody: [],
401
+ tfoot: [],
402
+ tr: [],
403
+ th: ['colspan', 'rowspan'],
404
+ td: ['colspan', 'rowspan'],
405
+ div: ['class'],
406
+ span: ['class'],
407
+ ul: [],
408
+ ol: [],
409
+ li: [],
410
+ b: [],
411
+ strong: [],
412
+ i: [],
413
+ em: [],
414
+ u: [],
415
+ strike: [],
416
+ br: [],
417
+ p: [],
418
+ hr: [],
419
+ a: ['href', 'target', 'title', 'name'],
420
+ img: ['src', 'title', 'alt']
421
+ }
422
+ },
423
+
424
+
425
+ // ## Injected Styles
426
+ //
427
+ // Mercury tries to stay as much out of your code as possible, but because regions appear within your document we
428
+ // need to include a few styles to indicate regions, as well as the different states of them (eg. focused). These
429
+ // styles are injected into your document, and as simple as they might be, you may want to change them.
430
+ //
431
+ // {{regionClass}} will be automatically replaced with whatever you have set in the regions.class config directive.
432
+ injectedStyles: '' +
433
+ '[data-mercury] { min-height: 10px; outline: 1px dotted #09F } ' +
434
+ '[data-mercury]:focus { outline: none; -webkit-box-shadow: 0 0 10px #09F, 0 0 1px #045; box-shadow: 0 0 10px #09F, 0 0 1px #045 }' +
435
+ '[data-mercury].focus { outline: none; -webkit-box-shadow: 0 0 10px #09F, 0 0 1px #045; box-shadow: 0 0 10px #09F, 0 0 1px #045 }' +
436
+ '[data-mercury]:after { content: "."; display: block; visibility: hidden; clear: both; height: 0; overflow: hidden; }' +
437
+ '[data-mercury] table { border: 1px dotted red; min-width: 6px; }' +
438
+ '[data-mercury] th { border: 1px dotted red; min-width: 6px; }' +
439
+ '[data-mercury] td { border: 1px dotted red; min-width: 6px; }' +
440
+ '[data-mercury] .mercury-textarea { border: 0; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; resize: none; }' +
441
+ '[data-mercury] .mercury-textarea:focus { outline: none; -webkit-box-shadow: none; -moz-box-shadow: none; box-shadow: none; }' +
442
+ '.selected-image { outline: 2px dotted #ff00ff }'
443
+ },
444
+
445
+ // ## Silent Mode
446
+ //
447
+ // Turning silent mode on will disable asking about unsaved changes before leaving the page.
448
+ silent: false,
449
+
450
+ // ## Debug Mode
451
+ //
452
+ // Turning debug mode on will log events and other various things (using console.debug if available).
453
+ debug: false,
454
+
455
+ // The onload method is provided as a callback in case you want to override default Mercury Editor behavior. It will
456
+ // be called directly after the Mercury scripts have loaded, but before anything has been initialized. It's a good
457
+ // place to add or change functionality.
458
+ onload: function() {
459
+ //Mercury.PageEditor.prototype.iframeSrc = function(url) { return '/testing'; }
460
+ },
461
+
462
+ };