-
-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add html_doctype, css_link, and js_link
- Loading branch information
1 parent
f587315
commit 5688e28
Showing
3 changed files
with
57 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require "../../spec_helper" | ||
|
||
private class TestPage | ||
include LuckyWeb::Page | ||
|
||
render do | ||
end | ||
end | ||
|
||
describe LuckyWeb::SpecialtyTags do | ||
it "renders doctype" do | ||
view.html_doctype.to_s.should contain <<-HTML | ||
<!DOCTYPE html> | ||
HTML | ||
end | ||
|
||
it "renders css link tag" do | ||
view.css_link("app.css").to_s.should contain <<-HTML | ||
<link href="app.css" rel="stylesheet" media="screen"> | ||
HTML | ||
|
||
view.css_link("app.css", rel: "preload", media: "print").to_s.should contain <<-HTML | ||
<link href="app.css" rel="preload" media="print"> | ||
HTML | ||
end | ||
|
||
it "renders js link tag" do | ||
view.js_link("app.js").to_s.should contain <<-HTML | ||
<script src="app.js"></script> | ||
HTML | ||
|
||
view.js_link("app.js", foo: "bar").to_s.should contain <<-HTML | ||
<script src="app.js" foo="bar"></script> | ||
HTML | ||
end | ||
end | ||
|
||
private def view | ||
TestPage.new | ||
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,16 @@ | ||
module LuckyWeb::SpecialtyTags | ||
def html_doctype | ||
@view << "<!DOCTYPE html>" | ||
end | ||
|
||
def css_link(href, rel = "stylesheet", media = "screen") | ||
tag_attrs = build_tag_attrs({href: href, rel: rel, media: media}) | ||
@view << "<link" << tag_attrs << ">" | ||
end | ||
|
||
def js_link(src, **options) | ||
options = merge_options(options, {"src" => src}) | ||
tag_attrs = build_tag_attrs(options) | ||
@view << "<script" << tag_attrs << "></script>" | ||
end | ||
end |