Module: Lesli::HtmlHelper

Defined in:
app/helpers/lesli/html_helper.rb

Instance Method Summary collapse

Instance Method Details

#dd(object) ⇒ Object

Prints objects as JSON code



116
117
118
119
120
121
122
# File 'app/helpers/lesli/html_helper.rb', line 116

def dd object
    (:pre) do 
        (:code) do
            ERB::Util.html_escape JSON.pretty_generate(object.as_json)
        end 
    end 
end

#lesli_application_body_classObject

return a string with a css class to identify the body example: builder engine-controller action



75
76
77
# File 'app/helpers/lesli/html_helper.rb', line 75

def lesli_application_body_class
    [lesli_instance_code, controller_path.sub("_","-").split("/"), action_name].join(" ")
end

#lesli_asset_path(engine = nil, stylesheet = 'application') ⇒ Object

Return a string path to load the template stylesheet by default we always return the latest version of the template

stylesheet from main App lesli_stylesheet_path()

/assets/application.css

Specific stylesheet from Engine lesli_stylesheet_path(:lesli, ‘application’) /assets/lesli/application.css

Specific stylesheet from gem lesli_stylesheet_path(:lesli_assets, ‘templates/application’) /assets/lesli_assets/templates/application.css



93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/helpers/lesli/html_helper.rb', line 93

def lesli_asset_path(engine = nil, stylesheet = 'application')

    # Stylesheets from specific engine
    return "#{engine}/#{stylesheet}" if engine.present?

    # Get current engine information
    engine_code = lesli_engine(:code)

    # Rails main host app stylesheets
    return 'application' if engine_code == 'root'

    # Rails engines stylesheets
    "#{engine_code}/#{stylesheet}"
end

#lesli_faviconObject

Prints link tags to add favicon to websites



37
38
39
40
41
42
43
44
# File 'app/helpers/lesli/html_helper.rb', line 37

def lesli_favicon
    icon_path = image_url("lesli_assets/brand/favicon.svg")
    safe_join([
        tag.link(href: icon_path, rel: "alternate icon"),
        tag.link(href: icon_path, rel: "icon", type: "image/svg+xml"),
        tag.link(href: icon_path, rel: "mask-icon", color: "#ff8a01")
    ])
end

#lesli_svg(name) ⇒ Object

print a custom icon for lesli



109
110
111
112
113
# File 'app/helpers/lesli/html_helper.rb', line 109

def lesli_svg(name)
    ("svg", width: "64px", height: "64px") do
        "<use xlink:href='##{name}'></use>".html_safe
    end
end

#lesli_website_meta_descriptionObject

build description using custom data from controller or engine gem description



66
67
68
69
70
71
# File 'app/helpers/lesli/html_helper.rb', line 66

def lesli_website_meta_description
    # if want to get description from gem you can use:
    # Gem::Specification.find_by_name(engine_name).description
    # Gem::Specification.find_by_name(engine_name).summary
    @application_html_description || ""
end

#lesli_website_titleObject

build the text for the html document title this helper works only for rails pages, for vue apps the title must be handled with JS



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/helpers/lesli/html_helper.rb', line 48

def lesli_website_title

    # Use instance variable if set, 
    return @application_html_title if @application_html_title.present?

    # otherwise construct a dynamic title
    title = controller_path.delete_prefix("lesli_")

    # Append action name unless it's "index"
    title += "/#{action_name}" unless action_name == "index"

    # Append company name if present
    title += " · #{Lesli.config.company.dig(:name)}"

    title
end