sinatra-head 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -114,6 +114,12 @@ Like the _title_ setting, the _stylesheets_ setting begins life as an empty arra
114
114
  stylesheets << 'specific.css'
115
115
  end
116
116
 
117
+ If your stylesheet string contains a space, the second and any following words will be used for the _media_ attribute:
118
+
119
+ stylesheets << 'no_effects.css print braille'
120
+ # yields:
121
+ <link rel='stylesheet' href='/stylesheets/no_effects.css' media='print, braille' />
122
+
117
123
  In your layout, you can call the `stylesheet_tag` helper for a single filename or URL you provide, or the `stylesheet_tags` helper which walks the array and creates a tag for each. (In FIFO or queue order, unlike _title._)
118
124
 
119
125
  Currently nothing is done for nicer asset packaging, fingerprinting, compressing, etc. There's [Rack][10] [middleware][9] for some of it, and future iterations may include these features. If you'd really really like to see them, [create an issue][7] and ask for them.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/lib/sinatra/head.rb CHANGED
@@ -6,18 +6,6 @@ require 'sinatra/head/tag_helpers'
6
6
  module Sinatra
7
7
  module Head
8
8
 
9
- # # Exposes the 'title' setting so that it can be overwritten or appended to.
10
- # # @see DataHelpers#title
11
- # def title
12
- # settings.title
13
- # end
14
- #
15
- # # Exposes the 'stylesheets' setting so that it can be overwritten or appended to.
16
- # # @see DataHelpers#stylesheets
17
- # def stylesheets
18
- # settings.stylesheets
19
- # end
20
-
21
9
  def self.registered(app)
22
10
  app.helpers DataHelpers
23
11
  app.helpers TagHelpers
@@ -35,5 +23,14 @@ module Sinatra
35
23
  app.set :javascript_path, '/javascript'
36
24
  end
37
25
  end
26
+
27
+ def inherited(child)
28
+ super
29
+ # Copy our arrays, because otherwise changes on subclasses will go upwards to superclasses
30
+ child.set :title, title.clone
31
+ child.set :stylesheets, stylesheets.clone
32
+ child.set :javascripts, javascripts.clone
33
+ end
34
+
38
35
  end
39
36
  end
@@ -35,10 +35,17 @@ module Sinatra
35
35
 
36
36
  # Spits out a <link rel='stylesheet'> element for the given stylesheet reference.
37
37
  # Relative filenames will be expanded with the Sinatra assets path, if set.
38
+ # If the filename string contains multiple words (separated by spaces), all
39
+ # words after the first will be used for _media_ identifiers.
38
40
  #
39
41
  # @param [String] sheet
40
- def stylesheet_tag(sheet)
41
- "<link rel='stylesheet' href='#{expand_stylesheet_path(sheet)}' />"
42
+ def stylesheet_tag(reference)
43
+ sheet, *media = reference.split
44
+ if media.empty?
45
+ "<link rel='stylesheet' href='#{expand_stylesheet_path(sheet)}' />"
46
+ else
47
+ "<link rel='stylesheet' href='#{expand_stylesheet_path(sheet)}' media='#{media.join(', ')}' />"
48
+ end
42
49
  end
43
50
 
44
51
  # Spits out stylesheet tags for all declared stylesheets, one per line.
