sinatra-css 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{sinatra-css}
8
+ s.version = "0.1.5"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["kematzy"]
12
+ s.date = %q{2010-08-10}
13
+ s.description = %q{A Sinatra Extension that makes working with CSS easy.}
14
+ s.email = %q{kematzy@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "CHANGES",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/sinatra/css.rb",
28
+ "sinatra-css.gemspec",
29
+ "spec/fixtures/app/views/css/screen.rcss",
30
+ "spec/fixtures/public/insert.css",
31
+ "spec/fixtures/public/inserted-from-path.css",
32
+ "spec/sinatra/css_spec.rb",
33
+ "spec/spec_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/kematzy/sinatra-css}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{A Sinatra Extension that makes working with CSS easy.}
40
+ s.test_files = [
41
+ "spec/sinatra/css_spec.rb",
42
+ "spec/spec_helper.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<sinatra>, [">= 1.0"])
51
+ s.add_runtime_dependency(%q<sinatra-tags>, [">= 0.1.0"])
52
+ s.add_development_dependency(%q<sinatra-tests>, [">= 0.1.6"])
53
+ s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
54
+ else
55
+ s.add_dependency(%q<sinatra>, [">= 1.0"])
56
+ s.add_dependency(%q<sinatra-tags>, [">= 0.1.0"])
57
+ s.add_dependency(%q<sinatra-tests>, [">= 0.1.6"])
58
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<sinatra>, [">= 1.0"])
62
+ s.add_dependency(%q<sinatra-tags>, [">= 0.1.0"])
63
+ s.add_dependency(%q<sinatra-tests>, [">= 0.1.6"])
64
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
65
+ end
66
+ end
67
+
@@ -0,0 +1,4 @@
1
+ /* Screen.rcss */
2
+ body {
3
+ color: <%= 'red' %>;
4
+ }
@@ -0,0 +1 @@
1
+ .inserted_css { color: grey; }
@@ -0,0 +1 @@
1
+ .inserted_css_from_path { color: yellow; }
@@ -0,0 +1,314 @@
1
+
2
+ require "#{File.dirname(File.dirname(File.expand_path(__FILE__)))}/spec_helper"
3
+
4
+ describe "Sinatra" do
5
+
6
+ class MyTestApp
7
+ register(Sinatra::CSS)
8
+ register(Sinatra::Cache)
9
+
10
+ set :cache_enabled, true
11
+ set :cache_environment, :test
12
+ set :cache_output_dir, "#{public_fixtures_path}/system/cache"
13
+ set :cache_fragments_output_dir, "#{public_fixtures_path}/system/cache_fragments"
14
+
15
+ set :views, "#{fixtures_path}/app/views"
16
+
17
+ get_all_css_requests # (:cache => true) # loads from /css
18
+ get_all_css_requests('/stylesheets')
19
+ get_all_css_requests('/custom', :cache => true) # loads from /custom
20
+ end
21
+
22
+ class MyCustomTestApp < Sinatra::Base
23
+ register(Sinatra::CSS)
24
+
25
+ end
26
+
27
+ it_should_behave_like "MyTestApp"
28
+
29
+ describe "CSS" do
30
+
31
+ describe "VERSION" do
32
+
33
+ it "should return the VERSION string" do
34
+ Sinatra::CSS::VERSION.should be_a_kind_of(String)
35
+ Sinatra::CSS::VERSION.should match(/\d\.\d+\.\d+(\.\d)?/)
36
+ end
37
+
38
+ end #/ VERSION
39
+
40
+ describe "#self.version" do
41
+
42
+ it "should return a version of the Sinatra::CSS VERSION string" do
43
+ Sinatra::CSS.version.should be_a_kind_of(String)
44
+ Sinatra::CSS.version.should match(/Sinatra::CSS v\d\.\d+\.\d+(\.\d)?/)
45
+ end
46
+
47
+ end #/ #self.version
48
+
49
+
50
+ describe "Configuration" do
51
+
52
+ describe "with Default settings" do
53
+
54
+ # it "should set the :pagetitle_default_options[:admin] to 'false'" do
55
+ # MyTestApp.pagetitle_default_options[:admin].should == false
56
+ # end
57
+
58
+ end #/ with Default settings
59
+
60
+ describe "with Custom Settings" do
61
+
62
+ # it "should set the :pagetitle_default_options[:admin] to 'true'" do
63
+ # MyCustomTestApp.pagetitle_default_options[:admin].should == true
64
+ # end
65
+
66
+
67
+ end #/ with Custom Settings
68
+
69
+ end #/ Configuration
70
+
71
+
72
+ describe "Helpers" do
73
+
74
+ describe "#css" do
75
+
76
+ describe "with a block" do
77
+
78
+ it "should return inline style tags" do
79
+ erb_app %Q{<%= css do
80
+ 'body { color: red; }'
81
+ end %>}
82
+ body.should have_tag('style[@type=text/css]', /body\s\{ color: red; \}/)
83
+ body.should_not have_tag('style[@charset=utf-8]')
84
+ end
85
+
86
+ end #/ with a block
87
+
88
+ describe "without a block" do
89
+
90
+ it "should assign type attribute" do
91
+ erb_app %Q{<%= css('style.css') %>}
92
+ body.should have_tag('link[@type=text/css]')
93
+ end
94
+
95
+ it "should assign rel attribute" do
96
+ erb_app %Q{<%= css('style.css') %>}
97
+ body.should have_tag('link[@rel=stylesheet]')
98
+ end
99
+
100
+ it "should assign charset UTF-8 attribute" do
101
+ erb_app %Q{<%= css('style.css') %>}
102
+ body.should have_tag('link[@charset=utf-8]')
103
+ end
104
+
105
+ it "should assign href attribute" do
106
+ erb_app %Q{<%= css('style.css') %>}
107
+ body.should have_tag('link[@href=/style.css]')
108
+ end
109
+
110
+ it "should assign media='screen' attribute" do
111
+ erb_app %Q{<%= css('style.css') %>}
112
+ body.should have_tag('link[@media=screen]')
113
+ end
114
+
115
+ it "should accept a hash of attributes 1" do
116
+ erb_app %Q{<%= css('style.css', :media => :print) %>}
117
+ body.should have_tag('link[@media=print]')
118
+ end
119
+
120
+ it "should accept a hash of attributes 2" do
121
+ erb_app %Q{<%= css('style.css', :media => "screen, projection") %>}
122
+ body.should have_tag('link[@media=screen, projection]')
123
+ end
124
+
125
+ end #/ without a block
126
+
127
+
128
+ end #/ #stylesheet
129
+
130
+ describe "#css_custom_add" do
131
+
132
+ it "should add the custom CSS to the buffer" do
133
+ @app.css_custom_add("does this work?")
134
+ assert_equal(["does this work?"], @app.sinatra_css_custom_code)
135
+ end
136
+
137
+ it "should handle multiple additions of CSS to the buffer" do
138
+ @app.css_custom_add("does this work?")
139
+ @app.css_custom_add("yes it does")
140
+ @app.sinatra_css_custom_code.should include('does this work?')
141
+ @app.sinatra_css_custom_code.should include('yes it does')
142
+ end
143
+
144
+ end #/ #css_custom_add
145
+
146
+ describe "#css_custom_add_file" do
147
+
148
+ it "should add custom CSS files to the buffer" do
149
+ @app.css_custom_add_file('dummy.css')
150
+ @app.sinatra_css_custom_files.should == [ ["dummy.css", :screen] ]
151
+ end
152
+
153
+ it "should handle multiple additions of files to the buffer" do
154
+ @app.css_custom_add_file('dummy.css')
155
+ @app.css_custom_add_file(['print',:print])
156
+ @app.sinatra_css_custom_files.should == [ ["dummy.css", :screen], ["print", :print] ]
157
+ end
158
+
159
+ it "should handle adding remote custom CSS files to the buffer" do
160
+ @app.css_custom_add_file('http://css.com/dummy.css')
161
+ @app.sinatra_css_custom_files.should == [ ["http://css.com/dummy.css", :screen] ]
162
+ end
163
+
164
+ it "should embed CSS when adding :insert_into_html to the tag" do
165
+ @app.css_custom_add_file('insert.css', :insert_into_html)
166
+ @app.sinatra_css_custom_files.should == nil
167
+ markup = @app.css_custom
168
+ markup.should match(/<style type="text\/css" media="screen">\n/)
169
+ markup.should match(/\s*\.inserted_css \{ color: grey; \}\n/)
170
+ markup.should match(/\s*<\/style>\n/)
171
+ end
172
+
173
+ it "should embed CSS when adding :insert_into_html and :path to the tag" do
174
+ @app.css_custom_add_file('inserted-from-path.css', :insert_into_html, "#{public_fixtures_path}/")
175
+ @app.sinatra_css_custom_files.should == nil
176
+ markup = @app.css_custom
177
+ markup.should match(/<style type="text\/css" media="screen">\n/)
178
+ markup.should match(/\s*\.inserted_css_from_path \{ color: yellow; \}\n/)
179
+ markup.should match(/\s*<\/style>\n/)
180
+ end
181
+
182
+ it "should NOT embed CSS when adding :insert_into_html to the tag and the file is NOT found" do
183
+ # TODO:: Work out some way to capture the warn message thrown here. $StdOut.
184
+ @app.css_custom_add_file('css/does-not-exist.css', :insert_into_html)
185
+ @app.sinatra_css_custom_files.should == nil
186
+ @app.css_custom.should == ''
187
+ end
188
+
189
+ end #/ #css_custom_add_file
190
+ #
191
+ describe "#css_custom" do
192
+
193
+ it "should return a <style> tag with the custom CSS" do
194
+ @app.css_custom_add(".custom_css { color: red; }")
195
+ @app.css_custom_add(".custom_css2 { color: green; }")
196
+ markup = @app.css_custom
197
+
198
+ markup.should match(/<style type="text\/css" media="screen">\n/)
199
+ markup.should match(/\s*\.custom_css \{ color: red; \}\n/)
200
+ markup.should match(/\s*\.custom_css2 \{ color: green; \}\n/)
201
+ markup.should match(/\s*<\/style>\n/)
202
+ end
203
+
204
+ it "should return nothing when no custom CSS has been added" do
205
+ @app.css_custom.should == ''
206
+ end
207
+
208
+ it "should reach the HTML output" do
209
+ # pending "Bug in Rack::Test ??, produces no output"
210
+ erb_app %Q{ <% css_custom_add(".custom_css { color: red; }") %> <% css_custom_add(".custom_css2 { color: green; }") %> },
211
+ :layout => %Q{ <%= css_custom %> }
212
+ body.should have_tag('style[@media=screen]')
213
+ body.should match(/\n\.custom_css \{ color: red; \}\n\s*\.custom_css2 \{ color: green; \}\n\s*/)
214
+ end
215
+
216
+ end #/ #css_custom
217
+
218
+ describe "#css_custom_files" do
219
+
220
+ it "should work with a single symbol passed to :custom_css_file" do
221
+ block = %Q[<% css_custom_add_file('/css/screen') %>]
222
+
223
+ erb_app block, :layout => %Q{ <%= css_custom_files %> }
224
+ # body.should have_tag(:debug)
225
+ body.should match(/<!-- custom css files -->\n/)
226
+ body.should have_tag('link[@href=/css/screen.css]') do |link|
227
+ link.attributes['rel'].should == 'stylesheet'
228
+ link.attributes['media'].should == 'screen'
229
+ link.attributes['type'].should == 'text/css'
230
+ link.attributes['charset'].should == 'utf-8'
231
+ end
232
+ body.should match(/\s*<!-- \/custom css files -->\n/)
233
+ end
234
+
235
+ it "should work with an array passed to :custom_css_file" do
236
+ block = %Q[<% css_custom_add_file(['/css/screen', 'screen, projection']) %>]
237
+ block << %Q[<% css_custom_add_file(['/css/print',:print]) %>]
238
+ block << %Q[<% css_custom_add_file(['http://css.com/dummy.css',:remote]) %>]
239
+
240
+ erb_app block, :layout => %Q{ <%= css_custom_files %> }
241
+ # body.should have_tag(:debug)
242
+ body.should have_tag('link[@href=/css/screen.css]') do |link|
243
+ link.attributes['rel'].should == 'stylesheet'
244
+ link.attributes['media'].should == 'screen, projection'
245
+ link.attributes['type'].should == 'text/css'
246
+ link.attributes['charset'].should == 'utf-8'
247
+ end
248
+ body.should have_tag('link[@href=/css/print.css]') do |link|
249
+ link.attributes['media'].should == 'print'
250
+ end
251
+ body.should have_tag('link[@href=http://css.com/dummy.css]') do |link|
252
+ link.attributes['media'].should == 'remote'
253
+ end
254
+ end
255
+
256
+ it "should return nothing when no custom CSS files have been added" do
257
+ erb_app %Q[<%= css_custom_files %>]
258
+ # body.should have_tag(:debug)
259
+ body.should == ''
260
+ end
261
+
262
+ end #/ #css_custom_files
263
+
264
+ end #/ Helpers
265
+
266
+
267
+ describe "DSL methods" do
268
+
269
+ describe "#get_all_css_requests" do
270
+
271
+ it "should get a .rcss stylesheet using defaults and return it" do
272
+ get('/css/screen.css')
273
+
274
+ status.should == 200
275
+ response.headers['Content-type'].should match(/text\/css/)
276
+ body.should == "/* Screen.rcss */\nbody {\n color: red;\n}\n"
277
+ end
278
+
279
+ it "should get a .rcss stylesheet using a custom path and return it" do
280
+ get('/stylesheets/screen.css')
281
+
282
+ status.should == 200
283
+ response.headers['Content-type'].should match(/text\/css/)
284
+ body.should == "/* Screen.rcss */\nbody {\n color: red;\n}\n"
285
+ end
286
+
287
+ it "should return a 404 when the stylesheet is NOT found" do
288
+ get('/css/does-not-exist.css')
289
+
290
+ status.should == 404
291
+ response.headers['Content-type'].should == "text/html"
292
+ # NOTE: dependent upon the error handling of Sinatra::Basic, but that's NOT really a core feature
293
+ # of the Sinatra::Sass extension
294
+ # body.should have_tag('h1', 'Not Found') #match(/<h1>Not Found<\/h1>\n/)
295
+ # body.should have_tag('p',/The requested URL \[ \/css\/does-not-exist\.css \] was not found on this server/ )
296
+ end
297
+
298
+ it "should function when given ':cache => Boolean'" do
299
+ get('/custom/screen.css')
300
+
301
+ status.should == 200
302
+ response.headers['Content-type'].should match(/text\/css/)
303
+ body.should == "/* Screen.rcss */\nbody {\n color: red;\n}"
304
+ end
305
+
306
+
307
+ end #/ #get_all_css_requests
308
+
309
+ end #/ DSL methods
310
+
311
+
312
+ end #/ CSS
313
+
314
+ end #/ Sinatra
@@ -0,0 +1,60 @@
1
+
2
+ ::APP_ROOT = "#{File.dirname(File.expand_path(__FILE__))}/fixtures"
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+
7
+ ENV['RACK_ENV'] = 'test'
8
+
9
+ #--
10
+ # DEPENDENCIES
11
+ #++
12
+ %w(
13
+ sinatra/base
14
+ ).each {|lib| require lib }
15
+
16
+ #--
17
+ ## SINATRA EXTENSIONS
18
+ #++
19
+ %w(
20
+ sinatra/tests
21
+ sinatra/css
22
+ sinatra/cache
23
+ ).each {|ext| require ext }
24
+
25
+
26
+ Spec::Runner.configure do |config|
27
+ config.include RspecHpricotMatchers
28
+ config.include Sinatra::Tests::TestCase
29
+ config.include Sinatra::Tests::RSpec::SharedSpecs
30
+ end
31
+
32
+
33
+ # quick convenience methods..
34
+
35
+ def fixtures_path
36
+ "#{File.dirname(File.expand_path(__FILE__))}/fixtures"
37
+ end
38
+
39
+ def public_fixtures_path
40
+ "#{fixtures_path}/public"
41
+ end
42
+
43
+ class MyTestApp < Sinatra::Base
44
+ # need to set the root of the app for the default :cache_fragments_output_dir to work
45
+ set :root, ::APP_ROOT
46
+
47
+ set :app_dir, "#{APP_ROOT}/apps/base"
48
+ set :public, "#{fixtures_path}/public"
49
+ set :views, "#{app_dir}/views"
50
+
51
+ register(Sinatra::Tests)
52
+
53
+ enable :raise_errors
54
+
55
+ end #/class MyTestApp
56
+
57
+
58
+ class Test::Unit::TestCase
59
+ Sinatra::Base.set :environment, :test
60
+ end