middleman-more 3.1.0.beta.1 → 3.1.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,196 +1,175 @@
1
- # Extension namespace
2
- module Middleman
3
- module Extensions
4
-
5
- # Lorem helper
6
- module Lorem
7
-
8
- # Setup extension
9
- class << self
1
+ class Middleman::Extensions::Lorem < ::Middleman::Extension
2
+ helpers do
3
+ # Access to the Lorem object
4
+ # @return [Middleman::Extensions::Lorem::LoremObject]
5
+ def lorem
6
+ LoremObject
7
+ end
10
8
 
11
- # Once registered
12
- def registered(app)
13
- # Include methods
14
- app.send :include, InstanceMethods
15
- end
9
+ # Return a placeholder image using placekitten.com
10
+ #
11
+ # @param [String] size
12
+ # @param [Hash] options
13
+ # @return [String]
14
+ def placekitten(size, options={})
15
+ options[:domain] = "http://placekitten.com"
16
+ lorem.image(size, options)
17
+ end
18
+ end
16
19
 
17
- alias :included :registered
20
+ # Adapted from Frank:
21
+ # https://github.com/blahed/frank/
22
+ # Copyright (c) 2010 Travis Dunn
23
+ #
24
+ # Permission is hereby granted, free of charge, to any person
25
+ # obtaining a copy of this software and associated documentation
26
+ # files (the "Software"), to deal in the Software without
27
+ # restriction, including without limitation the rights to use,
28
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell
29
+ # copies of the Software, and to permit persons to whom the
30
+ # Software is furnished to do so, subject to the following
31
+ # conditions:
32
+ #
33
+ # The above copyright notice and this permission notice shall be
34
+ # included in all copies or substantial portions of the Software.
35
+ #
36
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
37
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
38
+ # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
39
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
40
+ # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
41
+ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
42
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
43
+ # OTHER DEALINGS IN THE SOFTWARE.
44
+ module LoremObject
45
+ class << self
46
+ # Words for use in lorem text
47
+ 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)
48
+
49
+ # Get one placeholder word
50
+ # @return [String]
51
+ def word
52
+ words(1)
18
53
  end
19
54
 
20
- # Lorem extension instance methods
21
- module InstanceMethods
22
- # Access to the Lorem object
23
- # @return [Middleman::Extensions::Lorem::LoremObject]
24
- def lorem
25
- @_lorem ||= LoremObject.new
26
- end
27
-
28
- # Return a placeholder image using placekitten.com
29
- #
30
- # @param [String] size
31
- # @param [Hash] options
32
- # @return [String]
33
- def placekitten(size, options={})
34
- options[:domain] = "http://placekitten.com"
35
- lorem.image(size, options)
36
- end
55
+ # Get some number of placeholder words
56
+ # @param [Fixnum] total
57
+ # @return [String]
58
+ def words(total)
59
+ (1..total).map do
60
+ randm(WORDS)
61
+ end.join(' ')
37
62
  end
38
63
 
39
- # Adapted from Frank:
40
- # https://github.com/blahed/frank/
41
- # Copyright (c) 2010 Travis Dunn
42
- #
43
- # Permission is hereby granted, free of charge, to any person
44
- # obtaining a copy of this software and associated documentation
45
- # files (the "Software"), to deal in the Software without
46
- # restriction, including without limitation the rights to use,
47
- # copy, modify, merge, publish, distribute, sublicense, and/or sell
48
- # copies of the Software, and to permit persons to whom the
49
- # Software is furnished to do so, subject to the following
50
- # conditions:
51
- #
52
- # The above copyright notice and this permission notice shall be
53
- # included in all copies or substantial portions of the Software.
54
- #
55
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
56
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
57
- # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
58
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
59
- # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
60
- # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
61
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
62
- # OTHER DEALINGS IN THE SOFTWARE.
63
- class LoremObject
64
- # Words for use in lorem text
65
- 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)
66
-
67
- # Get one placeholder word
68
- # @return [String]
69
- def word
70
- words(1)
71
- end
64
+ # Get one placeholder sentence
65
+ # @return [String]
66
+ def sentence
67
+ sentences(1)
68
+ end
72
69
 
