Skip to content

Commit

Permalink
Merge pull request petebrowne#21 from dwradcliffe/stylesheet_tag_media
Browse files Browse the repository at this point in the history
support for media attribute on stylesheet_tag helper
  • Loading branch information
petebrowne committed Sep 11, 2013
2 parents 5997d47 + 25bc303 commit 6b81309
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/sprockets/helpers.rb
Expand Up @@ -160,9 +160,11 @@ def javascript_tag(source, options = {})
end

def stylesheet_tag(source, options = {})
media = options.delete(:media)
media_attr = media.nil? ? nil : " media=\"#{media}\""
options = Helpers.default_path_options[:stylesheet_path].merge(options)
asset_tag(source, options) do |path|
%Q(<link rel="stylesheet" href="#{path}">)
%Q(<link rel="stylesheet" href="#{path}"#{media_attr}>)
end
end

Expand Down
4 changes: 4 additions & 0 deletions spec/sprockets-helpers_spec.rb
Expand Up @@ -520,6 +520,10 @@
expect(context.stylesheet_tag('main')).to eq('<link rel="stylesheet" href="/stylesheets/main.css">')
end

it 'uses media attribute when provided' do
expect(context.stylesheet_tag('main', :media => "print")).to eq('<link rel="stylesheet" href="/stylesheets/main.css" media="print">')
end

describe 'when expanding' do
it 'generates stylesheet tag for each stylesheet asset' do
within_construct do |construct|
Expand Down

0 comments on commit 6b81309

Please sign in to comment.