Module: Slick::Helpers

Included in:
Slick, Command, Database::Migration, Helper, ProjectWatcher, ResourceFactory, Web::FileInterpreter, Workspace
Defined in:
lib/slick/helpers.rb,
lib/slick/helpers/html_builder.rb,
lib/slick/helpers/text_builder.rb

Constant Summary collapse

SELF_CLOSING_TAGS =
[
    'area',
    'base',
    'br',
    'embed',
    'hr',
    'iframe',
    'img',
    'input',
    'link',
    'meta',
    'param',
    'source',
    'track'
]
TEXT_ONLY_TAGS =
[
    'script',
    'style'
]
TAGS =
[
    "html",
    "a",
    "abbr",
    "address",
    "area",
    "article",
    "aside",
    "audio",
    "b",
    "base",
    "bdi",
    "bdo",
    "blockquote",
    "body",
    "br",
    "button",
    "canvas",
    "caption",
    "cite",
    "code",
    "col",
    "colgroup",
    "content",
    "data",
    "datalist",
    "dd",
    "del",
    "details",
    "dfn",
    "dialog",
    "div",
    "dl",
    "dt",
    "em",
    "embed",
    "fieldset",
    "figcaption",
    "figure",
    "footer",
    "form",
    "h1",
    "h2",
    "h3",
    "h4",
    "h5",
    "h6",
    "head",
    "header",
    "hr",
    "html",
    "i",
    "iframe",
    "img",
    "input",
    "ins",
    "kbd",
    "keygen",
    "label",
    "legend",
    "li",
    "link",
    "main",
    "map",
    "mark",
    "menu",
    "menuitem",
    "meta",
    "meter",
    "nav",
    "noscript",
    "object",
    "ol",
    "optgroup",
    "option",
    "output",
    "p",
    "param",
    "picture",
    "pre",
    "progress",
    "q",
    "rp",
    "rt",
    "rtc",
    "ruby",
    "s",
    "samp",
    "script",
    "section",
    "select",
    "shadow",
    "slot",
    "small",
    "source",
    "span",
    "strong",
    "style",
    "sub",
    "summary",
    "sup",
    "table",
    "tbody",
    "td",
    "template",
    "textarea",
    "tfoot",
    "th",
    "thead",
    "time",
    "title",
    "tr",
    "track",
    "u",
    "ul",
    "var",
    "video",
    "wbr"
]

Instance Method Summary collapse

Instance Method Details

#html_tag(name, *args, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/slick/helpers/html_builder.rb', line 31

def html_tag(name, *args, &block)
    name = name.to_s.downcase
    echo "<#{name.html_escape}"
    if args.last.kind_of?(Hash) 
        attributes = args.pop
        attributes.each do |name, value|
            echo " #{name.html_escape}=\"#{value.html_escape}\""
        end
    end
    echo ">"
    if !SELF_CLOSING_TAGS.include?(name)
        if args.first
            content = args.shift
            if TEXT_ONLY_TAGS.include?(name)
                echo content
            else
                text content
            end
        end
        block.call if block
        echo "</#{name.html_escape}>"
    end
    nil
end

#indent(&block) ⇒ Object



15
16
17
18
19
20
# File 'lib/slick/helpers/text_builder.rb', line 15

def indent(&block)
    grab(&block).to_s.split(/\n/).each do |stringable|
        line "  #{stringable}"
    end
    nil
end

#line(stringable = "") ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/slick/helpers/text_builder.rb', line 6

def line(stringable = "")
    if response.body.length > 0
        echo "\n#{stringable}"
    else
        echo stringable
    end
    nil
end

#text(stringable) ⇒ Object



6
7
8
# File 'lib/slick/helpers/html_builder.rb', line 6

def text(stringable)
    echo stringable.html_escape
end