73
- # Get some number of placeholder words
74
- # @param [Fixnum] total
75
- # @return [String]
76
- def words(total)
77
- (1..total).map do
78
- randm(WORDS)
79
- end.join(' ')
80
- end
70
+ # Get some number of placeholder sentences
71
+ # @param [Fixnum] total
72
+ # @return [String]
73
+ def sentences(total)
74
+ (1..total).map do
75
+ words(randm(4..15)).capitalize
76
+ end.join('. ')
77
+ end
81
78
 
82
- # Get one placeholder sentence
83
- # @return [String]
84
- def sentence
85
- sentences(1)
86
- end
79
+ # Get one placeholder paragraph
80
+ # @return [String]
81
+ def paragraph
82
+ paragraphs(1)
83
+ end
87
84
 
88
- # Get some number of placeholder sentences
89
- # @param [Fixnum] total
90
- # @return [String]
91
- def sentences(total)
92
- (1..total).map do
93
- words(randm(4..15)).capitalize
94
- end.join('. ')
95
- end
85
+ # Get some number of placeholder paragraphs
86
+ # @param [Fixnum] total
87
+ # @return [String]
88
+ def paragraphs(total)
89
+ (1..total).map do
90
+ sentences(randm(3..7)).capitalize
91
+ end.join("\n\n")
92
+ end
96
93
 
97
- # Get one placeholder paragraph
98
- # @return [String]
99
- def paragraph
100
- paragraphs(1)
101
- end
94
+ # Get a placeholder date
95
+ # @param [String] fmt
96
+ # @return [String]
97
+ def date(fmt = '%a %b %d, %Y')
98
+ y = rand(20) + 1990
99
+ m = rand(12) + 1
100
+ d = rand(31) + 1
101
+ Time.local(y,m,d).strftime(fmt)
102
+ end
102
103
 
103
- # Get some number of placeholder paragraphs
104
- # @param [Fixnum] total
105
- # @return [String]
106
- def paragraphs(total)
107
- (1..total).map do
108
- sentences(randm(3..7)).capitalize
109
- end.join("\n\n")
110
- end
104
+ # Get a placeholder name
105
+ # @return [String]
106
+ def name
107
+ "#{first_name} #{last_name}"
108
+ end
111
109
 
112
- # Get a placeholder date
113
- # @param [String] fmt
114
- # @return [String]
115
- def date(fmt = '%a %b %d, %Y')
116
- y = rand(20) + 1990
117
- m = rand(12) + 1
118
- d = rand(31) + 1
119
- Time.local(y,m,d).strftime(fmt)
120
- end
110
+ # Get a placeholder first name
111
+ # @return [String]
112
+ def first_name
113
+ names = "Judith Angelo Margarita Kerry Elaine Lorenzo Justice Doris Raul Liliana Kerry Elise Ciaran Johnny Moses Davion Penny Mohammed Harvey Sheryl Hudson Brendan Brooklynn Denis Sadie Trisha Jacquelyn Virgil Cindy Alexa Marianne Giselle Casey Alondra Angela Katherine Skyler Kyleigh Carly Abel Adrianna Luis Dominick Eoin Noel Ciara Roberto Skylar Brock Earl Dwayne Jackie Hamish Sienna Nolan Daren Jean Shirley Connor Geraldine Niall Kristi Monty Yvonne Tammie Zachariah Fatima Ruby Nadia Anahi Calum Peggy Alfredo Marybeth Bonnie Gordon Cara John Staci Samuel Carmen Rylee Yehudi Colm Beth Dulce Darius inley Javon Jason Perla Wayne Laila Kaleigh Maggie Don Quinn Collin Aniya Zoe Isabel Clint Leland Esmeralda Emma Madeline Byron Courtney Vanessa Terry Antoinette George Constance Preston Rolando Caleb Kenneth Lynette Carley Francesca Johnnie Jordyn Arturo Camila Skye Guy Ana Kaylin Nia Colton Bart Brendon Alvin Daryl Dirk Mya Pete Joann Uriel Alonzo Agnes Chris Alyson Paola Dora Elias Allen Jackie Eric Bonita Kelvin Emiliano Ashton Kyra Kailey Sonja Alberto Ty Summer Brayden Lori Kelly Tomas Joey Billie Katie Stephanie Danielle Alexis Jamal Kieran Lucinda Eliza Allyson Melinda Alma Piper Deana Harriet Bryce Eli Jadyn Rogelio Orlaith Janet Randal Toby Carla Lorie Caitlyn Annika Isabelle inn Ewan Maisie Michelle Grady Ida Reid Emely Tricia Beau Reese Vance Dalton Lexi Rafael Makenzie Mitzi Clinton Xena Angelina Kendrick Leslie Teddy Jerald Noelle Neil Marsha Gayle Omar Abigail Alexandra Phil Andre Billy Brenden Bianca Jared Gretchen Patrick Antonio Josephine Kyla Manuel Freya Kellie Tonia Jamie Sydney Andres Ruben Harrison Hector Clyde Wendell Kaden Ian Tracy Cathleen Shawn".split(" ")
114
+ names[rand(names.size)]
115
+ end
121
116
 
