Module: HT5
- Included in:
- Ht5
- Defined in:
- lib/ht5.rb
Overview
Copyright 2014 ePark Labs Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Defined Under Namespace
Classes: HT5OUT
Constant Summary collapse
- VERSION =
"0.1.1"
Instance Method Summary collapse
-
#__(&b) ⇒ Object
(also: #_)
Add a string with no tags (or your own tags).
- #_tag(el) ⇒ Object
-
#comment_(&b) ⇒ Object
(also: #_!)
Add a <!– comment –> Usage: comment_is a comment.”.
-
#doctype_ ⇒ Object
Adds the HTML5 DOCTYPE tag.
-
#h_(str) ⇒ Object
Escape HTML Returns an escaped string for [‘“&<>].
-
#ht5 ⇒ Object
The container that holds the output.
- #start_ht5 ⇒ Object
-
#tag_(el, opts = {}, &b) ⇒ Object
Support other tags Usage: tag_(:person, class: ‘active’)“Joe” Returns: <person class=“active”>Joe</person>.
-
#url_(str) ⇒ Object
Escape URL query string Returns an escaped string for all characters except [a-zA-Z0-9_.-].
Instance Method Details
#__(&b) ⇒ Object Also known as: _
Add a string with no tags (or your own tags)
42 43 44 |
# File 'lib/ht5.rb', line 42 def __(&b) ht5 << yield end |
#_tag(el) ⇒ Object
81 82 83 84 |
# File 'lib/ht5.rb', line 81 def _tag(el) ht5 << "</#{el}>" nil end |
#comment_(&b) ⇒ Object Also known as: _!
Add a <!– comment –> Usage: comment_is a comment.”
36 37 38 |
# File 'lib/ht5.rb', line 36 def comment_(&b) ht5 << "<!-- #{yield} -->" end |
#doctype_ ⇒ Object
Adds the HTML5 DOCTYPE tag
49 50 51 52 |
# File 'lib/ht5.rb', line 49 def doctype_ start_ht5 ht5 << "<!DOCTYPE html>" end |
#h_(str) ⇒ Object
Escape HTML Returns an escaped string for [‘“&<>]
56 57 58 |
# File 'lib/ht5.rb', line 56 def h_(str) str.to_s.gsub(/['&\"<>]/, {"'"=>"'", "&"=>"&", '"'=>""", "<"=>"<", ">"=>">"}) end |
#ht5 ⇒ Object
The container that holds the output.
26 27 28 |
# File 'lib/ht5.rb', line 26 def ht5 @ht5 ||= start_ht5 end |
#start_ht5 ⇒ Object
30 31 32 |
# File 'lib/ht5.rb', line 30 def start_ht5 @ht5 = ::HT5::HT5OUT.new end |
#tag_(el, opts = {}, &b) ⇒ Object
Support other tags Usage: tag_(:person, class: ‘active’)“Joe” Returns: <person class=“active”>Joe</person>
72 73 74 75 76 77 78 79 |
# File 'lib/ht5.rb', line 72 def tag_(el, opts={}, &b) ht5 << "<#{el}#{opts.map{|n,v| " #{n}=\"#{v}\""}.join}>" if block_given? ht5 << yield ht5 << "</#{el}>" end nil end |
#url_(str) ⇒ Object
Escape URL query string Returns an escaped string for all characters except [a-zA-Z0-9_.-]
62 63 64 65 66 67 |
# File 'lib/ht5.rb', line 62 def url_(str) encoding = str.encoding str.b.gsub(/([^ a-zA-Z0-9_.-]+)/) do |m| '%' + m.unpack('H2' * m.bytesize).join('%').upcase end.tr(' ', '+').force_encoding(encoding) end |