From 75fba6aa54899ce69c3709dadb0080dce086a465 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Fri, 23 Dec 2011 14:53:03 -0800 Subject: [PATCH] support placekitten.com --- CHANGELOG.md | 1 + features/helpers_lorem.feature | 3 ++- fixtures/test-app/source/lorem.html.erb | 3 ++- lib/middleman/extensions/lorem.rb | 14 ++++++++++++-- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33f2e654..69b26c1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ * Yard code docs: http://rubydoc.info/github/middleman/middleman * config.rb and extensions can add command-line commands * Nested layouts using `wrap_layout` helper +* Support for placekitten.com 2.0.14 ==== diff --git a/features/helpers_lorem.feature b/features/helpers_lorem.feature index 7cca187c..31995796 100644 --- a/features/helpers_lorem.feature +++ b/features/helpers_lorem.feature @@ -2,4 +2,5 @@ Feature: Lorem generating helper Scenario: Lorem Helper Given the Server is running at "test-app" - Then going to "/lorem.html" should not raise an exception \ No newline at end of file + Then going to "/lorem.html" should not raise an exception + And I should see "http://placekitten.com/100" \ No newline at end of file diff --git a/fixtures/test-app/source/lorem.html.erb b/fixtures/test-app/source/lorem.html.erb index bda62f21..924dab7d 100644 --- a/fixtures/test-app/source/lorem.html.erb +++ b/fixtures/test-app/source/lorem.html.erb @@ -9,4 +9,5 @@ <%= lorem.first_name %> <%= lorem.last_name %> <%= lorem.email %> -<%= lorem.image(100) %> \ No newline at end of file +<%= image_tag lorem.image(100) %> +<%= image_tag placekitten(100) %> \ No newline at end of file diff --git a/lib/middleman/extensions/lorem.rb b/lib/middleman/extensions/lorem.rb index 035ad87d..c6616fc1 100644 --- a/lib/middleman/extensions/lorem.rb +++ b/lib/middleman/extensions/lorem.rb @@ -9,7 +9,12 @@ module Middleman::Extensions module InstanceMethods def lorem - @_lorem ||= LoremObject.new + @_lorem ||= LoremObject.new(self) + end + + def placekitten(size, options={}) + options[:domain] = "http://placekitten.com" + lorem.image(size, options) end end @@ -40,6 +45,10 @@ module Middleman::Extensions class LoremObject WORDS = %w(alias consequatur aut perferendis sit voluptatem accusantium doloremque aperiam eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo aspernatur aut odit aut fugit sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt neque dolorem ipsum quia dolor sit amet consectetur adipisci velit sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem ut enim ad minima veniam quis nostrum exercitationem ullam corporis nemo enim ipsam voluptatem quia voluptas sit suscipit laboriosam nisi ut aliquid ex ea commodi consequatur quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae et iusto odio dignissimos ducimus qui blanditiis praesentium laudantium totam rem voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident sed ut perspiciatis unde omnis iste natus error similique sunt in culpa qui officia deserunt mollitia animi id est laborum et dolorum fuga et harum quidem rerum facilis est et expedita distinctio nam libero tempore cum soluta nobis est eligendi optio cumque nihil impedit quo porro quisquam est qui minus id quod maxime placeat facere possimus omnis voluptas assumenda est omnis dolor repellendus temporibus autem quibusdam et aut consequatur vel illum qui dolorem eum fugiat quo voluptas nulla pariatur at vero eos et accusamus officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae itaque earum rerum hic tenetur a sapiente delectus ut aut reiciendis voluptatibus maiores doloribus asperiores repellat) + def initialize(app) + @app = app + end + def word words(1) end @@ -99,7 +108,8 @@ module Middleman::Extensions end def image(size, options={}) - src = "http://placehold.it/#{size}" + domain = options[:domain] || "http://placehold.it" + src = "#{domain}/#{size}" hex = %w[a b c d e f 0 1 2 3 4 5 6 7 8 9] background_color = options[:background_color] color = options[:color]