122
- # Get a placeholder name
123
- # @return [String]
124
- def name
125
- "#{first_name} #{last_name}"
126
- end
117
+ # Get a placeholder last name
118
+ # @return [String]
119
+ def last_name
120
+ names = "Chung Chen Melton Hill Puckett Song Hamilton Bender Wagner McLaughlin McNamara Raynor Moon Woodard Desai Wallace Lawrence Griffin Dougherty Powers May Steele Teague Vick Gallagher Solomon Walsh Monroe Connolly Hawkins Middleton Goldstein Watts Johnston Weeks Wilkerson Barton Walton Hall Ross Chung Bender Woods Mangum Joseph Rosenthal Bowden Barton Underwood Jones Baker Merritt Cross Cooper Holmes Sharpe Morgan Hoyle Allen Rich Rich Grant Proctor Diaz Graham Watkins Hinton Marsh Hewitt Branch Walton O'Brien Case Watts Christensen Parks Hardin Lucas Eason Davidson Whitehead Rose Sparks Moore Pearson Rodgers Graves Scarborough Sutton Sinclair Bowman Olsen Love McLean Christian Lamb James Chandler Stout Cowan Golden Bowling Beasley Clapp Abrams Tilley Morse Boykin Sumner Cassidy Davidson Heath Blanchard McAllister McKenzie Byrne Schroeder Griffin Gross Perkins Robertson Palmer Brady Rowe Zhang Hodge Li Bowling Justice Glass Willis Hester Floyd Graves Fischer Norman Chan Hunt Byrd Lane Kaplan Heller May Jennings Hanna Locklear Holloway Jones Glover Vick O'Donnell Goldman McKenna Starr Stone McClure Watson Monroe Abbott Singer Hall Farrell Lucas Norman Atkins Monroe Robertson Sykes Reid Chandler Finch Hobbs Adkins Kinney Whitaker Alexander Conner Waters Becker Rollins Love Adkins Black Fox Hatcher Wu Lloyd Joyce Welch Matthews Chappell MacDonald Kane Butler Pickett Bowman Barton Kennedy Branch Thornton McNeill Weinstein Middleton Moss Lucas Rich Carlton Brady Schultz Nichols Harvey Stevenson Houston Dunn West O'Brien Barr Snyder Cain Heath Boswell Olsen Pittman Weiner Petersen Davis Coleman Terrell Norman Burch Weiner Parrott Henry Gray Chang McLean Eason Weeks Siegel Puckett Heath Hoyle Garrett Neal Baker Goldman Shaffer Choi Carver".split(" ")
121
+ names[rand(names.size)]
122
+ end
127
123
 
