mercury-rails 0.2.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. data/app/controllers/{images_controller.rb → mercury/images_controller.rb} +3 -3
  2. data/app/controllers/mercury_controller.rb +13 -3
  3. data/app/models/{image.rb → mercury/image.rb} +3 -1
  4. data/app/views/layouts/mercury.html.erb +14 -6
  5. data/app/views/mercury/lightviews/about.html +7 -3
  6. data/app/views/mercury/modals/character.html +2 -2
  7. data/app/views/mercury/modals/htmleditor.html +2 -2
  8. data/app/views/mercury/modals/link.html +3 -3
  9. data/app/views/mercury/modals/media.html +3 -3
  10. data/app/views/mercury/modals/table.html +3 -3
  11. data/app/views/mercury/panels/snippets.html +1 -1
  12. data/app/views/mercury/selects/formatblock.html +9 -9
  13. data/app/views/mercury/snippets/example/options.html.erb +27 -16
  14. data/config/engine.rb +35 -0
  15. data/db/migrate/{20110526035601_create_images.rb → 20110526035601_create_mercury_images.rb} +2 -2
  16. data/features/loading/loading.feature +1 -1
  17. data/features/loading/navigating.feature +1 -1
  18. data/features/loading/user_interface.feature +2 -2
  19. data/features/regions/editable/basic_editing.feature +8 -8
  20. data/features/regions/editable/inserting_snippets.feature +4 -5
  21. data/features/regions/editable/inserting_tables.feature +9 -9
  22. data/features/step_definitions/mercury_steps.rb +20 -23
  23. data/features/step_definitions/web_steps.rb +5 -5
  24. data/features/support/mercury_selectors.rb +1 -0
  25. data/lib/generators/mercury/install/install_generator.rb +24 -3
  26. data/lib/generators/mercury/install/templates/mongoid_paperclip_image.rb +17 -0
  27. data/lib/mercury-rails.rb +0 -1
  28. data/lib/mercury/authentication.rb +8 -0
  29. data/spec/javascripts/mercury/dialog_spec.js.coffee +28 -21
  30. data/spec/javascripts/mercury/dialogs/backcolor_spec.js.coffee +0 -2
  31. data/spec/javascripts/mercury/dialogs/forecolor_spec.js.coffee +0 -2
  32. data/spec/javascripts/mercury/dialogs/formatblock_spec.js.coffee +0 -2
  33. data/spec/javascripts/mercury/dialogs/snippetpanel_spec.js.coffee +0 -2
  34. data/spec/javascripts/mercury/dialogs/style_spec.js.coffee +0 -2
  35. data/spec/javascripts/mercury/history_buffer_spec.js.coffee +0 -2
  36. data/spec/javascripts/mercury/lightview_spec.js.coffee +42 -21
  37. data/spec/javascripts/mercury/mercury_spec.js.coffee +87 -7
  38. data/spec/javascripts/mercury/modal_spec.js.coffee +53 -23
  39. data/spec/javascripts/mercury/modals/htmleditor_spec.js.coffee +0 -2
  40. data/spec/javascripts/mercury/modals/insertcharacter_spec.js.coffee +2 -3
  41. data/spec/javascripts/mercury/modals/insertlink_spec.js.coffee +0 -2
  42. data/spec/javascripts/mercury/modals/insertmedia_spec.js.coffee +2 -2
  43. data/spec/javascripts/mercury/modals/insertsnippet_spec.js.coffee +0 -2
  44. data/spec/javascripts/mercury/modals/inserttable_spec.js.coffee +2 -4
  45. data/spec/javascripts/mercury/native_extensions_spec.js.coffee +20 -2
  46. data/spec/javascripts/mercury/page_editor_spec.js.coffee +130 -35
  47. data/spec/javascripts/mercury/palette_spec.js.coffee +4 -6
  48. data/spec/javascripts/mercury/panel_spec.js.coffee +44 -6
  49. data/spec/javascripts/mercury/region_spec.js.coffee +42 -8
  50. data/spec/javascripts/mercury/regions/editable_spec.js.coffee +0 -2
  51. data/spec/javascripts/mercury/regions/markupable_spec.js.coffee +0 -2
  52. data/spec/javascripts/mercury/regions/snippetable_spec.js.coffee +3 -5
  53. data/spec/javascripts/mercury/select_spec.js.coffee +4 -6
  54. data/spec/javascripts/mercury/snippet_spec.js.coffee +3 -4
  55. data/spec/javascripts/mercury/snippet_toolbar_spec.js.coffee +2 -4
  56. data/spec/javascripts/mercury/statusbar_spec.js.coffee +0 -2
  57. data/spec/javascripts/mercury/table_editor_spec.js.coffee +2 -4
  58. data/spec/javascripts/mercury/toolbar.button_group_spec.js.coffee +0 -2
  59. data/spec/javascripts/mercury/toolbar.button_spec.js.coffee +34 -15
  60. data/spec/javascripts/mercury/toolbar.expander_spec.js.coffee +0 -2
  61. data/spec/javascripts/mercury/toolbar_spec.js.coffee +41 -26
  62. data/spec/javascripts/mercury/tooltip_spec.js.coffee +3 -5
  63. data/spec/javascripts/mercury/uploader_spec.js.coffee +8 -14
  64. data/spec/javascripts/spec_helper.js +1 -0
  65. data/spec/javascripts/templates/mercury/page_editor.html +1 -0
  66. data/spec/javascripts/templates/mercury/region.html +2 -2
  67. data/vendor/assets/images/mercury/missing-image.png +0 -0
  68. data/vendor/assets/javascripts/mercury.js +218 -112
  69. data/vendor/assets/javascripts/mercury/dependencies/{jquery-1.6.js → jquery-1.7.js} +2030 -1595
  70. data/vendor/assets/javascripts/mercury/dependencies/jquery.additions.js +55 -0
  71. data/vendor/assets/javascripts/mercury/dialog.js.coffee +7 -5
  72. data/vendor/assets/javascripts/mercury/dialogs/backcolor.js.coffee +1 -1
  73. data/vendor/assets/javascripts/mercury/dialogs/forecolor.js.coffee +1 -1
  74. data/vendor/assets/javascripts/mercury/dialogs/formatblock.js.coffee +1 -1
  75. data/vendor/assets/javascripts/mercury/dialogs/{objectspanel.js.coffee → snippetpanel.js.coffee} +2 -2
  76. data/vendor/assets/javascripts/mercury/dialogs/style.js.coffee +1 -1
  77. data/vendor/assets/javascripts/mercury/finalize.js.coffee +3 -0
  78. data/vendor/assets/javascripts/mercury/lightview.js.coffee +76 -30
  79. data/vendor/assets/javascripts/mercury/locales/da.locale.js.coffee +211 -0
  80. data/vendor/assets/javascripts/mercury/locales/de.locale.js.coffee +206 -0
  81. data/vendor/assets/javascripts/mercury/locales/es.locale.js.coffee +211 -0
  82. data/vendor/assets/javascripts/mercury/locales/example.local.js.coffee +211 -0
  83. data/vendor/assets/javascripts/mercury/locales/fr.locale.js.coffee +211 -0
  84. data/vendor/assets/javascripts/mercury/locales/it.locale.js.coffee +208 -0
  85. data/vendor/assets/javascripts/mercury/locales/ko.local.js.coffee +206 -0
  86. data/vendor/assets/javascripts/mercury/locales/nl.locale.js.coffee +206 -0
  87. data/vendor/assets/javascripts/mercury/locales/pt.locale.js.coffee +211 -0
  88. data/vendor/assets/javascripts/mercury/locales/sv.local.js.coffee +209 -0
  89. data/vendor/assets/javascripts/mercury/locales/swedish_chef.locale.js.coffee +213 -0
  90. data/vendor/assets/javascripts/mercury/mercury.js.coffee +62 -17
  91. data/vendor/assets/javascripts/mercury/modal.js.coffee +34 -21
  92. data/vendor/assets/javascripts/mercury/modals/htmleditor.js.coffee +1 -2
  93. data/vendor/assets/javascripts/mercury/modals/insertcharacter.js.coffee +3 -3
  94. data/vendor/assets/javascripts/mercury/modals/insertlink.js.coffee +4 -4
  95. data/vendor/assets/javascripts/mercury/modals/insertmedia.js.coffee +10 -9
  96. data/vendor/assets/javascripts/mercury/modals/insertsnippet.js.coffee +1 -1
  97. data/vendor/assets/javascripts/mercury/modals/inserttable.js.coffee +8 -9
  98. data/vendor/assets/javascripts/mercury/native_extensions.js.coffee +26 -8
  99. data/vendor/assets/javascripts/mercury/page_editor.js.coffee +68 -46
  100. data/vendor/assets/javascripts/mercury/palette.js.coffee +1 -1
  101. data/vendor/assets/javascripts/mercury/panel.js.coffee +25 -7
  102. data/vendor/assets/javascripts/mercury/plugins/save_as_xml/mercury/page_editor.js.coffee +1 -0
  103. data/vendor/assets/javascripts/mercury/region.js.coffee +21 -17
  104. data/vendor/assets/javascripts/mercury/regions/editable.js.coffee +47 -35
  105. data/vendor/assets/javascripts/mercury/regions/markupable.js.coffee +43 -36
  106. data/vendor/assets/javascripts/mercury/regions/snippetable.js.coffee +22 -24
  107. data/vendor/assets/javascripts/mercury/select.js.coffee +3 -2
  108. data/vendor/assets/javascripts/mercury/snippet.js.coffee +2 -1
  109. data/vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee +10 -7
  110. data/vendor/assets/javascripts/mercury/statusbar.js.coffee +4 -4
  111. data/vendor/assets/javascripts/mercury/table_editor.js.coffee +1 -3
  112. data/vendor/assets/javascripts/mercury/toolbar.button.js.coffee +42 -20
  113. data/vendor/assets/javascripts/mercury/toolbar.button_group.js.coffee +3 -3
  114. data/vendor/assets/javascripts/mercury/toolbar.expander.js.coffee +2 -2
  115. data/vendor/assets/javascripts/mercury/toolbar.js.coffee +8 -6
  116. data/vendor/assets/javascripts/mercury/tooltip.js.coffee +13 -9
  117. data/vendor/assets/javascripts/mercury/uploader.js.coffee +22 -16
  118. data/vendor/assets/javascripts/mercury_loader.js +2 -0
  119. data/vendor/assets/javascripts/mercury_overrides.js +6 -0
  120. data/vendor/assets/stylesheets/mercury/all_images.css.erb +89 -0
  121. data/vendor/assets/stylesheets/mercury/dialog.css +13 -4
  122. data/vendor/assets/stylesheets/mercury/lightview.css +66 -15
  123. data/vendor/assets/stylesheets/mercury/mercury.css +12 -7
  124. data/vendor/assets/stylesheets/mercury/modal.css +9 -5
  125. data/vendor/assets/stylesheets/mercury/toolbar.css +3 -29
  126. metadata +266 -144
  127. data/POST_INSTALL +0 -15
  128. data/README.md +0 -299
  129. data/VERSION +0 -1
  130. data/annotated_source.template +0 -57
  131. data/config/routes.rb +0 -15
  132. data/mercury-rails.gemspec +0 -288
  133. data/spec/javascripts/responses/blank.html +0 -1
  134. data/vendor/assets/javascripts/mercury/lightviews/imageprocessor.js.coffee +0 -2
