Module: Lesli::HtmlHelper
- Defined in:
- app/helpers/lesli/html_helper.rb
Instance Method Summary collapse
-
#dd(object) ⇒ Object
Prints objects as JSON code.
-
#lesli_application_body_class ⇒ Object
return a string with a css class to identify the body example: builder engine-controller action.
-
#lesli_favicon ⇒ Object
Prints link tags to add favicon to websites.
-
#lesli_stylesheet_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.
-
#lesli_svg(name) ⇒ Object
print a custom icon for lesli.
-
#lesli_website_meta_description ⇒ Object
build description using custom data from controller or engine gem description.
-
#lesli_website_title ⇒ Object
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.
Instance Method Details
#dd(object) ⇒ Object
Prints objects as JSON code
112 113 114 115 116 117 118 |
# File 'app/helpers/lesli/html_helper.rb', line 112 def dd object content_tag(:pre) do content_tag(:code) do ERB::Util.html_escape JSON.pretty_generate(object.as_json) end end end |
#lesli_application_body_class ⇒ Object
return a string with a css class to identify the body example: builder engine-controller action
71 72 73 |
# File 'app/helpers/lesli/html_helper.rb', line 71 def lesli_application_body_class [lesli_instance_code, controller_path.sub("_","-").split("/"), action_name].join(" ") end |
#lesli_favicon ⇒ Object
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/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_stylesheet_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
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/helpers/lesli/html_helper.rb', line 89 def lesli_stylesheet_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_svg(name) ⇒ Object
print a custom icon for lesli
105 106 107 108 109 |
# File 'app/helpers/lesli/html_helper.rb', line 105 def lesli_svg(name) content_tag("svg", width: "64px", height: "64px") do "<use xlink:href='##{name}'></use>".html_safe end end |
#lesli_website_meta_description ⇒ Object
build description using custom data from controller or engine gem description
62 63 64 65 66 67 |
# File 'app/helpers/lesli/html_helper.rb', line 62 def # 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_title ⇒ Object
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 |
# File 'app/helpers/lesli/html_helper.rb', line 48 def lesli_website_title # Use instance variable if set, otherwise construct a dynamic title title = @application_html_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 |