128
- # Get a placeholder first name
129
- # @return [String]
130
- def first_name
131
- names = "Judith Angelo Margarita Kerry Elaine Lorenzo Justice Doris Raul Liliana Kerry Elise Ciaran Johnny Moses Davion Penny Mohammed Harvey Sheryl Hudson Brendan Brooklynn Denis Sadie Trisha Jacquelyn Virgil Cindy Alexa Marianne Giselle Casey Alondra Angela Katherine Skyler Kyleigh Carly Abel Adrianna Luis Dominick Eoin Noel Ciara Roberto Skylar Brock Earl Dwayne Jackie Hamish Sienna Nolan Daren Jean Shirley Connor Geraldine Niall Kristi Monty Yvonne Tammie Zachariah Fatima Ruby Nadia Anahi Calum Peggy Alfredo Marybeth Bonnie Gordon Cara John Staci Samuel Carmen Rylee Yehudi Colm Beth Dulce Darius inley Javon Jason Perla Wayne Laila Kaleigh Maggie Don Quinn Collin Aniya Zoe Isabel Clint Leland Esmeralda Emma Madeline Byron Courtney Vanessa Terry Antoinette George Constance Preston Rolando Caleb Kenneth Lynette Carley Francesca Johnnie Jordyn Arturo Camila Skye Guy Ana Kaylin Nia Colton Bart Brendon Alvin Daryl Dirk Mya Pete Joann Uriel Alonzo Agnes Chris Alyson Paola Dora Elias Allen Jackie Eric Bonita Kelvin Emiliano Ashton Kyra Kailey Sonja Alberto Ty Summer Brayden Lori Kelly Tomas Joey Billie Katie Stephanie Danielle Alexis Jamal Kieran Lucinda Eliza Allyson Melinda Alma Piper Deana Harriet Bryce Eli Jadyn Rogelio Orlaith Janet Randal Toby Carla Lorie Caitlyn Annika Isabelle inn Ewan Maisie Michelle Grady Ida Reid Emely Tricia Beau Reese Vance Dalton Lexi Rafael Makenzie Mitzi Clinton Xena Angelina Kendrick Leslie Teddy Jerald Noelle Neil Marsha Gayle Omar Abigail Alexandra Phil Andre Billy Brenden Bianca Jared Gretchen Patrick Antonio Josephine Kyla Manuel Freya Kellie Tonia Jamie Sydney Andres Ruben Harrison Hector Clyde Wendell Kaden Ian Tracy Cathleen Shawn".split(" ")
132
- names[rand(names.size)]
133
- end
124
+ # Get a placeholder 140 character tweet about Philip the Purple Otter
125
+ # Via http://www.kevadamson.com/talking-of-design/article/140-alternative-characters-to-lorem-ipsum
126
+ # @return [String]
127
+ def tweet
128
+ tweets = [ 'Far away, in a forest next to a river beneath the mountains, there lived a small purple otter called Philip. Philip likes sausages. The End.',
129
+ 'He liked the quality sausages from Marks & Spencer but due to the recession he had been forced to shop in a less desirable supermarket. End.',
130
+ 'He awoke one day to find his pile of sausages missing. Roger the greedy boar with human eyes, had skateboarded into the forest & eaten them!']
131
+ tweets[rand(tweets.size)]
132
+ end
134
133
 
