Sha256: a0e2e497a9db549be683e74d43ea2c375a0f9cd59c711d8c84f9ce1ac28f6e53

Contents?: true

Size: 1.69 KB

Versions: 2

Compression:

Stored size: 1.69 KB

Contents

module ApplicationHelper
  def parent_layout(layout)
    layout = layout.to_s
    layout = "layouts/#{layout}" unless layout.include?('/')

    @view_flow.set(:layout, output_buffer)

    output = render file: layout

    self.output_buffer = ActionView::OutputBuffer.new(output)
  end

  def modal_for(id, modal_title = nil, &block)
    modal_id = id + '-modal'
    modal_body = capture(&block)
    render partial: 'common/modal', locals: {modal_id: modal_id,
                                             modal_title: modal_title,
                                             modal_body: modal_body}
  end

  def svg_tag(filename, options = {})
    options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size]

    assets = Rails.application.assets
    file = assets.find_asset(filename + '.svg').body.force_encoding('UTF-8')
    doc = Nokogiri::HTML::DocumentFragment.parse file

    svg = doc.at_css 'svg'

    svg["class"] = options[:class] if options[:class]
    svg["id"] = options[:id] if options[:id]
    svg["width"] = options[:width] if options[:width]
    svg["height"] = options[:height] if options[:height]

    raw doc
  end

  def close_button_tag(options = {})
    options = Hash(options).reverse_merge!({type: 'button', class: 'close', aria: {label: 'Close'}})
    content_tag :button, options do
      content_tag :span, aria: {hidden: 'true'} do
        '×'.html_safe
      end
    end
  end

  def icon_tag(name)
    content_tag :i, nil, class: "icon icon-#{name}"
  end

  def flash_class(level)
    case level.to_sym
      when :notice then 'alert alert-success'
      when :error then 'alert alert-danger'
      when :alert then 'alert alert-danger'
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pineapples-0.3.345 lib/pineapples/templates/app/helpers/application_helper.rb
pineapples-0.3.34 lib/pineapples/templates/app/helpers/application_helper.rb