@@ -15,23 +15,23 @@ Then /^(.+) should (not )?be visible$/ do |locator, boolean|
15
15
  end
16
16
 
17
17
  # scoping step for different windows
18
- When /^(.*) in the "([^"]*)" window$/ do |step, window|
18
+ When /^(.*) in the "([^"]*)" window$/ do |s, window|
19
19
  page.driver.within_window(window) do
20
- When(step)
20
+ step(s)
21
21
  end
22
22
  end
23
23
 
24
24
 
25
25
  ## Mercury general steps
26
26
  #------------------------------------------------------------------------------
27
- Given /^(?:|I )adjust the configuration to have: "([^"]*)"$/ do |javascript|
28
- Rails.application.config.mercury_config = javascript
27
+ Given /^(?:|I )adjust the configuration to have: \{([^\}]*)\}$/ do |javascript|
28
+ Rails.application.config.mercury_config = JSON.parse("{#{javascript}}")
29
29
  end
30
30
 
31
31
  # scoping step for the mercury content frame
32
- When /^(.*) in the content frame$/ do |step|
32
+ When /^(.*) in the content frame$/ do |s|
33
33
  page.driver.within_frame('mercury_iframe') do
34
- When(step)
34
+ step(s)
35
35
  end
36
36
  end
37
37
 