135
- # Get a placeholder last name
136
- # @return [String]
137
- def last_name
138
- names = "Chung Chen Melton Hill Puckett Song Hamilton Bender Wagner McLaughlin McNamara Raynor Moon Woodard Desai Wallace Lawrence Griffin Dougherty Powers May Steele Teague Vick Gallagher Solomon Walsh Monroe Connolly Hawkins Middleton Goldstein Watts Johnston Weeks Wilkerson Barton Walton Hall Ross Chung Bender Woods Mangum Joseph Rosenthal Bowden Barton Underwood Jones Baker Merritt Cross Cooper Holmes Sharpe Morgan Hoyle Allen Rich Rich Grant Proctor Diaz Graham Watkins Hinton Marsh Hewitt Branch Walton O'Brien Case Watts Christensen Parks Hardin Lucas Eason Davidson Whitehead Rose Sparks Moore Pearson Rodgers Graves Scarborough Sutton Sinclair Bowman Olsen Love McLean Christian Lamb James Chandler Stout Cowan Golden Bowling Beasley Clapp Abrams Tilley Morse Boykin Sumner Cassidy Davidson Heath Blanchard McAllister McKenzie Byrne Schroeder Griffin Gross Perkins Robertson Palmer Brady Rowe Zhang Hodge Li Bowling Justice Glass Willis Hester Floyd Graves Fischer Norman Chan Hunt Byrd Lane Kaplan Heller May Jennings Hanna Locklear Holloway Jones Glover Vick O'Donnell Goldman McKenna Starr Stone McClure Watson Monroe Abbott Singer Hall Farrell Lucas Norman Atkins Monroe Robertson Sykes Reid Chandler Finch Hobbs Adkins Kinney Whitaker Alexander Conner Waters Becker Rollins Love Adkins Black Fox Hatcher Wu Lloyd Joyce Welch Matthews Chappell MacDonald Kane Butler Pickett Bowman Barton Kennedy Branch Thornton McNeill Weinstein Middleton Moss Lucas Rich Carlton Brady Schultz Nichols Harvey Stevenson Houston Dunn West O'Brien Barr Snyder Cain Heath Boswell Olsen Pittman Weiner Petersen Davis Coleman Terrell Norman Burch Weiner Parrott Henry Gray Chang McLean Eason Weeks Siegel Puckett Heath Hoyle Garrett Neal Baker Goldman Shaffer Choi Carver".split(" ")
139
- names[rand(names.size)]
140
- end
134
+ # Get a placeholder email address
135
+ # @return [String]
136
+ def email
137
+ delimiters = [ '_', '-', '' ]
138
+ domains = %w(gmail.com yahoo.com hotmail.com email.com live.com me.com mac.com aol.com fastmail.com mail.com)
139
+ username = name.gsub(/[^\w]/, delimiters[rand(delimiters.size)])
140
+ "#{username}@#{domains[rand(domains.size)]}".downcase
141
+ end
141
142
 
142
- # Get a placeholder 140 character tweet about Philip the Purple Otter
143
- # Via http://www.kevadamson.com/talking-of-design/article/140-alternative-characters-to-lorem-ipsum
144
- # @return [String]
145
- def tweet
146
- tweets = [ 'Far away, in a forest next to a river beneath the mountains, there lived a small purple otter called Philip. Philip likes sausages. The End.',
147
- 'He liked the quality sausages from Marks & Spencer but due to the recession he had been forced to shop in a less desirable supermarket. End.',
148
- 'He awoke one day to find his pile of sausages missing. Roger the greedy boar with human eyes, had skateboarded into the forest & eaten them!']
149
- tweets[rand(tweets.size)]
150
- end
143
+ # Get a placeholder image, using placehold.it by default
144
+ # @param [String] size
145
+ # @param [Hash] options
146
+ # @return [String]
147
+ def image(size, options={})
148
+ domain = options[:domain] || "http://placehold.it"
149
+ src = "#{domain}/#{size}"
150
+ hex = %w[a b c d e f 0 1 2 3 4 5 6 7 8 9]
151
+ background_color = options[:background_color]
152
+ color = options[:color]
151
153
 
152
- # Get a placeholder email address
153
- # @return [String]
154
- def email
155
- delimiters = [ '_', '-', '' ]
156
- domains = %w(gmail.com yahoo.com hotmail.com email.com live.com me.com mac.com aol.com fastmail.com mail.com)
157
- username = name.gsub(/[^\w]/, delimiters[rand(delimiters.size)])
158
- "#{username}@#{domains[rand(domains.size)]}".downcase
154
+ if options[:random_color]
155
+ background_color = hex.shuffle[0...6].join
156
+ color = hex.shuffle[0...6].join
159
157
  end
