Module: Lesli::GeneralHelper
- Defined in:
- app/helpers/lesli/general_helper.rb
Instance Method Summary collapse
-
#application_body_class ⇒ Object
return a string with a css class to identify the body example: builder engine-controller action.
- #dd(object) ⇒ Object
-
#language_flag(locale) ⇒ Object
return flag code according to locale code.
-
#language_name(locale) ⇒ Object
return the name of the language.
-
#language_url(locale) ⇒ Object
build a url path to change locales.
-
#lesli_svg(name) ⇒ Object
print a custom icon for lesli.
-
#website_meta_description ⇒ Object
build description using custom data from controller or engine gem description.
-
#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
#application_body_class ⇒ Object
return a string with a css class to identify the body example: builder engine-controller action
61 62 63 |
# File 'app/helpers/lesli/general_helper.rb', line 61 def application_body_class [lesli_instance_code, controller_path.sub("_","-").split("/"), action_name].join(" ") end |
#dd(object) ⇒ Object
88 89 90 91 92 93 94 |
# File 'app/helpers/lesli/general_helper.rb', line 88 def dd object content_tag(:pre) do content_tag(:code) do h JSON.pretty_generate(object.as_json) end end end |
#language_flag(locale) ⇒ Object
return flag code according to locale code
42 43 44 45 |
# File 'app/helpers/lesli/general_helper.rb', line 42 def language_flag(locale) locale = "gb" if locale.to_s == "en" locale end |
#language_name(locale) ⇒ Object
return the name of the language
48 49 50 |
# File 'app/helpers/lesli/general_helper.rb', line 48 def language_name(locale) Lesli.config.locales.dig(locale) || "undefined" end |
#language_url(locale) ⇒ Object
build a url path to change locales
37 38 39 |
# File 'app/helpers/lesli/general_helper.rb', line 37 def language_url(locale) "/lesli/language?locale=#{locale}" end |
#lesli_svg(name) ⇒ Object
print a custom icon for lesli
53 54 55 56 57 |
# File 'app/helpers/lesli/general_helper.rb', line 53 def lesli_svg(name) content_tag("svg", width: "64px", height: "64px") do "<use xlink:href='##{name}'></use>".html_safe end end |
#website_meta_description ⇒ Object
build description using custom data from controller or engine gem description
81 82 83 84 85 86 |
# File 'app/helpers/lesli/general_helper.rb', line 81 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 |
#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
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/helpers/lesli/general_helper.rb', line 67 def 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 |