Module: Alchemy::BaseHelper
- Included in:
- Admin::BaseHelper, PagesHelper
- Defined in:
- app/helpers/alchemy/base_helper.rb
Instance Method Summary collapse
- #page_or_find(page) ⇒ Object deprecated Deprecated.
-
#render_icon(icon_name, options = {}) ⇒ String
Render a Remix icon.
-
#render_message(type = :info, msg = nil, &blk) ⇒ Object
Returns a div with an icon and the passed content The default message type is info, but you can also pass other types like :warning or :error.
- #shorten(text, length) ⇒ Object deprecated Deprecated.
-
#warning(message, text = nil) ⇒ Object
Logs a message in the Rails logger (warn level) and optionally displays an error message to the user.
Instance Method Details
#page_or_find(page) ⇒ Object
Deprecated.
Checks if the given argument is a String or a Page object. If a String is given, it tries to find the page via page_layout Logs a warning if no page is given.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/helpers/alchemy/base_helper.rb', line 53 def page_or_find(page) unless Current.language warning("No default language set up") return nil end if page.is_a?(String) page = Current.language.pages.find_by(page_layout: page) end if page.blank? warning("No Page found for #{page.inspect}") nil else page end end |
#render_icon(icon_name, options = {}) ⇒ String
Render a Remix icon
31 32 33 |
# File 'app/helpers/alchemy/base_helper.rb', line 31 def render_icon(icon_name, = {}) render Alchemy::Admin::Icon.new(icon_name, ) end |
#render_message(type = :info, msg = nil, &blk) ⇒ Object
Returns a div with an icon and the passed content The default message type is info, but you can also pass other types like :warning or :error
Usage:
<%= render_message :warning do
<p>Caution! This is a warning!</p>
<% end %>
45 46 47 |
# File 'app/helpers/alchemy/base_helper.rb', line 45 def (type = :info, msg = nil, &blk) render Alchemy::Admin::Message.new(msg || capture(&blk), type: type) end |
#shorten(text, length) ⇒ Object
Deprecated.
An alias for truncate. Left here for downwards compatibilty.
8 9 10 |
# File 'app/helpers/alchemy/base_helper.rb', line 8 def shorten(text, length) text.truncate(length: length) end |
#warning(message, text = nil) ⇒ Object
Logs a message in the Rails logger (warn level) and optionally displays an error message to the user.
15 16 17 18 19 20 21 22 |
# File 'app/helpers/alchemy/base_helper.rb', line 15 def warning(, text = nil) Logger.warn(, caller(1..1)) unless text.nil? (:warning) do text.html_safe end end end |