mercury_engine 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 Josh Nussbaum
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # Mercury Engine
2
+
3
+ A basic content editing system based on [Mercury Editor](http://jejacks0n.github.com/mercury/).
4
+
5
+ [![Travis CI Status](https://travis-ci.org/DynamoMTL/mercury-engine.png)](https://travis-ci.org/DynamoMTL/mercury-engine)
6
+
7
+ [![Code Climate](https://codeclimate.com/github/DynamoMTL/mercury-engine.png)](https://codeclimate.com/github/DynamoMTL/mercury-engine)
8
+
9
+ Whats that?
10
+ --------
11
+
12
+ mercury-engine is a lightweight content editing system that makes it easy to add live in-place editing to your site's static pages.
13
+
14
+ It is designed to fit a workflow where static pages are hand crafted using regular Rails templates/asset pipeline.
15
+
16
+ It does not impose any structure on the host application and has minimal requirements.
17
+
18
+ ### How it works
19
+
20
+ Say you have a HAML template like this:
21
+ ```haml
22
+ -# in app/views/pages/index.html.haml
23
+ %section#main
24
+ %h1 My Cyber Web Page
25
+ #details.highlight
26
+ :markdown
27
+ All your web belong to us
28
+ ```
29
+
30
+ To make it editable, simply annotate it with the helper:
31
+ ```haml
32
+ %section#main
33
+ = editable(:title, :h1) do
34
+ My Editable Cyber Web Page
35
+
36
+ = editable(:details, class: 'highlight') do
37
+ :markdown
38
+ All your web belong to us
39
+ ```
40
+
41
+ ## `editable` helper
42
+
43
+ `#editable(id, tag_or_options, options)`
44
+
45
+ - The `id` is required and should be unique per page
46
+ - The tag is optional and defaults to `:div`
47
+ - The last parameter is an optional hash of html attributes
48
+
49
+ ## How we decide which content to use
50
+
51
+ If the user has edited a given section, content will be served from the database.
52
+ When there are no edits, then the content defined in the template will used.
53
+
54
+ ## Content Types
55
+
56
+ The helper also supports Mercury's other content types:
57
+
58
+ ```haml
59
+ = editable(:title, :h1, type: :simple) # only allow text in h1
60
+ = editable(:details, :div, type: :full) # allow any markup inside div
61
+ ```
62
+
63
+ Most of the time you wont need to explicitly declare the `:type` because the helper can determine `:type` for common tags.
64
+ The following tags are considered simple: h1, h2, h3, h4, h5, h6, a, span, label
65
+
66
+ Installation
67
+ ------------
68
+ Add `mercury_engine` to your Gemfile:
69
+
70
+ ```ruby
71
+ gem 'mercury_engine'
72
+ ```
73
+
74
+ Alternatively you can use the git repo directly:
75
+
76
+ ```ruby
77
+ gem 'mercury_engine', github: 'DynamoMTL/mercury-engine'
78
+ ```
79
+
80
+ Now, update your bundle:
81
+
82
+ ```bash
83
+ bundle
84
+ ```
85
+
86
+ Then, run the `mercury_engine:install` generator.
87
+ It will copy over database migrations and will mount the engine in your `config/routes.rb` file.
88
+
89
+ ```
90
+ rails generate mercury_engine:install
91
+ ```
92
+
93
+ Also, add the "Edit" link somewhere in your layout.
94
+ The engine provides a partial that will only show the link when an admin is logged in.
95
+
96
+ ```haml
97
+ = render partial: 'mercury_engine/shared/edit_link'
98
+ ```
99
+ # And - you're done.
100
+ coffee break?
101
+
102
+ Testing
103
+ -------
104
+
105
+ Clone the repo:
106
+
107
+ $ hub clone DynamoMTL/mercury-engine && cd mercury-engine
108
+
109
+ To run tests:
110
+
111
+ $ bundle exec rake spec
112
+
113
+ To run tests with guard (preferred):
114
+
115
+ $ bundle exec guard
data/Rakefile ADDED
@@ -0,0 +1,29 @@
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 = 'Mercury Engine'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
25
+ task default: :spec
26
+
27
+ task :spec do
28
+ sh 'cd spec/dummy && bundle exec rake spec'
29
+ end
@@ -0,0 +1,533 @@
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
+ # * Minimum jQuery requirements are 1.7
6
+ # *= require_self
7
+ # *
8
+ # * You can include the Rails jQuery ujs script here to get some nicer behaviors in modals, panels and lightviews when
9
+ # * using :remote => true within the contents rendered in them.
10
+ # * require jquery_ujs
11
+ # *
12
+ # * Add any requires for the support libraries that integrate nicely with Mercury Editor.
13
+ # * require mercury/support/history
14
+ # *
15
+ # * Require Mercury Editor itself.
16
+ # *= require mercury/mercury
17
+ # *
18
+ # * Require any localizations you wish to support
19
+ # * Example: es.locale, or fr.locale -- regional dialects are in each language file so never en_US for instance.
20
+ # * Make sure you enable the localization feature in the configuration.
21
+ # * require mercury/locales/swedish_chef.locale
22
+ # *
23
+ # * Add all requires for plugins that extend or change the behavior of Mercury Editor.
24
+ # * require mercury/plugins/save_as_xml/plugin.js
25
+ # *
26
+ # * Require any files you want to use that either extend, or change the default Mercury behavior.
27
+ # * require mercury_overrides
28
+ #
29
+ window.Mercury =
30
+
31
+ # # Mercury Configuration
32
+ config:
33
+
34
+ # ## Toolbars
35
+ #
36
+ # This is where you can customize the toolbars by adding or removing buttons, or changing them and their
37
+ # behaviors. Any top level object put here will create a new toolbar. Buttons are simply nested inside the
38
+ # toolbars, along with button groups.
39
+ #
40
+ # Some toolbars are custom (the snippets toolbar for instance), and to denote that use _custom: true. You can then
41
+ # build the toolbar yourself with it's own behavior.
42
+ #
43
+ # Buttons can be grouped, and a button group is simply a way to wrap buttons for styling -- they can also handle
44
+ # enabling or disabling all the buttons within it by using a context. The table button group is a good example of
45
+ # this.
46
+ #
47
+ # It's important to note that each of the button names (keys), in each toolbar object must be unique, regardless of
48
+ # if it's in a button group, or nested, etc. This is because styling is applied to them by name, and because their
49
+ # name is used in the event that's fired when you click on them.
50
+ #
51
+ # Button format: `[label, description, {type: action, type: action, etc}]`
52
+ #
53
+ # ### The available button types are:
54
+ #
55
+ # - toggle: toggles on or off when clicked, otherwise behaves like a button
56
+ # - modal: opens a modal window, expects the action to be one of:
57
+ # 1. a string url
58
+ # 2. a function that returns a string url
59
+ # - lightview: opens a lightview window (like modal, but different UI), expects the action to be one of:
60
+ # 1. a string url
61
+ # 2. a function that returns a string url
62
+ # - panel: opens a panel dialog, expects the action to be one of:
63
+ # 1. a string url
64
+ # 2. a function that returns a string url
65
+ # - palette: opens a palette window, expects the action to be one of:
66
+ # 1. a string url
67
+ # 2. a function that returns a string url
68
+ # - select: opens a pulldown style window, expects the action to be one of:
69
+ # 1. a string url
70
+ # 2. a function that returns a string url
71
+ # - context: calls a callback function, expects the action to be:
72
+ # 1. a function that returns a boolean to highlight the button
73
+ # note: if a function isn't provided, the key will be passed to the contextHandler, in which case a default
74
+ # context will be used (for more info read the Contexts section below)
75
+ # - mode: toggle a given mode in the editor, expects the action to be:
76
+ # 1. a string, denoting the name of the mode
77
+ # note: it's assumed that when a specific mode is turned on, all other modes will be turned off, which happens
78
+ # automatically, thus putting the editor into a specific "state"
79
+ # - regions: allows buttons to be enabled/disabled based on what region type has focus, expects:
80
+ # 1. an array of region types (eg. ['full', 'markdown'])
81
+ # - preload: allows some dialog views to be loaded when the button is created instead of on first open, expects:
82
+ # 1. a boolean true / false
83
+ # note: this is only used by panels, selects, and palettes
84
+ #
85
+ # Separators are any "button" that's not an array, and are expected to be a string. You can use two different
86
+ # separator styles: line ('-'), and spacer (' ').
87
+ #
88
+ # ### Adding Contexts
89
+ #
90
+ # Contexts are used callback functions used for highlighting and disabling/enabling buttons and buttongroups. When
91
+ # the cursor enters an element within an html region for instance we want to disable or highlight buttons based on
92
+ # the properties of the given node. You can see examples of contexts in, and add your own to:
93
+ # `Mercury.Toolbar.Button.contexts` and `Mercury.Toolbar.ButtonGroup.contexts`
94
+ toolbars:
95
+ primary:
96
+ save: ["Save", "Save this page"]
97
+ preview: ["Preview", "Preview this page",
98
+ toggle: true
99
+ mode: true
100
+ ]
101
+ sep1: " "
102
+ undoredo:
103
+ undo: ["Undo", "Undo your last action"]
104
+ redo: ["Redo", "Redo your last action"]
105
+ sep: " "
106
+
107
+ insertLink: ["Link", "Insert Link",
108
+ modal: "/mercury/modals/link.html"
109
+ regions: ["full", "markdown"]
110
+ ]
111
+ insertMedia: ["Media", "Insert Media (images and videos)",
112
+ modal: "/mercury/modals/media.html"
113
+ regions: ["full", "markdown"]
114
+ ]
115
+ insertTable: ["Table", "Insert Table",
116
+ modal: "/mercury/modals/table.html"
117
+ regions: ["full", "markdown"]
118
+ ]
119
+ insertCharacter: ["Character", "Special Characters",
120
+ modal: "/mercury/modals/character.html"
121
+ regions: ["full", "markdown"]
122
+ ]
123
+ snippetPanel: ["Snippet", "Snippet Panel",
124
+ panel: "/mercury/panels/snippets.html"
125
+ ]
126
+ sep2: " "
127
+ historyPanel: ["History", "Page Version History",
128
+ panel: "/mercury/panels/history.html"
129
+ ]
130
+ sep3: " "
131
+ notesPanel: ["Notes", "Page Notes",
132
+ panel: "/mercury/panels/notes.html"
133
+ ]
134
+
135
+ editable:
136
+ _regions: ["full", "markdown"]
137
+ predefined:
138
+ style: ["Style", null,
139
+ select: "/mercury/selects/style.html"
140
+ preload: true
141
+ ]
142
+ sep1: " "
143
+ formatblock: ["Block Format", null,
144
+ select: "/mercury/selects/formatblock.html"
145
+ preload: true
146
+ ]
147
+ sep2: "-"
148
+
149
+ colors:
150
+ backColor: ["Background Color", null,
151
+ palette: "/mercury/palettes/backcolor.html"
152
+ context: true
153
+ preload: true
154
+ regions: ["full"]
155
+ ]
156
+ sep1: " "
157
+ foreColor: ["Text Color", null,
158
+ palette: "/mercury/palettes/forecolor.html"
159
+ context: true
160
+ preload: true
161
+ regions: ["full"]
162
+ ]
163
+ sep2: "-"
164
+
165
+ decoration:
166
+ bold: ["Bold", null,
167
+ context: true
168
+ ]
169
+ italic: ["Italicize", null,
170
+ context: true
171
+ ]
172
+ overline: ["Overline", null,
173
+ context: true
174
+ regions: ["full"]
175
+ ]
176
+ strikethrough: ["Strikethrough", null,
177
+ context: true
178
+ regions: ["full"]
179
+ ]
180
+ underline: ["Underline", null,
181
+ context: true
182
+ regions: ["full"]
183
+ ]
184
+ sep: "-"
185
+
186
+ script:
187
+ subscript: ["Subscript", null,
188
+ context: true
189
+ ]
190
+ superscript: ["Superscript", null,
191
+ context: true
192
+ ]
193
+ sep: "-"
194
+
195
+ justify:
196
+ justifyLeft: ["Align Left", null,
197
+ context: true
198
+ regions: ["full"]
199
+ ]
200
+ justifyCenter: ["Center", null,
201
+ context: true
202
+ regions: ["full"]
203
+ ]
204
+ justifyRight: ["Align Right", null,
205
+ context: true
206
+ regions: ["full"]
207
+ ]
208
+ justifyFull: ["Justify Full", null,
209
+ context: true
210
+ regions: ["full"]
211
+ ]
212
+ sep: "-"
213
+
214
+ list:
215
+ insertUnorderedList: ["Unordered List", null,
216
+ context: true
217
+ ]
218
+ insertOrderedList: ["Numbered List", null,
219
+ context: true
220
+ ]
221
+ sep: "-"
222
+
223
+ indent:
224
+ outdent: ["Decrease Indentation"]
225
+ indent: ["Increase Indentation"]
226
+ sep: "-"
227
+
228
+ table:
229
+ _context: true
230
+ insertRowBefore: ["Insert Table Row", "Insert a table row before the cursor",
231
+ regions: ["full"]
232
+ ]
233
+ insertRowAfter: ["Insert Table Row", "Insert a table row after the cursor",
234
+ regions: ["full"]
235
+ ]
236
+ deleteRow: ["Delete Table Row", "Delete this table row",
237
+ regions: ["full"]
238
+ ]
239
+ insertColumnBefore: ["Insert Table Column", "Insert a table column before the cursor",
240
+ regions: ["full"]
241
+ ]
242
+ insertColumnAfter: ["Insert Table Column", "Insert a table column after the cursor",
243
+ regions: ["full"]
244
+ ]
245
+ deleteColumn: ["Delete Table Column", "Delete this table column",
246
+ regions: ["full"]
247
+ ]
248
+ sep1: " "
249
+ increaseColspan: ["Increase Cell Columns", "Increase the cells colspan"]
250
+ decreaseColspan: ["Decrease Cell Columns", "Decrease the cells colspan and add a new cell"]
251
+ increaseRowspan: ["Increase Cell Rows", "Increase the cells rowspan"]
252
+ decreaseRowspan: ["Decrease Cell Rows", "Decrease the cells rowspan and add a new cell"]
253
+ sep2: "-"
254
+
255
+ rules:
256
+ horizontalRule: ["Horizontal Rule", "Insert a horizontal rule"]
257
+ sep1: "-"
258
+
259
+ formatting:
260
+ removeFormatting: ["Remove Formatting", "Remove formatting for the selection",
261
+ regions: ["full"]
262
+ ]
263
+ sep2: " "
264
+
265
+ editors:
266
+ htmlEditor: ["Edit HTML", "Edit the HTML content",
267
+ regions: ["full"]
268
+ ]
269
+
270
+ snippets:
271
+ _custom: true
272
+ actions:
273
+ editSnippet: ["Edit Snippet Settings"]
274
+ sep1: " "
275
+ removeSnippet: ["Remove Snippet"]
276
+
277
+
278
+ # ## Region Options
279
+ #
280
+ # You can customize some aspects of how regions are found, identified, and saved.
281
+ #
282
+ # attribute: Mercury identifies editable regions by a data-mercury attribute. This attribute has to be added in
283
+ # your HTML in advance, and is the only real code/naming exposed in the implementation of Mercury. To allow this
284
+ # to be as configurable as possible, you can set the name of this attribute. If you change this, you should adjust
285
+ # the injected styles as well.
286
+ #
287
+ # identifier: This is used as a unique identifier for any given region (and thus should be unique to the page).
288
+ # By default this is the id attribute but can be changed to a data attribute should you want to use something
289
+ # custom instead.
290
+ #
291
+ # dataAttributes: The dataAttributes is an array of data attributes that will be serialized and returned to the
292
+ # server upon saving. These attributes, when applied to a Mercury region element, will be automatically serialized
293
+ # and submitted with the AJAX request sent when a page is saved. These are expected to be HTML5 data attributes,
294
+ # and 'data-' will automatically be prepended to each item in this directive. (ex. ['scope', 'version'])
295
+ #
296
+ # determineType: This function is called after checking the data-type attribute for the correct field type. Use
297
+ # it if you want to dynamically set the type based on inspection of the region.
298
+ regions:
299
+ attribute: "data-mercury"
300
+ identifier: "id"
301
+ dataAttributes: []
302
+
303
+
304
+ # determineType: function(region){},
305
+
306
+ # ## Snippet Options / Preview
307
+ #
308
+ # When a user drags a snippet onto the page they'll be prompted to enter options for the given snippet. The server
309
+ # is expected to respond with a form. Once the user submits this form, an Ajax request is sent to the server with
310
+ # the options provided; this preview request is expected to respond with the rendered markup for the snippet.
311
+ #
312
+ # method: The HTTP method used when submitting both the options and the preview. We use POST by default because a
313
+ # snippet options form may contain large text inputs and we don't want that to be truncated when sent to the
314
+ # server.
315
+ #
316
+ # optionsUrl: The url that the options form will be loaded from.
317
+ #
318
+ # previewUrl: The url that the options will be submitted to, and will return the rendered snippet markup.
319
+ #
320
+ # **Note:** `:name` will be replaced with the snippet name in the urls (eg. /mercury/snippets/example/options.html)
321
+ snippets:
322
+ method: "POST"
323
+ optionsUrl: "/mercury/snippets/:name/options.html"
324
+ previewUrl: "/mercury/snippets/:name/preview.html"
325
+
326
+
327
+ # ## Image Uploading
328
+ #
329
+ # If you drag images from your desktop into regions that support it, it will be uploaded to the server and inserted
330
+ # into the region. You can disable or enable this feature, the accepted mime-types, file size restrictions, and
331
+ # other things related to uploading.
332
+ #
333
+ # **Note:** Image uploading is only supported in some region types, and some browsers.
334
+ #
335
+ # enabled: You can set this to true, or false if you want to disable the feature entirely.
336
+ #
337
+ # allowedMimeTypes: You can restrict the types of files that can be uploaded by providing a list of allowed mime
338
+ # types.
339
+ #
340
+ # maxFileSize: You can restrict large files by setting the maxFileSize (in bytes).
341
+ #
342
+ # inputName: When uploading, a form is generated and submitted to the server via Ajax. If your server would prefer
343
+ # a different name for how the image comes through, you can change the inputName.
344
+ #
345
+ # url: The url that the image upload will be submitted to.
346
+ #
347
+ # handler: You can use false to let Mercury handle it for you, or you can provide a handler function that can
348
+ # modify the response from the server. This can be useful if your server doesn't respond the way Mercury expects.
349
+ # The handler function should take the response from the server and return an object that matches:
350
+ # `{image: {url: '[your provided url]'}`
351
+ uploading:
352
+ enabled: true
353
+ allowedMimeTypes: ["image/jpeg", "image/gif", "image/png"]
354
+ maxFileSize: 1235242880
355
+ inputName: "image[image]"
356
+ url: "/mercury/images"
357
+ handler: false
358
+
359
+
360
+ # ## Localization / I18n
361
+ #
362
+ # Include the .locale files you want to support when loading Mercury. The files are always named by the language,
363
+ # and not the regional dialect (eg. en.locale.js) because the regional dialects are nested within the primary
364
+ # locale files.
365
+ #
366
+ # The client locale will be used first, and if no proper locale file is found for their language then the fallback
367
+ # preferredLocale configuration will be used. If one isn't provided, and the client locale isn't included, the
368
+ # strings will remain untranslated.
369
+ #
370
+ # enabled: Set to false to disable, true to enable.
371
+ #
372
+ # preferredLocale: If a client doesn't support the locales you've included, this is used as a fallback.
373
+ localization:
374
+ enabled: false
375
+ preferredLocale: "swedish_chef-BORK"
376
+
377
+
378
+ # ## Behaviors
379
+ #
380
+ # Behaviors are used to change the default behaviors of a given region type when a given button is clicked. For
381
+ # example, you may prefer to add HR tags using an HR wrapped within a div with a classname (for styling). You
382
+ # can add your own complex behaviors here and they'll be shared across all regions.
383
+ #
384
+ # If you want to add behaviors to specific region types, you can mix them into the actions property of any region
385
+ # type.
386
+ #
387
+ # Mercury.Regions.Full.actions.htmlEditor = function() {}
388
+ #
389
+ # You can see how the behavior matches up directly with the button names. It's also important to note that the
390
+ # callback functions are executed within the scope of the given region, so you have access to all it's methods.
391
+ behaviors:
392
+
393
+ #foreColor: function(selection, options) { selection.wrap('<span style="color:' + options.value.toHex() + '">', true) },
394
+ htmlEditor: ->
395
+ Mercury.modal "/mercury/modals/htmleditor.html",
396
+ title: "HTML Editor"
397
+ fullHeight: true
398
+ handler: "htmlEditor"
399
+
400
+
401
+
402
+ # ## Global Behaviors
403
+ #
404
+ # Global behaviors are much like behaviors, but are more "global". Things like save, exit, etc. can be included
405
+ # here. They'll only be called once, and execute within the scope of whatever editor is instantiated (eg.
406
+ # PageEditor).
407
+ #
408
+ # An example of changing how saving works:
409
+ #
410
+ # save: function() {
411
+ # var data = top.JSON.stringify(this.serialize(), null, ' ');
412
+ # var content = '<textarea style="width:500px;height:200px" wrap="off">' + data + '</textarea>';
413
+ # Mercury.modal(null, {title: 'Saving', closeButton: true, content: content})
414
+ # }
415
+ #
416
+ # This is a nice way to add functionality, when the behaviors aren't region specific. These can be triggered by a
417
+ # button, or manually with `Mercury.trigger('action', {action: 'barrelRoll'})`
418
+ globalBehaviors:
419
+ exit: ->
420
+ window.location.href = @iframeSrc()
421
+
422
+ barrelRoll: ->
423
+ $("body").css webkitTransform: "rotate(360deg)"
424
+
425
+
426
+ # ## Ajax and CSRF Headers
427
+ #
428
+ # Some server frameworks require that you provide a specific header for Ajax requests. The values for these CSRF
429
+ # tokens are typically stored in the rendered DOM. By default, Mercury will look for the Rails specific meta tag,
430
+ # and provide the X-CSRF-Token header on Ajax requests, but you can modify this configuration if the system you're
431
+ # using doesn't follow the same standard.
432
+ csrfSelector: "meta[name=\"csrf-token\"]"
433
+ csrfHeader: "X-CSRF-Token"
434
+
435
+ # ## Editor URLs
436
+ #
437
+ # When loading a given page, you may want to tweak this regex. It's to allow the url to differ from the page
438
+ # you're editing, and the url at which you access it.
439
+ editorUrlRegEx: /([http|https]:\/\/.[^\/]*)\/editor\/?(.*)/i
440
+
441
+ # ## Hijacking Links & Forms
442
+ #
443
+ # Mercury will hijack links and forms that don't have a target set, or the target is set to _self and will set it
444
+ # to _parent. This is because the target must be set properly for Mercury to not get in the way of some
445
+ # functionality, like proper page loads on form submissions etc. Mercury doesn't do this to links or forms that
446
+ # are within editable regions because it doesn't want to impact the html that's saved. With that being explained,
447
+ # you can add classes to links or forms that you don't want this behavior added to. Let's say you have links that
448
+ # open a lightbox style window, and you don't want the targets of these to be set to _parent. You can add classes
449
+ # to this array, and they will be ignored when the hijacking is applied.
450
+ nonHijackableClasses: []
451
+
452
+ # ## Pasting & Sanitizing
453
+ #
454
+ # When pasting content into Mercury it may sometimes contain HTML tags and attributes. This markup is used to
455
+ # style the content and makes the pasted content look (and behave) the same as the original content. This can be a
456
+ # desired feature or an annoyance, so you can enable various sanitizing methods to clean the content when it's
457
+ # pasted.
458
+ #
459
+ # sanitize: Can be any of the following:
460
+ # - false: no sanitizing is done, the content is pasted the exact same as it was copied by the user
461
+ # - 'whitelist': content is cleaned using the settings specified in the tag white list (described below)
462
+ # - 'text': all html is stripped before pasting, leaving only the raw text
463
+ #
464
+ # whitelist: The white list allows you to specify tags and attributes that are allowed when pasting content. Each
465
+ # item in this object should contain the allowed tag, and an array of attributes that are allowed on that tag. If
466
+ # the allowed attributes array is empty, all attributes will be removed. If a tag is not present in this list, it
467
+ # will be removed, but without removing any of the text or tags inside it.
468
+ #
469
+ # **Note:** Content is *always* sanitized if looks like it's from MS Word or similar editors regardless of this
470
+ # configuration.
471
+ pasting:
472
+ sanitize: "whitelist"
473
+ whitelist:
474
+ h1: []
475
+ h2: []
476
+ h3: []
477
+ h4: []
478
+ h5: []
479
+ h6: []
480
+ table: []
481
+ thead: []
482
+ tbody: []
483
+ tfoot: []
484
+ tr: []
485
+ th: ["colspan", "rowspan"]
486
+ td: ["colspan", "rowspan"]
487
+ div: ["class"]
488
+ span: ["class"]
489
+ ul: []
490
+ ol: []
491
+ li: []
492
+ b: []
493
+ strong: []
494
+ i: []
495
+ em: []
496
+ u: []
497
+ strike: []
498
+ br: []
499
+ p: []
500
+ hr: []
501
+ a: ["href", "target", "title", "name"]
502
+ img: ["src", "title", "alt"]
503
+
504
+
505
+ # ## Injected Styles
506
+ #
507
+ # Mercury tries to stay as much out of your code as possible, but because regions appear within your document we
508
+ # need to include a few styles to indicate regions, as well as the different states of them (eg. focused). These
509
+ # styles are injected into your document, and as simple as they might be, you may want to change them.
510
+ injectedStyles: "" + "[data-mercury] { min-height: 10px; outline: 1px dotted #09F } " + "[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 }" + "[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 }" + "[data-mercury]:after { content: \".\"; display: block; visibility: hidden; clear: both; height: 0; overflow: hidden; }" + "[data-mercury] table { border: 1px dotted red; min-width: 6px; }" + "[data-mercury] th { border: 1px dotted red; min-width: 6px; }" + "[data-mercury] td { border: 1px dotted red; min-width: 6px; }" + "[data-mercury] .mercury-textarea { border: 0; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; resize: none; }" + "[data-mercury] .mercury-textarea:focus { outline: none; -webkit-box-shadow: none; -moz-box-shadow: none; box-shadow: none; }"
511
+
512
+
513
+ # ## Silent Mode
514
+ #
515
+ # Turning silent mode on will disable asking about unsaved changes before leaving the page.
516
+ silent: false
517
+
518
+ # ## Debug Mode
519
+ #
520
+ # Turning debug mode on will log events and other various things (using console.debug if available).
521
+ debug: false
522
+
523
+ $(window).bind 'mercury:saved', ->
524
+ window.location = window.location.href.replace(/\/editor\//i, '/')
525
+
526
+ $(window).bind 'mercury:ready', ->
527
+ iframe = $('#mercury_iframe').contents()
528
+ body = iframe.find('body')
529
+ element = iframe.find('#edit-page')
530
+
531
+ Mercury.saveURL = element.data('save-url')
532
+ element.hide()
533
+ body.addClass('editing')
@@ -0,0 +1,27 @@
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
+ * Copyright (c) 2011 Jeremy Jackson
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
9
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
10
+ * persons to whom the Software is furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
13
+ * Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
16
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
+ *
20
+ *= require_self
21
+ *= require mercury/bootstrap-ish
22
+ *= require mercury/mercury
23
+ */
24
+
25
+ .mercury-iframe {
26
+ height: 100%;
27
+ }
@@ -0,0 +1,18 @@
1
+ class PagesController < ApplicationController
2
+ include PagesHelper
3
+ protect_from_forgery
4
+ before_filter :authenticate_admin_user!, except: :show
5
+
6
+ def show
7
+ path = params[:path]
8
+ @page = Page.find_by_path(path)
9
+
10
+ render action: template_path(path)
11
+ end
12
+
13
+ def update
14
+ Page.update_content(params[:path], format_content(params[:content]))
15
+
16
+ render text: ''
17
+ end
18
+ end
@@ -0,0 +1,78 @@
1
+ module PagesHelper
2
+ SIMPLE_TAGS = %w(h1 h2 h3 h4 h5 h6 a span label)
3
+
4
+ def format_content(content)
5
+ content.reduce({}) do |hash, (key, data)|
6
+ hash[key.to_s] = data[:value] || data[:attributes][:src]
7
+ hash
8
+ end
9
+ end
10
+
11
+ def editable(id, tag=:div, options={}, &block)
12
+ content = content_for(id)
13
+ type = options[:type] || find_type_for_tag(tag)
14
+
15
+ if tag.is_a?(Hash)
16
+ options = tag if tag.is_a?(Hash)
17
+ tag = :div
18
+ end
19
+
20
+ options[:id] = id
21
+
22
+ set_mercury_options(options, type)
23
+
24
+ if type == :simple
25
+ if content
26
+ content_tag(tag, content, options.except(:type))
27
+ else
28
+ content_tag(tag, options.except(:type), &block)
29
+ end
30
+ else
31
+ content_tag(tag, options.except(:type), false) do
32
+ raw(content || (block.call if block))
33
+ end
34
+ end
35
+ end
36
+
37
+ def editable_image(id, default=nil)
38
+ source = content_for(id) || default
39
+ options = {id: id}
40
+
41
+ set_mercury_options(options, :image)
42
+
43
+ image_tag(source, options)
44
+ end
45
+
46
+ def title
47
+ editable(:title, :h1) { @page.content[:title] }
48
+ end
49
+
50
+ def content_for(id)
51
+ @page.content[id.to_s] if @page
52
+ end
53
+
54
+ def set_mercury_options(options, type)
55
+ if params[:mercury_frame]
56
+ options[:data] ||= {}
57
+ options[:data][:mercury] = type
58
+ end
59
+ end
60
+
61
+ def find_type_for_tag(tag)
62
+ if SIMPLE_TAGS.include?(tag.to_s)
63
+ :simple
64
+ else
65
+ :full
66
+ end
67
+ end
68
+
69
+ def template_path(path)
70
+ return 'index' if path.blank?
71
+
72
+ if template_exists?(path + '/index', %w(pages))
73
+ path + '/index'
74
+ else
75
+ path
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,42 @@
1
+ class Page < ActiveRecord::Base
2
+ acts_as_tree
3
+ has_paper_trail
4
+ attr_accessible :content, :parent, :parent_id, :permalink
5
+ serialize :content, Hash
6
+
7
+ class << self
8
+ def find_by_path(path)
9
+ return unless page = root
10
+
11
+ page.walk(path) do |last, part|
12
+ last.children.find_by_permalink(part) if last
13
+ end
14
+ end
15
+
16
+ def update_content(path, content = {})
17
+ page = root || Page.create(permalink: '')
18
+
19
+ page = page.walk(path) do |last, part|
20
+ last.children.find_or_create_by_permalink(part)
21
+ end
22
+
23
+ page.update_attributes(content: content)
24
+
25
+ page
26
+ end
27
+ end
28
+
29
+ def path
30
+ if parent
31
+ Pathname.new(parent.path) + permalink
32
+ else
33
+ Pathname.new("/")
34
+ end.to_s
35
+ end
36
+
37
+ def walk(path, &block)
38
+ parts = Pathname.new(path.to_s).each_filename
39
+
40
+ parts.reduce(self, &block)
41
+ end
42
+ end
@@ -0,0 +1,19 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %meta{:content => "width=device-width, maximum-scale=1.0, initial-scale=1.0", :name => "viewport"}/
5
+ = csrf_meta_tags
6
+ %title Content Manager
7
+ = stylesheet_link_tag 'mercury_engine/mercury'
8
+ = javascript_include_tag 'jquery-1.7', 'mercury_engine/mercury'
9
+ %body
10
+ :javascript
11
+ // Set to the url that you want to save any given page to, leave null for default handling.
12
+ var saveUrl = null;
13
+
14
+ // Instantiate the PageEditor
15
+ new Mercury.PageEditor(saveUrl, {
16
+ saveStyle: 'form', // 'form', or 'json' (default json)
17
+ saveMethod: null, // 'PUT', or 'POST', (create, vs. update -- default PUT)
18
+ visible: true // boolean - if the interface should start visible or not
19
+ });
@@ -0,0 +1,3 @@
1
+ - if admin_user_signed_in?
2
+ %nav#edit-page{ data: { 'save-url' => page_path(params[:path]) }}
3
+ = link_to t(:edit), "/editor" + request.path
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ Rails.application.routes.draw do
2
+ mount Mercury::Engine => '/'
3
+
4
+ get '/(*path)' => 'pages#show', as: :page
5
+ put '/(*path)' => 'pages#update', as: :page
6
+ end
@@ -0,0 +1,13 @@
1
+ class CreateVersions < ActiveRecord::Migration
2
+ def change
3
+ create_table :versions do |t|
4
+ t.string :item_type, :null => false
5
+ t.integer :item_id, :null => false
6
+ t.string :event, :null => false
7
+ t.string :whodunnit
8
+ t.text :object
9
+ t.datetime :created_at
10
+ end
11
+ add_index :versions, [:item_type, :item_id]
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ class CreatePages < ActiveRecord::Migration
2
+ def change
3
+ create_table :pages do |t|
4
+ t.string :permalink
5
+ t.integer :parent_id
6
+ t.text :content
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+ module MercuryEngine
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ def add_route
5
+ route "mount MercuryEngine::Engine => '/'"
6
+ end
7
+
8
+ def add_migrations
9
+ run 'bundle exec rake railties:install:migrations FROM=mercury_engine'
10
+ end
11
+
12
+ def run_migrations
13
+ response = ask "Would you like to run the migrations now? [Y/n]"
14
+
15
+ if response == "" || response.downcase == "y"
16
+ run 'bundle exec rake db:migrate'
17
+ else
18
+ say "Skipping rake db:migrate, don't forget to run it!", :yellow
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ module Mercury
2
+ module Authentication
3
+ def can_edit?
4
+ admin_user_signed_in?
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'mercury-rails'
2
+ require 'mercury/authentication'
3
+ require 'acts_as_tree'
4
+ require 'paper_trail'
5
+ require 'haml'
6
+ require 'devise'
7
+ require 'mercury_engine/engine'
@@ -0,0 +1,5 @@
1
+ module MercuryEngine
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace MercuryEngine
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module MercuryEngine
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :mercury_engine do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,211 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mercury_engine
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Josh Nussbaum
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.13
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.13
30
+ - !ruby/object:Gem::Dependency
31
+ name: mercury-rails
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: devise
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: acts_as_tree
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: paper_trail
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: haml-rails
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: sass-rails
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: coffee-rails
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :runtime
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: sqlite3
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ description: Adds models and helpers that make it easy to integrate Mercury Editor
159
+ into any rails app
160
+ email: joshnuss@gmail.com
161
+ executables: []
162
+ extensions: []
163
+ extra_rdoc_files: []
164
+ files:
165
+ - app/assets/stylesheets/mercury_engine/mercury.css
166
+ - app/assets/javascripts/mercury_engine/mercury.js.coffee
167
+ - app/views/mercury_engine/shared/_edit_link.html.haml
168
+ - app/views/layouts/mercury.html.haml
169
+ - app/models/page.rb
170
+ - app/helpers/pages_helper.rb
171
+ - app/controllers/pages_controller.rb
172
+ - config/routes.rb
173
+ - db/migrate/20130318125100_create_pages.rb
174
+ - db/migrate/20130318080000_create_versions.rb
175
+ - lib/tasks/mercury_engine_tasks.rake
176
+ - lib/mercury_engine.rb
177
+ - lib/generators/mercury_engine/install_generator.rb
178
+ - lib/mercury_engine/version.rb
179
+ - lib/mercury_engine/engine.rb
180
+ - lib/mercury/authentication.rb
181
+ - MIT-LICENSE
182
+ - Rakefile
183
+ - README.md
184
+ homepage: http://www.github.com/DynamoMTL/mercury-engine
185
+ licenses: []
186
+ post_install_message:
187
+ rdoc_options: []
188
+ require_paths:
189
+ - lib
190
+ required_ruby_version: !ruby/object:Gem::Requirement
191
+ none: false
192
+ requirements:
193
+ - - ! '>='
194
+ - !ruby/object:Gem::Version
195
+ version: 1.9.3
196
+ required_rubygems_version: !ruby/object:Gem::Requirement
197
+ none: false
198
+ requirements:
199
+ - - ! '>='
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ segments:
203
+ - 0
204
+ hash: -89830127
205
+ requirements: []
206
+ rubyforge_project:
207
+ rubygems_version: 1.8.25
208
+ signing_key:
209
+ specification_version: 3
210
+ summary: Content management in an engine using Mercury Editor
211
+ test_files: []