Module: Spina::ApplicationHelper
- Included in:
- ApplicationController
- Defined in:
- app/helpers/spina/application_helper.rb
Instance Method Summary collapse
- #current_account ⇒ Object
- #error_explanation!(resource) ⇒ Object
- #image_tag_with_at2x(name_at_1x, options = {}) ⇒ Object
- #link_to_add_fields(name, f, association) ⇒ Object
- #markdown(text) ⇒ Object
Instance Method Details
#current_account ⇒ Object
33 34 35 |
# File 'app/helpers/spina/application_helper.rb', line 33 def current_account @current_account ||= Account.first end |
#error_explanation!(resource) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/helpers/spina/application_helper.rb', line 42 def error_explanation!(resource) return "" if resource.errors.empty? = resource.errors..map { |msg| content_tag(:li, msg) }.join sentence = I18n.t("errors.messages.not_saved", count: resource.errors.count, resource: resource.class.model_name.human.downcase) html = <<-HTML <div id="error_explanation" class="notification notification-error" data-icon='m'> <p>#{sentence}</p> <ul>#{}</ul> </div> HTML html.html_safe end |
#image_tag_with_at2x(name_at_1x, options = {}) ⇒ Object
37 38 39 40 |
# File 'app/helpers/spina/application_helper.rb', line 37 def image_tag_with_at2x(name_at_1x, ={}) name_at_2x = name_at_1x.gsub(%r{\.\w+$}, '@2x\0') image_tag(name_at_1x, .merge("data-at2x" => asset_path(name_at_2x))) end |
#link_to_add_fields(name, f, association) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'app/helpers/spina/application_helper.rb', line 24 def link_to_add_fields(name, f, association) new_object = f.object.send(association).klass.new id = new_object.object_id fields = f.fields_for(association, new_object, child_index: id) do |builder| render(association.to_s.singularize + "_fields", f: builder) end link_to(name, '#', class: "add_fields button button-primary button-link", data: {id: id, fields: fields.gsub("\n", ""), icon: '&'}) end |
#markdown(text) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/helpers/spina/application_helper.rb', line 4 def markdown(text) sha = Digest::SHA1.hexdigest(text.to_s) Rails.cache.fetch sha do renderer = Redcarpet::Render::HTML.new(hard_wrap: true, filter_html: false) = { autolink: true, no_intra_emphasis: true, fenced_code_blocks: true, lax_spacing: true, strikethrough: true, superscript: true } html = Redcarpet::Markdown.new(renderer, ).render(text.to_s) html.gsub!(/\[vimeo\s+(\d*)\]/, '<figure class="video"><iframe src="http://player.vimeo.com/video/\1?portrait=0&title=0&byline=0" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></figure>') html.gsub!(/\[button\s+(.*)\](.*)\[\/button\]/, '<a href="\1" class="button">\2</a>') html.html_safe end end |