160
158
 
161
- # Get a placeholder image, using placehold.it by default
162
- # @param [String] size
163
- # @param [Hash] options
164
- # @return [String]
165
- def image(size, options={})
166
- domain = options[:domain] || "http://placehold.it"
167
- src = "#{domain}/#{size}"
168
- hex = %w[a b c d e f 0 1 2 3 4 5 6 7 8 9]
169
- background_color = options[:background_color]
170
- color = options[:color]
171
-
172
- if options[:random_color]
173
- background_color = hex.shuffle[0...6].join
174
- color = hex.shuffle[0...6].join
175
- end
176
-
177
- src << "/#{background_color.sub(/^#/, '')}" if background_color
178
- src << "/ccc" if background_color.nil? && color
179
- src << "/#{color.sub(/^#/, '')}" if color
180
- src << "&text=#{Rack::Utils::escape(options[:text])}" if options[:text]
181
-
182
- src
183
- end
159
+ src << "/#{background_color.sub(/^#/, '')}" if background_color
160
+ src << "/ccc" if background_color.nil? && color
161
+ src << "/#{color.sub(/^#/, '')}" if color
162
+ src << "&text=#{Rack::Utils::escape(options[:text])}" if options[:text]
184
163
 
185
- private
164
+ src
165
+ end
186
166
 
187
- # Pick a random item from a given range
188
- # @param [Range] range
189
- # @return [Object]
190
- def randm(range)
191
- a = range.to_a
192
- a[rand(a.length)]
193
- end
167
+ # Pick a random item from a given range
168
+ # @param [Range] range
169
+ # @return [Object]
170
+ def randm(range)
171
+ a = range.to_a
172
+ a[rand(a.length)]
194
173
  end
195
174
  end
196
175
  end
@@ -1,89 +1,77 @@
1
- # Extensions namespace
2
- module Middleman
3
- module Extensions
1
+ # Minify CSS Extension
2
+ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
3
+ option :compressor, nil, 'Set the CSS compressor to use.'
4
+ option :inline, false, 'Whether to minify CSS inline within HTML files'
5
+ option :ignore, [], 'Patterns to avoid minifying'
4
6
 
5
- # Minify CSS Extension
6
- module MinifyCss
7
+ def initialize(app, options_hash={}, &block)
8
+ super
7
9
 
8
- # Setup extension
9
- class << self
10
-
11
- # Once registered
12
- def registered(app, options={})
13
- app.config.define_setting :css_compressor, nil, 'Set the CSS compressor to use. Deprecated in favor of the :compressor option when activating :minify_css'
14
-
15
- ignore = Array(options[:ignore]) << /\.min\./
16
- inline = options[:inline] || false
17
-
18
- app.after_configuration do
19
- chosen_compressor = config[:css_compressor] || options[:compressor] || begin
20
- ::Middleman::Extensions::MinifyCss::SassCompressor
21
- end
10
+ app.config.define_setting :css_compressor, nil, 'Set the CSS compressor to use. Deprecated in favor of the :compressor option when activating :minify_css'
11
+ end
22
12
 
23
- # Setup Rack middleware to minify CSS
24
- use Rack, :compressor => chosen_compressor,
25
- :ignore => ignore,
26
- :inline => inline
27
- end
28
- end
29
- alias :included :registered
30
- end
13
+ def after_configuration
14
+ chosen_compressor = app.config[:css_compressor] || options[:compressor] || SassCompressor
31
15
 
32
- class SassCompressor
33
- def self.compress(style, options = {})
34
- root_node = ::Sass::SCSS::CssParser.new(style, 'middleman-css-input', 1).parse
35
- root_node.options = { :style => :compressed }
36
- root_node.render.strip
37
- end
38
- end
16
+ # Setup Rack middleware to minify CSS
17
+ app.use Rack, :compressor => chosen_compressor,
18
+ :ignore => Array(options[:ignore]) + [/\.min\./],
19
+ :inline => options[:inline]
20
+ end
39
21
 
