Module: Lookbook::ApplicationHelper

Defined in:
app/helpers/lookbook/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#beautify(source, language = "html") ⇒ Object



26
27
28
29
30
# File 'app/helpers/lookbook/application_helper.rb', line 26

def beautify(source, language = "html")
  source = source.strip
  result = language.downcase == "html" ? HtmlBeautifier.beautify(source) : source
  result.strip.html_safe
end

#class_names(*args) ⇒ Object



48
49
50
51
# File 'app/helpers/lookbook/application_helper.rb', line 48

def class_names(*args)
  tokens = build_tag_values(*args).flat_map { |value| value.to_s.split(/\s+/) }.uniq
  safe_join(tokens, " ")
end

#component(name, **attrs, &block) ⇒ Object



40
41
42
43
44
45
# File 'app/helpers/lookbook/application_helper.rb', line 40

def component(name, **attrs, &block)
  render "lookbook/components/#{name}",
    classes: class_names(attrs[:class]),
    **attrs.except(:class),
    &block
end

#configObject



7
8
9
# File 'app/helpers/lookbook/application_helper.rb', line 7

def config
  Lookbook::Engine.config.lookbook
end

#highlight(source, language, opts = {}) ⇒ Object



20
21
22
23
24
# File 'app/helpers/lookbook/application_helper.rb', line 20

def highlight(source, language, opts = {})
  formatter = Lookbook::CodeFormatter.new(opts)
  lexer = Rouge::Lexer.find(language)
  formatter.format(lexer.lex(source)).html_safe
end

#icon(name = nil, size: 4, **attrs) ⇒ Object



32
33
34
35
36
37
38
# File 'app/helpers/lookbook/application_helper.rb', line 32

def icon(name = nil, size: 4, **attrs)
  render "lookbook/components/icon",
    name: name,
    size: size,
    classes: class_names(attrs[:class]),
    **attrs.except(:class)
end

#markdown(text) ⇒ Object



11
12
13
14
15
16
17
18
# File 'app/helpers/lookbook/application_helper.rb', line 11

def markdown(text)
  markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, {
    tables: true,
    fenced_code_blocks: true,
    disable_indented_code_blocks: true
  })
  markdown.render(text).html_safe
end