Skip to content

Commit

Permalink
Add html_doctype, css_link, and js_link
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcsmith committed Jun 30, 2017
1 parent f587315 commit 5688e28
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
40 changes: 40 additions & 0 deletions spec/lucky_web/specialty_tags_spec.cr
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
1 change: 1 addition & 0 deletions src/lucky_web/page.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module LuckyWeb::Page
include LuckyWeb::FormHelpers
include LuckyWeb::LabelHelpers
include LuckyWeb::InputHelpers
include LuckyWeb::SpecialtyTags
include LuckyWeb::Assignable
include LuckyWeb::AssetHelpers

Expand Down
16 changes: 16 additions & 0 deletions src/lucky_web/tags/specialty_tags.cr
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

0 comments on commit 5688e28

Please sign in to comment.