From 6dbe4ac4add3104cb4f714e1e3513e3ec06bb0fd Mon Sep 17 00:00:00 2001 From: jejacks0n Date: Sun, 18 Mar 2012 14:28:26 -0600 Subject: [PATCH] added (name)-snippet class to snippets, so they can be styled easier by type -- fixes #176 --- .../regions/editable/inserting_snippets.feature | 14 +++++++------- .../mercury/regions/snippetable_spec.js.coffee | 2 +- spec/javascripts/mercury/snippet_spec.js.coffee | 2 +- .../assets/javascripts/mercury/snippet.js.coffee | 9 ++++++--- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/features/regions/editable/inserting_snippets.feature b/features/regions/editable/inserting_snippets.feature index a94bea78..a6a7d137 100644 --- a/features/regions/editable/inserting_snippets.feature +++ b/features/regions/editable/inserting_snippets.feature @@ -25,7 +25,7 @@ Feature: And fill in "Favorite Beer" with "Stella" And press "Insert Snippet" Then the modal window should not be visible - And the contents of the editable region should be "this is
Jeremy likes Stella
simple content" + And the contents of the editable region should be "this is
Jeremy likes Stella
simple content" Scenario: A user can use the snippet toolbar to remove a snippet @@ -52,7 +52,7 @@ Feature: When I fill in "First Name" with "Jeremy" And fill in "Favorite Beer" with "Stella" And press "Insert Snippet" - Then the contents of the editable region should be "
Jeremy likes Stella
content" + Then the contents of the editable region should be "
Jeremy likes Stella
content" Scenario: A user can make changes to a snippets options, and they'll be versioned for undo and redo @@ -63,7 +63,7 @@ Feature: And I fill in "First Name" with "Jeremy" And fill in "Favorite Beer" with "Stella" And press "Insert Snippet" - Then the contents of the editable region should be "
Jeremy likes Stella
content" + Then the contents of the editable region should be "
Jeremy likes Stella
content" When I edit the snippet Then the "First Name" field should contain "Jeremy" @@ -72,10 +72,10 @@ Feature: When fill in "First Name" with "Diesel" And fill in "Favorite Beer" with "Bells Hopslam" And press "Insert Snippet" - Then the content of the editable region should be "
Diesel likes Bells Hopslam
content" + Then the content of the editable region should be "
Diesel likes Bells Hopslam
content" When I click on the "Undo" button - Then the contents of the editable region should be "
Jeremy likes Stella
content" + Then the contents of the editable region should be "
Jeremy likes Stella
content" When I edit the snippet # todo: this is a bug @@ -84,7 +84,7 @@ Feature: When I close the modal When I click on the "Redo" button - Then the contents of the editable region should be "
Diesel likes Bells Hopslam
content" + Then the contents of the editable region should be "
Diesel likes Bells Hopslam
content" When I edit the snippet Then the "First Name" field should contain "Diesel" @@ -93,7 +93,7 @@ Feature: When I fill in "First Name" with "Jen" And fill in "Favorite Beer" with "Miller High Life" And press "Insert Snippet" - Then the contents of the editable region should be "
Jen likes Miller High Life
content" + Then the contents of the editable region should be "
Jen likes Miller High Life
content" # Scenario: When a user saves, the snippets should be gone from the html, but the options are serialized diff --git a/spec/javascripts/mercury/regions/snippetable_spec.js.coffee b/spec/javascripts/mercury/regions/snippetable_spec.js.coffee index 0c64b031..d63eab4c 100644 --- a/spec/javascripts/mercury/regions/snippetable_spec.js.coffee +++ b/spec/javascripts/mercury/regions/snippetable_spec.js.coffee @@ -312,7 +312,7 @@ describe "Mercury.Regions.Snippetable.actions", -> it "finds the snippet by it's identity and replaces it with the new snippet", -> @actions['insertSnippet'].call(@region, {value: Mercury.Snippet.find('snippet_1')}) - expect($('#snippetable_region2').html()).toContain('class="mercury-snippet"') + expect($('#snippetable_region2').html()).toContain('class="mercury-snippet example-snippet"') expect($('#snippetable_region2').html()).toContain('contenteditable="false"') expect($('#snippetable_region2').html()).toContain('data-version="1"') expect($('#snippetable_region2').html()).toContain('data-snippet="snippet_1"') diff --git a/spec/javascripts/mercury/snippet_spec.js.coffee b/spec/javascripts/mercury/snippet_spec.js.coffee index 9f0ac5e6..31a07c3a 100644 --- a/spec/javascripts/mercury/snippet_spec.js.coffee +++ b/spec/javascripts/mercury/snippet_spec.js.coffee @@ -35,7 +35,7 @@ describe "Mercury.Snippet", -> it "builds an element (in whatever context is provided", -> ret = @snippet.getHTML($(document)) html = $('
').html(ret).html() - expect(html).toContain('class="mercury-snippet"') + expect(html).toContain('class="mercury-snippet foo-snippet"') expect(html).toContain('contenteditable="false"') expect(html).toContain('data-snippet="identity"') expect(html).toContain('data-version="1"') diff --git a/vendor/assets/javascripts/mercury/snippet.js.coffee b/vendor/assets/javascripts/mercury/snippet.js.coffee index d36be846..261b4f22 100644 --- a/vendor/assets/javascripts/mercury/snippet.js.coffee +++ b/vendor/assets/javascripts/mercury/snippet.js.coffee @@ -44,9 +44,12 @@ class @Mercury.Snippet getHTML: (context, callback = null) -> - element = jQuery('
', context) - element.attr({'data-snippet': @identity}) - element.attr({'data-version': @version}) + element = jQuery('
', { + class: "mercury-snippet #{@name}-snippet" + contenteditable: "false" + 'data-snippet': @identity + 'data-version': @version + }, context) element.html("[#{@identity}]") @loadPreview(element, callback) return element