-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds rails stylesheet and javascript tags back
This will support work for adding SRI to our templates. This will let us add an 'integrity' attribute to both the stylesheet_link_tag and the javascript_include_tag. What this does It adds the ability to understand and convert stylesheet_link_tag and javascript_include_tag to html for the other languages in which our erb template is being compiled to (e.g. Django, Mustache, Liquid, Jinja)
- Loading branch information
Elena Tanasoiu
committed
May 12, 2017
1 parent
d2cf462
commit 155a2fb
Showing
11 changed files
with
183 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'spec_helper' | ||
require File.join(PROJECT_ROOT, 'build_tools/compiler/liquid_processor.rb') | ||
|
||
describe Compiler::LiquidProcessor do | ||
|
||
let(:file) {"some/file.erb"} | ||
subject {described_class.new(file)} | ||
|
||
it_behaves_like "a processor" | ||
|
||
end |
11 changes: 11 additions & 0 deletions
11
spec/build_tools/compiler/mustache_inheritance_processor_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'spec_helper' | ||
require File.join(PROJECT_ROOT, 'build_tools/compiler/mustache_inheritance_processor.rb') | ||
|
||
describe Compiler::MustacheInheritanceProcessor do | ||
|
||
let(:file) {"some/file.erb"} | ||
subject {described_class.new(file)} | ||
|
||
it_behaves_like "a processor" | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'spec_helper' | ||
require File.join(PROJECT_ROOT, 'build_tools/compiler/plain_processor.rb') | ||
|
||
describe Compiler::PlainProcessor do | ||
|
||
let(:file) {"some/file.erb"} | ||
subject {described_class.new(file)} | ||
|
||
it_behaves_like "a processor" | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
require 'spec_helper' | ||
require 'set' | ||
|
||
shared_examples_for "a processor" do | ||
let(:html_erb_file) {"a/file.css"} | ||
let(:processor) { described_class.new(html_erb_file) } | ||
|
||
describe "convert rails tags into html" do | ||
|
||
let(:css_source) { "govuk-template.css" } | ||
let(:js_source) { "ie.js" } | ||
|
||
describe "#stylesheet_link_tag" do | ||
let(:css_options) { {"media" => "print"} } | ||
|
||
it "should parse the stylesheet tag" do | ||
expect(processor.stylesheet_link_tag(css_source)).to eql("<link rel=\"stylesheet\" media=\"screen\" href=\"#{processor.asset_path(css_source)}\"/>") | ||
end | ||
|
||
context "if css file is for print" do | ||
it "should parse the stylesheet tag for print" do | ||
expect(processor.stylesheet_link_tag(css_source, css_options)).to eql("<link rel=\"stylesheet\" media=\"print\" href=\"#{processor.asset_path(css_source)}\"/>") | ||
end | ||
end | ||
end | ||
|
||
describe "#javascript_include_tag" do | ||
let(:js_options) { {"charset" => "UTF-8"} } | ||
|
||
it "should parse the javascript tag" do | ||
expect(processor.javascript_include_tag(js_source)).to eql("<script src=\"#{processor.asset_path(js_source)}\"></script>") | ||
end | ||
|
||
it "should parse the javascript tag" do | ||
expect(processor.javascript_include_tag(js_source, js_options)).to eql("<script src=\"#{processor.asset_path(js_source)}\" charset=\"UTF-8\"></script>") | ||
end | ||
end | ||
|
||
describe "#content_tag" do | ||
it "should return the correct html script tag" do | ||
expect(processor.content_tag(:script, " src=\"#{processor.asset_path(js_source)}\"")).to eql("<script src=\"#{processor.asset_path(js_source)}\"></script>") | ||
end | ||
end | ||
|
||
describe "#tag" do | ||
it "should return the correct html link tag" do | ||
expect(processor.tag(:link, " rel=\"stylesheet\" media=\"screen\" href=\"#{processor.asset_path(css_source)}\"")).to eql("<link rel=\"stylesheet\" media=\"screen\" href=\"#{processor.asset_path(css_source)}\"/>") | ||
end | ||
end | ||
|
||
describe "#extract_options!" do | ||
let(:options) { ["govuk-template.css", {"media" => "print"}]} | ||
|
||
it "should extract the last part of the options" do | ||
expect(processor.extract_options!(options)).to eql({"media" => "print"}) | ||
end | ||
end | ||
|
||
describe "#stringify_keys" do | ||
let(:options) { {:media => "print"} } | ||
|
||
it "should turn keys of a hash into strings" do | ||
expect(processor.stringify_keys(options)).to eql({"media"=>"print"}) | ||
end | ||
end | ||
|
||
describe "#tag_options" do | ||
let(:options) { {"rel"=>"stylesheet", "media"=>"screen", "href"=>processor.asset_path(css_source)} } | ||
|
||
it "should parse the hash" do | ||
expect(processor.tag_options(options)).to eql(" rel=\"stylesheet\" media=\"screen\" href=\"#{processor.asset_path(css_source)}\"") | ||
end | ||
end | ||
|
||
end | ||
end |