From 60c48f4f2e3398880bd7307ba4c8edeb61fc6c76 Mon Sep 17 00:00:00 2001 From: Mario Visic Date: Thu, 2 Jun 2011 21:15:11 +0800 Subject: [PATCH 1/6] Added a failing feature for updating a snippet --- features/admin/snippets.feature | 25 ++++++++++++++++++++++ features/step_definitions/snippet_steps.rb | 7 ++++++ 2 files changed, 32 insertions(+) create mode 100644 features/admin/snippets.feature diff --git a/features/admin/snippets.feature b/features/admin/snippets.feature new file mode 100644 index 00000000..84c30a3b --- /dev/null +++ b/features/admin/snippets.feature @@ -0,0 +1,25 @@ +Feature: Snippets + In order to manage snippets + As an administrator + I want to add/edit/delete snippets of my site + +Background: + Given I have the site: "test site" set up + And I am an authenticated user + And a snippet named "yield" with the template: + """ + HELLO WORLD ! + """ + +Scenario: Updating a Snippet that includes another snippet + And a page named "snippet-test" with the template: + """ + {% include 'yield' %} + """ + When I go to theme assets + And I follow "yield" + And I fill in "snippet_template" with "{% include 'other' %}" + And I press "Update" + Then I should see "Snippet was successfully updated." + And I should have "{% include 'other' %}" in the yield snippet + Then show me the page diff --git a/features/step_definitions/snippet_steps.rb b/features/step_definitions/snippet_steps.rb index 440ecc96..830d9e40 100644 --- a/features/step_definitions/snippet_steps.rb +++ b/features/step_definitions/snippet_steps.rb @@ -13,4 +13,11 @@ Given /^a snippet named "([^"]*)" with the template:$/ do |name, template| @snippet = create_snippet(name, template) end +# checks to see if a string is in the slug +Then /^I should have "(.*)" in the (.*) snippet/ do |content, snippet_slug| + snippet = @site.snippets.where(:slug => snippet_slug).first + raise "Could not find snippet: #{snippet_slug}" unless snippet + + snippet.template.should == content +end From c07dbb3f98cc56f9c8a2f48a66c6c8b9190a88ab Mon Sep 17 00:00:00 2001 From: Mario Visic Date: Thu, 2 Jun 2011 21:36:03 +0800 Subject: [PATCH 2/6] Cleaned up the snippet feature. --- features/admin/snippets.feature | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/features/admin/snippets.feature b/features/admin/snippets.feature index 84c30a3b..b304bd96 100644 --- a/features/admin/snippets.feature +++ b/features/admin/snippets.feature @@ -6,20 +6,23 @@ Feature: Snippets Background: Given I have the site: "test site" set up And I am an authenticated user - And a snippet named "yield" with the template: - """ - HELLO WORLD ! - """ + And a page named "home" with the template: + """ + {% include 'yield' %} + """ + And a snippet named "yield" with the template: + """ + "yield" + """ + And a snippet named "other" with the template: + """ + "other" + """ Scenario: Updating a Snippet that includes another snippet - And a page named "snippet-test" with the template: - """ - {% include 'yield' %} - """ When I go to theme assets And I follow "yield" And I fill in "snippet_template" with "{% include 'other' %}" And I press "Update" Then I should see "Snippet was successfully updated." And I should have "{% include 'other' %}" in the yield snippet - Then show me the page From 684b1ddf5cd27ccb5840ef0e4cc07a9f0f289465 Mon Sep 17 00:00:00 2001 From: Mario Visic Date: Thu, 2 Jun 2011 21:56:05 +0800 Subject: [PATCH 3/6] Nested snippets now update correctly, fixes #84 --- lib/locomotive/liquid/tags/snippet.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/locomotive/liquid/tags/snippet.rb b/lib/locomotive/liquid/tags/snippet.rb index 336905bf..704a6017 100644 --- a/lib/locomotive/liquid/tags/snippet.rb +++ b/lib/locomotive/liquid/tags/snippet.rb @@ -12,11 +12,14 @@ module Locomotive @slug = @template_name.gsub('\'', '') + @context[:snippets] = [] if @context[:snippets].nil? (@context[:snippets] << @slug).uniq! - snippet = @context[:site].snippets.where(:slug => @slug).first + if @context[:site].present? + snippet = @context[:site].snippets.where(:slug => @slug).first - self.refresh(snippet) if snippet + self.refresh(snippet) if snippet + end end def render(context) From 8575af8b3370d539d80be4e35905cc31352f9e26 Mon Sep 17 00:00:00 2001 From: Mario Visic Date: Thu, 2 Jun 2011 21:58:17 +0800 Subject: [PATCH 4/6] Small fix on the admin snippets feature. --- features/admin/snippets.feature | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/features/admin/snippets.feature b/features/admin/snippets.feature index b304bd96..b39bf92e 100644 --- a/features/admin/snippets.feature +++ b/features/admin/snippets.feature @@ -14,12 +14,12 @@ Background: """ "yield" """ - And a snippet named "other" with the template: + +Scenario: Updating a Snippet that includes another snippet + Given a snippet named "other" with the template: """ "other" """ - -Scenario: Updating a Snippet that includes another snippet When I go to theme assets And I follow "yield" And I fill in "snippet_template" with "{% include 'other' %}" From 19a07910f7b329d3aed399a7e713cf271a8018a1 Mon Sep 17 00:00:00 2001 From: Mario Visic Date: Thu, 2 Jun 2011 22:01:25 +0800 Subject: [PATCH 5/6] Added a feature to creating snippets. --- features/admin/snippets.feature | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/features/admin/snippets.feature b/features/admin/snippets.feature index b39bf92e..b59b2a9b 100644 --- a/features/admin/snippets.feature +++ b/features/admin/snippets.feature @@ -15,6 +15,17 @@ Background: "yield" """ + +Scenario: Creating a Snippet + When I go to theme assets + And I follow "new snippet" + And I fill in "Name" with "Banner" + And I fill in "Slug" with "banner" + And I fill in "snippet_template" with "banner" + And I press "Create" + Then I should see "Snippet was successfully created." + And I should have "banner" in the banner snippet + Scenario: Updating a Snippet that includes another snippet Given a snippet named "other" with the template: """ From 8c62ec4dba74e2d64932809702c44bdbd9ba6c84 Mon Sep 17 00:00:00 2001 From: Mario Visic Date: Thu, 2 Jun 2011 22:34:06 +0800 Subject: [PATCH 6/6] Small refactoring on the snippet tag constructor. --- lib/locomotive/liquid/tags/snippet.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/locomotive/liquid/tags/snippet.rb b/lib/locomotive/liquid/tags/snippet.rb index 704a6017..19c6d7e1 100644 --- a/lib/locomotive/liquid/tags/snippet.rb +++ b/lib/locomotive/liquid/tags/snippet.rb @@ -12,12 +12,14 @@ module Locomotive @slug = @template_name.gsub('\'', '') - @context[:snippets] = [] if @context[:snippets].nil? - (@context[:snippets] << @slug).uniq! + if @context[:snippets].present? + (@context[:snippets] << @slug).uniq! + else + @context[:snippets] = [@slug] + end if @context[:site].present? snippet = @context[:site].snippets.where(:slug => @slug).first - self.refresh(snippet) if snippet end end