40
- # Rack middleware to look for CSS and compress it
41
- class Rack
42
-
43
- # Init
44
- # @param [Class] app
45
- # @param [Hash] options
46
- def initialize(app, options={})
47
- @app = app
48
- @compressor = options[:compressor]
49
- @ignore = options[:ignore]
50
- @inline = options[:inline]
51
- end
22
+ class SassCompressor
23
+ def self.compress(style, options = {})
24
+ root_node = ::Sass::SCSS::CssParser.new(style, 'middleman-css-input', 1).parse
25
+ root_node.options = { :style => :compressed }
26
+ root_node.render.strip
27
+ end
28
+ end
52
29
 
53
- # Rack interface
54
- # @param [Rack::Environmemt] env
55
- # @return [Array]
56
- def call(env)
57
- status, headers, response = @app.call(env)
30
+ # Rack middleware to look for CSS and compress it
31
+ class Rack
32
+
33
+ # Init
34
+ # @param [Class] app
35
+ # @param [Hash] options
36
+ def initialize(app, options={})
37
+ @app = app
38
+ @compressor = options[:compressor]
39
+ @ignore = options[:ignore]
40
+ @inline = options[:inline]
41
+ end
58
42
 
59
- path = env["PATH_INFO"]
43
+ # Rack interface
44
+ # @param [Rack::Environmemt] env
45
+ # @return [Array]
46
+ def call(env)
47
+ status, headers, response = @app.call(env)
60
48
 
61
- if (path.end_with?('.html') || path.end_with?('.php')) && @inline
62
- uncompressed_source = ::Middleman::Util.extract_response_text(response)
49
+ path = env["PATH_INFO"]
63
50
 
64
- minified = uncompressed_source.gsub(/(<style[^>]*>\s*(?:\/\*<!\[CDATA\[\*\/\n)?)(.*?)((?:(?:\n\s*)?\/\*\]\]>\*\/)?\s*<\/style>)/m) do |match|
65
- first = $1
66
- css = $2
67
- last = $3
51
+ if (path.end_with?('.html') || path.end_with?('.php')) && @inline
52
+ uncompressed_source = ::Middleman::Util.extract_response_text(response)
68
53
 
69
- minified_css = @compressor.compress(css)
54
+ minified = uncompressed_source.gsub(/(<style[^>]*>\s*(?:\/\*<!\[CDATA\[\*\/\n)?)(.*?)((?:(?:\n\s*)?\/\*\]\]>\*\/)?\s*<\/style>)/m) do |match|
55
+ first = $1
56
+ css = $2
57
+ last = $3
70
58
 
71
- first << minified_css << last
72
- end
59
+ minified_css = @compressor.compress(css)
73
60
 
74
- headers["Content-Length"] = ::Rack::Utils.bytesize(minified).to_s
75
- response = [minified]
76
- elsif path.end_with?('.css') && @ignore.none? {|ignore| Middleman::Util.path_match(ignore, path) }
77
- uncompressed_source = ::Middleman::Util.extract_response_text(response)
78
- minified_css = @compressor.compress(uncompressed_source)
61
+ first << minified_css << last
62
+ end
79
63
 
80
- headers["Content-Length"] = ::Rack::Utils.bytesize(minified_css).to_s
81
- response = [minified_css]
82
- end
64
+ headers["Content-Length"] = ::Rack::Utils.bytesize(minified).to_s
65
+ response = [minified]
66
+ elsif path.end_with?('.css') && @ignore.none? {|ignore| Middleman::Util.path_match(ignore, path) }
67
+ uncompressed_source = ::Middleman::Util.extract_response_text(response)
68
+ minified_css = @compressor.compress(uncompressed_source)
83
69
 
84
- [status, headers, response]
85
- end
70
+ headers["Content-Length"] = ::Rack::Utils.bytesize(minified_css).to_s
71
+ response = [minified_css]
86
72
  end
73
+
74
+ [status, headers, response]
87
75
  end
88
76
  end
89
77
  end