@@ -0,0 +1,74 @@
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-head}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Stephen Eley"]
12
+ s.date = %q{2010-05-20}
13
+ s.description = %q{Sinatra::Head provides class methods and helpers for dynamically controlling the fields in your <HEAD> element that are usually preset in your layout: the page title, stylesheet and javascript assets, etc. Asset lists are inherited throughout superclasses, subclasses, and within action methods, and basic asset path management is supported.}
14
+ s.email = %q{sfeley@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.markdown",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE.markdown",
23
+ "README.markdown",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/sinatra/head.rb",
27
+ "lib/sinatra/head/data_helpers.rb",
28
+ "lib/sinatra/head/tag_helpers.rb",
29
+ "sinatra-head.gemspec",
30
+ "spec/sinatra/head_spec.rb",
31
+ "spec/sinatra/javascripts_spec.rb",
32
+ "spec/sinatra/stylesheet_spec.rb",
33
+ "spec/sinatra/title_spec.rb",
34
+ "spec/spec.opts",
35
+ "spec/spec_helper.rb",
36
+ "spec/support/dummy_app.rb"
37
+ ]
38
+ s.homepage = %q{http://github.com/SFEley/sinatra-head}
39
+ s.rdoc_options = ["--charset=UTF-8"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = %q{1.3.7}
42
+ s.summary = %q{A Sinatra extension that gets inside your <HEAD>.}
43
+ s.test_files = [
44
+ "spec/sinatra/head_spec.rb",
45
+ "spec/sinatra/javascripts_spec.rb",
46
+ "spec/sinatra/stylesheet_spec.rb",
47
+ "spec/sinatra/title_spec.rb",
48
+ "spec/spec_helper.rb",
49
+ "spec/support/dummy_app.rb"
50
+ ]
51
+
52
+ if s.respond_to? :specification_version then
53
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
54
+ s.specification_version = 3
55
+
56
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
58
+ s.add_development_dependency(%q<yard>, [">= 0"])
59
+ s.add_development_dependency(%q<haml>, [">= 3"])
60
+ s.add_development_dependency(%q<capybara>, [">= 0.3.8"])
61
+ else
62
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
63
+ s.add_dependency(%q<yard>, [">= 0"])
64
+ s.add_dependency(%q<haml>, [">= 3"])
65
+ s.add_dependency(%q<capybara>, [">= 0.3.8"])
66
+ end
67
+ else
68
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
69
+ s.add_dependency(%q<yard>, [">= 0"])
70
+ s.add_dependency(%q<haml>, [">= 3"])
71
+ s.add_dependency(%q<capybara>, [">= 0.3.8"])
72
+ end
73
+ end
74
+
@@ -4,15 +4,6 @@ describe Sinatra::Head, "javascripts" do
4
4
  include DummyFixture
5
5
 
6
6
 
7
- class DummyFixture::DummyApp
8
- javascripts << 'main.js'
9
- end
10
-
11
- class DummyFixture::DummyChild
12
- javascripts << 'secondary.js'
13
- set :javascript_path, '/things/javascript'
14
- end
15
-
16
7
  before(:each) do
17
8
  app DummyFixture::DummyChild
18
9
  @instance = app.new
@@ -31,6 +22,10 @@ describe Sinatra::Head, "javascripts" do
31
22
  @instance.javascripts.should == ['main.js', 'secondary.js', 'specific.js']
32
23
  end
33
24
 
25
+ it "leaves its superclass's value alone" do
26
+ instance = DummyFixture::DummyApp.new
27
+ instance.javascripts.should == ['main.js']
28
+ end
34
29
 
35
30
  it "expands the assets path for relative filenames" do
36
31
  @instance.expand_javascript_path(@instance.javascripts.first).should == '/things/javascript/main.js'
@@ -5,12 +5,9 @@ describe Sinatra::Head, "stylesheets" do
5
5
 
6
6
 
7
7
  class DummyFixture::DummyApp
8
- stylesheets << 'main.css'
9
8
  end
10
9
 
11
10
  class DummyFixture::DummyChild
12
- stylesheets << 'secondary.css'
13
- set :stylesheet_path, '/stuff/stylesheets'
14
11
  end
15
12
 
16
13
  before(:each) do
@@ -31,6 +28,10 @@ describe Sinatra::Head, "stylesheets" do
31
28
  @instance.stylesheets.should == ['main.css', 'secondary.css', 'specific.css']
32
29
  end
33
30
 
31
+ it "leaves its superclass's value alone" do
32
+ instance = DummyFixture::DummyApp.new
33
+ instance.stylesheets.should == ['main.css']
34
+ end
34
35
 
35
36
  it "expands the assets path for relative filenames" do
36
37
  @instance.expand_stylesheet_path(@instance.stylesheets.first).should == '/stuff/stylesheets/main.css'
@@ -44,6 +45,10 @@ describe Sinatra::Head, "stylesheets" do
44
45
  it "knows how to make a tag" do
45
46
  @instance.stylesheet_tag(@instance.stylesheets.first).should == "<link rel='stylesheet' href='/stuff/stylesheets/main.css' />"
46
47
  end
48
+
49
+ it "can make a stylesheet tag just for a specific medium" do
50
+ @instance.stylesheet_tag('print.css print braille').should == "<link rel='stylesheet' href='/stuff/stylesheets/print.css' media='print, braille' />"
51
+ end
47
52
 
48
53
  it "knows how to make all the tags" do
49
54
  @instance.stylesheets << 'http://yahoo.com/yahoo_style.css'
@@ -3,15 +3,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
3
3
  describe Sinatra::Head, "titles" do
4
4
  include DummyFixture
5
5
 
6
-
7
- class DummyFixture::DummyApp
8
- title << 'High Level'
9
- end
10
-
11
- class DummyFixture::DummyChild
12
- title << 'Mid-Level'
13
- end
14
-
6
+
15
7
  before(:each) do
16
8
  @instance = app.new
17
9
  end
@@ -34,6 +26,11 @@ describe Sinatra::Head, "titles" do
34
26
  @instance.title.should == ['Kaboom!']
35
27
  end
36
28
 
29
+ it "leaves its superclass's value alone" do
30
+ instance = DummyFixture::DummyApp.new
31
+ instance.title.should == ['High Level']
32
+ end
33
+
37
34
  it "returns itself as a string" do
38
35
  @instance.title << 'Low Level'
39
36
  @instance.title_string.should == 'Low Level | Mid-Level | High Level'
@@ -8,6 +8,9 @@ module DummyFixture
8
8
  enable :inline_templates
9
9
 
10
10
  register Sinatra::Head
11
+ title << 'High Level'
12
+ stylesheets << 'main.css'
13
+ javascripts << 'main.js'
11
14
 
12
15
  get "/" do
13
16
  haml :index
@@ -15,6 +18,14 @@ module DummyFixture
15
18
  end
16
19
 
17
20
  class DummyChild < DummyApp
21
+ title << 'Mid-Level'
22
+
23
+ stylesheets << 'secondary.css'
24
+ set :stylesheet_path, '/stuff/stylesheets'
25
+
26
+ javascripts << 'secondary.js'
27
+ set :javascript_path, '/things/javascript'
28
+
18
29
  end
19
30
 
20
31
  def app(klass=nil)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-head
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Stephen Eley
@@ -97,6 +97,7 @@ files:
97
97
  - lib/sinatra/head.rb
98
98
  - lib/sinatra/head/data_helpers.rb
99
99
  - lib/sinatra/head/tag_helpers.rb
100
+ - sinatra-head.gemspec
100
101
  - spec/sinatra/head_spec.rb
101
102
  - spec/sinatra/javascripts_spec.rb
102
103
  - spec/sinatra/stylesheet_spec.rb
@@ -104,7 +105,6 @@ files:
104
105
  - spec/spec.opts
105
106
  - spec/spec_helper.rb
106
107
  - spec/support/dummy_app.rb
107
- - spec/title_spec.rb
108
108
  has_rdoc: true
109
109
  homepage: http://github.com/SFEley/sinatra-head
110
110
  licenses: []
@@ -146,4 +146,3 @@ test_files:
146
146
  - spec/sinatra/title_spec.rb
147
147
  - spec/spec_helper.rb
148
148
  - spec/support/dummy_app.rb
149
- - spec/title_spec.rb
data/spec/title_spec.rb DELETED
@@ -1,5 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe "title" do
4
-
5
- end