@@ -53,14 +53,14 @@ end
53
53
  ## Panel specific steps
54
54
  #------------------------------------------------------------------------------
55
55
  When /^(?:I )(?:open|close|toggle) the (.*?) panel$/ do |panel_locator|
56
- When(%Q{I click on the "#{panel_locator}" button})
56
+ step(%Q{I click on the "#{panel_locator}" button})
57
57
  end
58
58
 
59
59
 
60
60
  ## Modal specific steps
61
61
  #------------------------------------------------------------------------------
62
62
  When /^(?:I )close the modal(?: window)?$/ do
63
- When(%Q{I click on the modal close button})
63
+ step(%Q{I click on the modal close button})
64
64
  end
65
65
 
66
66
 
@@ -68,7 +68,7 @@ end
68
68
  #------------------------------------------------------------------------------
69
69
  # setting content
70
70
  Given /^the content of (.*?) (?:is|are|has|includes) (.*?)$/ do |region_locator, contents|
71
- When(%Q{I set the contents of #{region_locator} to #{contents}})
71
+ step(%Q{I set the contents of #{region_locator} to #{contents}})
72
72
  end
73
73
 
74
74
  When /^(?:|I )(?:change|set) the contents? of (.*?) to (.*?)$/ do |region_locator, contents|
@@ -90,11 +90,11 @@ end
90
90
 
91
91
  # setting/making selections
92
92
  When /^(?:|I )(?:make|have) a selection$/ do
93
- When(%Q{I have a selection for "span"})
93
+ step(%Q{I have a selection for "span"})
94
94
  end
95
95
 
96
96
  When /^(?:|I )(?:make|have) a selection (?:in (.*?) )?for "([^"]*)"$/ do |region_locator, selector|
97
- Given(%Q{I can simulate complex javascript events})
97
+ step(%Q{I can simulate complex javascript events})
98
98
  # assume the first editable region if one wasn't provided'
99
99
  region_selector = region_selector_for(region_locator || 'the editable region')
100
100
  page.driver.within_frame('mercury_iframe') do
@@ -117,7 +117,7 @@ end
117
117
 
118
118
  # other events
119
119
  When /^(?:|I )double click on (.*?) in (.*?)$/ do |locator, region_locator|
120
- Given(%Q{I can simulate complex javascript events})
120
+ step(%Q{I can simulate complex javascript events})
121
121
  selector = selector_for(locator)
122
122
  # assume the first editable region if one wasn't provided'
123
123
  region_selector = region_selector_for(region_locator || 'the editable region')
@@ -153,11 +153,8 @@ end
153
153
  # caching for the last save -- a request will still be made
154
154
  Given /^save results will be cached$/ do
155
155
  page.driver.execute_script <<-JAVASCRIPT
156
- Mercury.PageEditor.prototype.oldSerialize = Mercury.PageEditor.prototype.serialize;
157
- Mercury.PageEditor.prototype.serialize = function() {
158
- results = this.oldSerialize.call(this, arguments);
159
- window.cachedResults = results;
160
- return results;
156
+ Mercury.PageEditor.prototype.save = function() {
157
+ window.cachedResults = this.serialize();
161
158
  }
162
159
  JAVASCRIPT
163
160
  end
@@ -179,17 +176,17 @@ end
179
176
  # in the modal window
180
177
  When /^(?:|I )(?:add|insert) a (row|column) (before|after)(?: it)?$/ do |row_or_column, before_or_after|
181
178
  name = "insert_#{row_or_column}_#{before_or_after}".camelcase(:lower)
182
- When(%Q{I click on ".mercury-modal-content input[name=#{name}]"})
179
+ step(%Q{I click on ".mercury-modal-content input[name=#{name}]"})
183
180
  end
184
181
 
185
182
  When /^(?:|I )delete the(?: current)? (row|column)$/ do |row_or_column|
186
183
  name = "delete_#{row_or_column}".camelcase(:lower)
187
- When(%Q{I click on ".mercury-modal-content input[name=#{name}]"})
184
+ step(%Q{I click on ".mercury-modal-content input[name=#{name}]"})
188
185
  end
189
186
 
190
187
  When /^(?:|I )(increase|decrease) the (rowspan|colspan)$/ do |increase_or_decrease, rowspan_or_colspan|
191
188
  name = "#{increase_or_decrease}_#{rowspan_or_colspan}".camelcase(:lower)
192
- When(%Q{I click on ".mercury-modal-content input[name=#{name}]"})
189
+ step(%Q{I click on ".mercury-modal-content input[name=#{name}]"})
193
190
  end
194
191
 
195
192
  Then /^the selected cell should be (.*?)$/ do |locator|
@@ -238,7 +235,7 @@ When /^(?:|I )(?:drag|drop) (.*?) (?:into|on) (.*?)$/ do |snippet_locator, regio
238
235
  end
239
236
 
240
237
  When /^(?:|I )hover over (.*?)(?: in (.*?))?$/ do |locator, region_locator|
241
- Given(%Q{I can simulate complex javascript events})
238
+ step(%Q{I can simulate complex javascript events})
242
239
  selector = selector_for(locator)
243
240
  region_selector = region_selector_for(region_locator || 'the editable region')
244
241
  page.driver.within_frame('mercury_iframe') do
@@ -256,8 +253,8 @@ When /^(?:|I )hover over (.*?)(?: in (.*?))?$/ do |locator, region_locator|
256
253
  end
257
254
 
258
255
  When /^(?:|I )edit the snippet$/ do
259
- When(%{I hover over the snippet})
260
- And(%{click on the edit snippet settings toolbar button})
256
+ step(%{I hover over the snippet})
257
+ step(%{click on the edit snippet settings toolbar button})
261
258
  end
262
259
 
263
260
 
@@ -32,13 +32,13 @@ end
32
32
  World(WithinHelpers)
33
33
 
34
34
  # Single-line step scoper
35
- When /^(.*) within ([^:]+)$/ do |step, parent|
36
- with_scope(parent) { When step }
35
+ When /^(.*) within ([^:]+)$/ do |s, parent|
36
+ with_scope(parent) { step(s) }
37
37
  end
38
38
 
39
39
  # Multi-line step scoper
40
- When /^(.*) within ([^:]+):$/ do |step, parent, table_or_string|
41
- with_scope(parent) { When "#{step}:", table_or_string }
40
+ When /^(.*) within ([^:]+):$/ do |s, parent, table_or_string|
41
+ with_scope(parent) { step "#{s}:", table_or_string }
42
42
  end
43
43
 
44
44
  Given /^(?:|I )am on (.+)$/ do |page_name|
@@ -78,7 +78,7 @@ end
78
78
  #
79
79
  When /^(?:|I )fill in the following:$/ do |fields|
80
80
  fields.rows_hash.each do |name, value|
81
- When %{I fill in "#{name}" with "#{value}"}
81
+ step %{I fill in "#{name}" with "#{value}"}
82
82
  end
83
83
  end
84
84
 
@@ -54,6 +54,7 @@ module MercurySelectorsHelpers
54
54
  when 'the lightview', 'the lightview window', /^the (.*?) lightview$/ then '.mercury-lightview'
55
55
  when 'the lightview overlay' then '.mercury-lightview-overlay'
56
56
  when 'the lightview title' then '.mercury-lightview h1.mercury-lightview-title'
57
+ when 'the lightview close button' then '.mercury-lightview h1.mercury-lightview-title a'
57
58
 
58
59
  # snippet selectors
59
60
  when 'the snippet toolbar' then '.mercury-snippet-toolbar'
@@ -5,22 +5,43 @@ module Mercury
5
5
 
6
6
  desc "Installs Mercury into your application by copying the configuration file."
7
7
 
8
- class_option :full, :type => :boolean, :aliases => "-f",
8
+ class_option :orm, :default => 'active_record', :banner => 'mongoid',
9
+ :desc => 'ORM for required models -- active_record, or mongoid'
10
+
11
+ class_option :full, :type => :boolean, :aliases => '-g',
9
12
  :desc => 'Full installation will install the layout and css overrides for easier customization.'
10
13
 
11
14
  def copy_config
12
15
  copy_file 'vendor/assets/javascripts/mercury.js', 'app/assets/javascripts/mercury.js'
13
16
  end
14
17
 
15
- def copy_layout_and_css_overrides
18
+ def add_routes
19
+ route %Q{Mercury::Engine.routes}
20
+ end
21
+
22
+ def copy_models
23
+ if options[:orm] == 'mongoid'
24
+ copy_file 'lib/generators/mercury/install/templates/mongoid_paperclip_image.rb', 'app/models/mercury/image.rb'
25
+ else
26
+ copy_file 'app/models/mercury/image.rb' if options[:full]
27
+ end
28
+ end
29
+
30
+ def copy_layout_and_css_overrides
16
31
  if options[:full] || yes?("Install the layout and CSS overrides files? [yN]")
17
32
  copy_file 'app/views/layouts/mercury.html.erb', 'app/views/layouts/mercury.html.erb'
18
33
  copy_file 'vendor/assets/stylesheets/mercury_overrides.css', 'app/assets/stylesheets/mercury_overrides.css'
19
34
  end
20
35
  end
21
36
 
37
+ def copy_authentication_overrides
38
+ if options[:full] || yes?("Install the authentication file so you can restrict access to editing? [yN]")
39
+ copy_file 'lib/mercury/authentication.rb'
40
+ end
41
+ end
42
+
22
43
  def display_readme
23
- readme 'POST_INSTALL'
44
+ readme 'POST_INSTALL' if behavior == :invoke
24
45
  end
25
46
 
26
47
  end
@@ -0,0 +1,17 @@
1
+ class Mercury::Image
2
+ include Mongoid::Document
3
+ include Mongoid::Paperclip
4
+
5
+ has_mongoid_attached_file :image
6
+
7
+ validates_presence_of :image
8
+
9
+ delegate :url, :to => :image
10
+
11
+ def serializable_hash(options = nil)
12
+ options ||= {}
13
+ options[:methods] ||= []
14
+ options[:methods] << :url
15
+ super(options)
16
+ end
17
+ end
@@ -1,4 +1,3 @@
1
1
  require 'paperclip'
2
- require 'formtastic'
3
2
 
4
3
  require File.expand_path('../config/engine', File.dirname(__FILE__))
@@ -0,0 +1,8 @@
1
+ module Mercury
2
+ module Authentication
3
+
4
+ def can_edit?
5
+ true # check here to see if the user is logged in/has access
6
+ end
7
+ end
8
+ end
@@ -1,15 +1,17 @@
1
- require '/assets/mercury.js'
2
-
3
1
  describe "Mercury.Dialog", ->
4
2
 
5
3
  template 'mercury/dialog.html'
6
4
 
7
5
  beforeEach ->
8
6
  $.fx.off = true
7
+ Mercury.determinedLocale =
8
+ top: {'hello world!': 'bork! bork!'}
9
+ sub: {'foo': 'Bork!'}
9
10
 
10
11
  afterEach ->
11
- @dialog = null
12
12
  delete(@dialog)
13
+ Mercury.config.localization.enabled = false
14
+
13
15
 
14
16
  describe "constructor", ->
15
17
 
@@ -19,12 +21,12 @@ describe "Mercury.Dialog", ->
19
21
  @preloadSpy = spyOn(Mercury.Dialog.prototype, 'preload').andCallFake(=>)
20
22
 
21
23
  it "expects a url and name", ->
22
- @dialog = new Mercury.Dialog('/evergreen/responses/blank.html', 'foo')
23
- expect(@dialog.url).toEqual('/evergreen/responses/blank.html')
24
+ @dialog = new Mercury.Dialog('/blank.html', 'foo')
25
+ expect(@dialog.url).toEqual('/blank.html')
24
26
  expect(@dialog.name).toEqual('foo')
25
27
 
26
28
  it "accepts options", ->
27
- @dialog = new Mercury.Dialog('/evergreen/responses/blank.html', 'foo', {for: 'something', foo: 'bar'})
29
+ @dialog = new Mercury.Dialog('/blank.html', 'foo', {for: 'something', foo: 'bar'})
28
30
  expect(@dialog.options).toEqual({for: 'something', foo: 'bar'})
29
31
 
30
32
  it "calls build", ->
@@ -47,13 +49,13 @@ describe "Mercury.Dialog", ->
47
49
  @preloadSpy = spyOn(Mercury.Dialog.prototype, 'preload').andCallFake(=>)
48
50
 
49
51
  it "builds an element", ->
50
- @dialog = new Mercury.Dialog('/evergreen/responses/blank.html', 'foo', {appendTo: '#test'})
52
+ @dialog = new Mercury.Dialog('/blank.html', 'foo', {appendTo: '#test'})
51
53
  html = $('<div>').html(@dialog.element).html()
52
54
  expect(html).toContain('class="mercury-dialog mercury-foo-dialog loading"')
53
55
  expect(html).toContain('style="display:none"')
54
56
 
55
57
  it "appends to any element", ->
56
- @dialog = new Mercury.Dialog('/evergreen/responses/blank.html', 'foo', {appendTo: '#dialog_container'})
58
+ @dialog = new Mercury.Dialog('/blank.html', 'foo', {appendTo: '#dialog_container'})
57
59
  expect($('#dialog_container .mercury-dialog').length).toEqual(1)
58
60
 
59
61
 
@@ -68,18 +70,18 @@ describe "Mercury.Dialog", ->
68
70
  @loadSpy = spyOn(Mercury.Dialog.prototype, 'load').andCallFake(=>)
69
71
 
70
72
  it "calls load if configured", ->
71
- @dialog = new Mercury.Dialog('/evergreen/responses/blank.html', 'foo', {appendTo: '#test', preload: true})
73
+ @dialog = new Mercury.Dialog('/blank.html', 'foo', {appendTo: '#test', preload: true})
72
74
  expect(@loadSpy.callCount).toEqual(1)
73
75
 
74
76
  it "doesn't call load if configured", ->
75
- @dialog = new Mercury.Dialog('/evergreen/responses/blank.html', 'foo', {appendTo: '#test', preload: false})
77
+ @dialog = new Mercury.Dialog('/blank.html', 'foo', {appendTo: '#test', preload: false})
76
78
  expect(@loadSpy.callCount).toEqual(0)
77
79
 
78
80
 
79
81
  describe "#toggle", ->
80
82
 
81
83
  beforeEach ->
82
- @dialog = new Mercury.Dialog('/evergreen/responses/blank.html', 'foo', {appendTo: '#test'})
84
+ @dialog = new Mercury.Dialog('/blank.html', 'foo', {appendTo: '#test'})
83
85
 
84
86
  it "shows or hides", ->
85
87
  expect(@dialog.element.css('display')).toEqual('none')
@@ -92,7 +94,7 @@ describe "Mercury.Dialog", ->
92
94
  describe "#resize", ->
93
95
 
94
96
  beforeEach ->
95
- @dialog = new Mercury.Dialog('/evergreen/responses/blank.html', 'foo', {appendTo: '#test'})
97
+ @dialog = new Mercury.Dialog('/blank.html', 'foo', {appendTo: '#test'})
96
98
 
97
99
  it "calls show", ->
98
100
  spy = spyOn(Mercury.Dialog.prototype, 'show').andCallFake(=>)
@@ -103,7 +105,7 @@ describe "Mercury.Dialog", ->
103
105
  describe "#show", ->
104
106
 
105
107
  beforeEach ->
106
- @dialog = new Mercury.Dialog('/evergreen/responses/blank.html', 'foo', {appendTo: '#test'})
108
+ @dialog = new Mercury.Dialog('/blank.html', 'foo', {appendTo: '#test'})
107
109
 
108
110
  it "triggers a custom event to hide all other dialogs", ->
109
111
  spy = spyOn(Mercury, 'trigger').andCallFake(=>)
@@ -155,7 +157,7 @@ describe "Mercury.Dialog", ->
155
157
  describe "#appear", ->
156
158
 
157
159
  beforeEach ->
158
- @dialog = new Mercury.Dialog('/evergreen/responses/blank.html', 'foo', {appendTo: '#test'})
160
+ @dialog = new Mercury.Dialog('/blank.html', 'foo', {appendTo: '#test'})
159
161
 
160
162
  it "animates the dialog in", ->
161
163
  @dialog.appear()
@@ -168,7 +170,7 @@ describe "Mercury.Dialog", ->
168
170
  describe "#hide", ->
169
171
 
170
172
  beforeEach ->
171
- @dialog = new Mercury.Dialog('/evergreen/responses/blank.html', 'foo', {appendTo: '#test'})
173
+ @dialog = new Mercury.Dialog('/blank.html', 'foo', {appendTo: '#test'})
172
174
 
173
175
  it "hides the dialog", ->
174
176
  @dialog.element.css({display: 'block'})
@@ -182,7 +184,7 @@ describe "Mercury.Dialog", ->
182
184
  beforeEach ->
183
185
  @spyFunction = ->
184
186
  Mercury.dialogHandlers.foo = ->
185
- @dialog = new Mercury.Dialog('/evergreen/responses/blank.html', 'foo', {appendTo: '#test', for: $('#button')})
187
+ @dialog = new Mercury.Dialog('/blank.html', 'foo', {appendTo: '#test', for: $('#button')})
186
188
 
187
189
  it "does nothing if there's no url", ->
188
190
  spy = spyOn($, 'ajax').andCallFake(=>)
@@ -193,7 +195,7 @@ describe "Mercury.Dialog", ->
193
195
  describe "on a preloaded view", ->
194
196
 
195
197
  beforeEach ->
196
- Mercury.preloadedViews = {'/evergreen/responses/blank.html': 'this is the preloaded content'}
198
+ Mercury.preloadedViews = {'/blank.html': 'this is the preloaded content'}
197
199
 
198
200
  afterEach ->
199
201
  Mercury.preloadedViews = {}
@@ -253,13 +255,13 @@ describe "Mercury.Dialog", ->
253
255
  it "alerts the user", ->
254
256
  @dialog.load()
255
257
  expect(@alertSpy.callCount).toEqual(1)
256
- expect(@alertSpy.argsForCall[0]).toEqual(['Mercury was unable to load /evergreen/responses/blank.html for the foo dialog.'])
258
+ expect(@alertSpy.argsForCall[0]).toEqual(['Mercury was unable to load /blank.html for the "foo" dialog.'])
257
259
 
258
260
 
259
261
  describe "#loadContent", ->
260
262
 
261
263
  beforeEach ->
262
- @dialog = new Mercury.Dialog('/evergreen/responses/blank.html', 'foo', {appendTo: '#test'})
264
+ @dialog = new Mercury.Dialog('/blank.html', 'foo', {appendTo: '#test'})
263
265
 
264
266
  it "sets loaded to be true", ->
265
267
  @dialog.loadContent()
@@ -270,5 +272,10 @@ describe "Mercury.Dialog", ->
270
272
  expect(@dialog.element.hasClass('loading')).toEqual(false)
271
273
 
272
274
  it "sets the element html to be the data passed to it", ->
273
- @dialog.loadContent('hello world!')
274
- expect(@dialog.element.html()).toEqual('hello world!')
275
+ @dialog.loadContent('<span>hello world!</span>')
276
+ expect(@dialog.element.html()).toEqual('<span>hello world!</span>')
277
+
278
+ it "translates the content if configured", ->
279
+ Mercury.config.localization.enabled = true
280
+ @dialog.loadContent('<span>hello world!</span>')
281
+ expect(@dialog.element.html()).toEqual('<span>bork! bork!</span>')
@@ -1,5 +1,3 @@
1
- require '/assets/mercury.js'
2
-
3
1
  describe "Mercury.dialogHandlers.backColor", ->
4
2
 
5
3
  template 'mercury/dialogs/backcolor.html'
@@ -1,5 +1,3 @@
1
- require '/assets/mercury.js'
2
-
3
1
  describe "Mercury.dialogHandlers.foreColor", ->
4
2
 
5
3
  template 'mercury/dialogs/forecolor.html'
@@ -1,5 +1,3 @@
1
- require '/assets/mercury.js'
2
-
3
1
  describe "Mercury.dialogHandlers.formatblock", ->
4
2
 
5
3
  template 'mercury/dialogs/formatblock.html'
@@ -1,5 +1,3 @@
1
- require '/assets/mercury.js'
2
-
3
1
  describe "Mercury.dialogHandlers.snippetPanel", ->
4
2
 
5
3
  template 'mercury/dialogs/snippetpanel.html'
@@ -1,5 +1,3 @@
1
- require '/assets/mercury.js'
2
-
3
1
  describe "Mercury.dialogHandlers.style", ->
4
2
 
5
3
  template 'mercury/dialogs/style.html'
@@ -1,5 +1,3 @@
1
- require '/assets/mercury.js'
2
-
3
1
  describe "Mercury.HistoryBuffer", ->
4
2
 
5
3
  beforeEach ->
@@ -1,5 +1,3 @@
1
- require '/assets/mercury.js'
2
-
3
1
  describe "Mercury.lightview", ->
4
2
 
5
3
  template 'mercury/lightview.html'
@@ -7,8 +5,12 @@ describe "Mercury.lightview", ->
7
5
  beforeEach ->
8
6
  $.fx.off = true
9
7
  Mercury.displayRect = {fullHeight: 200, width: 1000}
8
+ Mercury.determinedLocale =
9
+ top: {'hello world!': 'bork! bork!'}
10
+ sub: {'foo': 'Bork!'}
10
11
 
11
12
  afterEach ->
13
+ Mercury.config.localization.enabled = false
12
14
  Mercury.lightview.initialized = false
13
15
  Mercury.lightview.visible = false
14
16
  $(window).unbind('mercury:refresh')
@@ -114,11 +116,6 @@ describe "Mercury.lightview", ->
114
116
  expect($('#lightview_container .mercury-lightview').length).toEqual(1)
115
117
  expect($('#lightview_container .mercury-lightview-overlay').length).toEqual(1)
116
118
 
117
- it "updates the title to reflect what was passed in the options", ->
118
- Mercury.lightview.options.title = 'title'
119
- Mercury.lightview.build()
120
- expect($('#test .mercury-lightview-title span').html()).toEqual('title')
121
-
122
119
  it "creates a close button if asked to in the options", ->
123
120
  Mercury.lightview.options.closeButton = true
124
121
  Mercury.lightview.build()
@@ -189,6 +186,17 @@ describe "Mercury.lightview", ->
189
186
  jasmine.simulate.click($('.mercury-lightview-overlay').get(0))
190
187
  expect(spy.callCount).toEqual(0)
191
188
 
189
+ describe "ajax:beforeSend", ->
190
+
191
+ it "sets a success that will load the contents of the response", ->
192
+ options = {}
193
+ spy = spyOn(Mercury.lightview, 'loadContent').andCallFake(=>)
194
+ Mercury.lightview.element.trigger('ajax:beforeSend', [null, options])
195
+ expect(options.success).toBeDefined()
196
+ options.success('new content')
197
+ expect(spy.callCount).toEqual(1)
198
+ expect(spy.argsForCall[0]).toEqual(['new content'])
199
+
192
200
 
193
201
  describe "#appear", ->
194
202
 
@@ -197,7 +205,7 @@ describe "Mercury.lightview", ->
197
205
  spyOn(Mercury.lightview, 'update').andCallFake(=>)
198
206
  @loadSpy = spyOn(Mercury.lightview, 'load').andCallFake(=>)
199
207
  @positionSpy = spyOn(Mercury.lightview, 'position').andCallFake(=>)
200
- Mercury.lightview('/evergreen/responses/blank.html', {appendTo: $('#test')})
208
+ Mercury.lightview('/blank.html', {appendTo: $('#test')})
201
209
 
202
210
  it "calls position", ->
203
211
  Mercury.lightview.appear()
@@ -242,7 +250,13 @@ describe "Mercury.lightview", ->
242
250
 
243
251
  beforeEach ->
244
252
  spyOn(Mercury.lightview, 'appear').andCallFake(=>)
245
- Mercury.lightview('/evergreen/responses/blank.html', {appendTo: $('#test')})
253
+ Mercury.lightview('/blank.html', {appendTo: $('#test')})
254
+ Mercury.lightview.contentPane = $()
255
+
256
+ it "will keep the content element visible if asked to do so", ->
257
+ $('.mercury-lightview-content').css('visibility', 'visible')
258
+ Mercury.lightview.resize(true)
259
+ expect($('.mercury-lightview-content').css('visibility')).toEqual('visible')
246
260
 
247
261
  it "resizes the element and adjusts it's position when empty", ->
248
262
  $('.mercury-lightview').css({display: 'block', visibility: 'visible', top: 0})
@@ -255,8 +269,8 @@ describe "Mercury.lightview", ->
255
269
  Mercury.lightview.loadContent('<div style="width:600px;height:400px"></div>')
256
270
  $('.mercury-lightview').css({display: 'block', visibility: 'visible', top: 0})
257
271
  Mercury.lightview.resize()
258
- expect($('.mercury-lightview').width()).toEqual(642)
259
- expect($('.mercury-lightview').offset()).toEqual({top: 20, left: 179})
272
+ expect($('.mercury-lightview').width()).toEqual(300)
273
+ expect($('.mercury-lightview').offset()).toEqual({top: 20, left: 350})
260
274
  expect($('.mercury-lightview').height()).toEqual(180)
261
275
 
262
276
 
@@ -292,7 +306,7 @@ describe "Mercury.lightview", ->
292
306
  beforeEach ->
293
307
  spyOn(Mercury.lightview, 'appear').andCallFake(=>)
294
308
  @ajaxSpy = spyOn($, 'ajax')
295
- Mercury.lightview('/evergreen/responses/blank.html', {appendTo: $('#test')})
309
+ Mercury.lightview('/blank.html', {appendTo: $('#test')})
296
310
 
297
311
  it "does nothing if there's no url", ->
298
312
  Mercury.lightview.url = null
@@ -312,8 +326,8 @@ describe "Mercury.lightview", ->
312
326
  describe "on a preloaded view", ->
313
327
 
314
328
  beforeEach ->
315
- @setTimeoutSpy = spyOn(window, 'setTimeout').andCallFake((callback) => callback())
316
- Mercury.preloadedViews = {'/evergreen/responses/blank.html': 'this is the preloaded content'}
329
+ @setTimeoutSpy = spyOn(window, 'setTimeout').andCallFake((timeout, callback) => callback())
330
+ Mercury.preloadedViews = {'/blank.html': 'this is the preloaded content'}
317
331
 
318
332
  afterEach ->
319
333
  Mercury.preloadedViews = {}
@@ -328,8 +342,10 @@ describe "Mercury.lightview", ->
328
342
 
329
343
  it "makes an ajax request", ->
330
344
  @ajaxSpy.andCallFake(=>)
345
+ spyOn(Mercury, 'ajaxHeaders').andCallFake(=> {'X-CSRFToken': 'f00'})
331
346
  Mercury.lightview.load()
332
347
  expect(@ajaxSpy.callCount).toEqual(1)
348
+ expect(@ajaxSpy.argsForCall[0][1]['headers']).toEqual({'X-CSRFToken': 'f00'})
333
349
 
334
350
  describe "on success", ->
335
351
 
@@ -358,7 +374,7 @@ describe "Mercury.lightview", ->
358
374
  spy = spyOn(window, 'alert').andCallFake(=>)
359
375
  Mercury.lightview.load()
360
376
  expect(spy.callCount).toEqual(1)
361
- expect(spy.argsForCall[0]).toEqual(['Mercury was unable to load /evergreen/responses/blank.html for the lightview.'])
377
+ expect(spy.argsForCall[0]).toEqual(['Mercury was unable to load /blank.html for the lightview.'])
362
378
 
363
379
 
364
380
  describe "#loadContent", ->
@@ -366,7 +382,7 @@ describe "Mercury.lightview", ->
366
382
  beforeEach ->
367
383
  spyOn(Mercury.lightview, 'appear').andCallFake(=>)
368
384
  @resizeSpy = spyOn(Mercury.lightview, 'resize').andCallFake(=>)
369
- Mercury.lightview('/evergreen/responses/blank.html', {appendTo: $('#test'), title: 'title'})
385
+ Mercury.lightview('/blank.html', {appendTo: $('#test'), title: 'title'})
370
386
 
371
387
  it "accepts options and sets them to the instance options", ->
372
388
  Mercury.lightview.loadContent('content', {title: 'title'})
@@ -393,8 +409,8 @@ describe "Mercury.lightview", ->
393
409
  expect($('.mercury-lightview').hasClass('loading')).toEqual(false)
394
410
 
395
411
  it "sets the content elements html to whatever was passed", ->
396
- Mercury.lightview.loadContent('content')
397
- expect($('.mercury-lightview-content').html()).toEqual('content')
412
+ Mercury.lightview.loadContent('<span>content</span>')
413
+ expect($('.mercury-lightview-content').html()).toEqual('<span>content</span>')
398
414
 
399
415
  it "hides the contentElement", ->
400
416
  $('.mercury-lightview-content').css('display', 'block')
@@ -413,6 +429,11 @@ describe "Mercury.lightview", ->
413
429
  Mercury.lightview.loadContent('content', {handler: 'foo'})
414
430
  expect(callCount).toEqual(1)
415
431
 
432
+ it "translates the content if configured", ->
433
+ Mercury.config.localization.enabled = true
434
+ Mercury.lightview.loadContent('<span>foo</span>')
435
+ expect($('.mercury-lightview-content').html()).toEqual('<span>Bork!</span>')
436
+
416
437
  it "calls resize", ->
417
438
  Mercury.lightview.loadContent('content')
418
439
  expect(@resizeSpy.callCount).toEqual(1)
@@ -422,7 +443,7 @@ describe "Mercury.lightview", ->
422
443
 
423
444
  beforeEach ->
424
445
  spyOn(Mercury.lightview, 'appear').andCallFake(=>)
425
- Mercury.lightview('/evergreen/responses/blank.html', {appendTo: $('#test'), title: 'title'})
446
+ Mercury.lightview('/blank.html', {appendTo: $('#test'), title: 'title'})
426
447
 
427
448
  it "sets the the title contents to what was provided in the options", ->
428
449
  Mercury.lightview.options = {title: 'new title'}
@@ -434,7 +455,7 @@ describe "Mercury.lightview", ->
434
455
 
435
456
  beforeEach ->
436
457
  spyOn(Mercury.lightview, 'appear').andCallFake(=>)
437
- Mercury.lightview('/evergreen/responses/blank.html', {appendTo: $('#test'), title: 'title'})
458
+ Mercury.lightview('/blank.html', {appendTo: $('#test'), title: 'title'})
438
459
 
439
460
  it "clears the title and content elements", ->
440
461
  $('.mercury-lightview-content').html('content')
@@ -447,7 +468,7 @@ describe "Mercury.lightview", ->
447
468
 
448
469
  beforeEach ->
449
470
  spyOn(Mercury.lightview, 'appear').andCallFake(=>)
450
- Mercury.lightview('/evergreen/responses/blank.html', {appendTo: $('#test')})
471
+ Mercury.lightview('/blank.html', {appendTo: $('#test')})
451
472
 
452
473
  it "triggers the focus:frame event", ->
453
474
  spy = spyOn(Mercury, 'trigger').andCallFake(=>)