Sha256: cf1a8b39f9334e2b19b42750c7bf215de6fb0360b4606051eb76f7eda7d18611

Contents?: true

Size: 1.66 KB

Versions: 8

Compression:

Stored size: 1.66 KB

Contents

module Para
  module TagHelper
    def icon_link_to(name, url_options = nil, options = nil, &block)
      if block
        options, url_options = url_options, name
        name = capture { block.call }
      end

      if (icon = options.delete(:icon))
        icon_tag = content_tag(:i, '', class: "fa fa-#{ icon }")
        name = [icon_tag, name].join(' ').html_safe
      end

      link_to(name, url_options, options)
    end

    def listing_for(resources, options = {})
      model = resources.model
      attributes = model_field_mappings(model).fields
      relation = options.fetch(:relation, model.name.to_s.underscore.pluralize)
      allow_adding_resource = options.fetch(:addable, true)

      partial = :list
      partial = :tree if model.respond_to?(:roots) && can?(:tree, model)

      render(
        partial: find_partial_for(relation, partial),
        locals: {
          component: @component,
          resources: resources,
          relation: relation,
          model: model,
          attributes: attributes,
          allow_adding_resource: allow_adding_resource
        }
      )
    end

    def table_for(options)
      partial = :table
      render(
        partial: find_partial_for(
          options[:model].name.underscore.pluralize,
          partial
        ),
        locals: options
      )
    end

    def add_button_for(component, relation, model)
      return unless can?(:create, model)

      partial_name = if component.subclassable?
        :subclassable_add_button
      else
        :add_button
      end

      render partial: find_partial_for(relation, partial_name), locals: {
        component: component, model: model
      }
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
para-0.8.13 app/helpers/para/tag_helper.rb
para-0.8.12 app/helpers/para/tag_helper.rb
para-0.8.11 app/helpers/para/tag_helper.rb
para-0.8.10 app/helpers/para/tag_helper.rb
para-0.8.9 app/helpers/para/tag_helper.rb
para-0.8.8 app/helpers/para/tag_helper.rb
para-0.8.7 app/helpers/para/tag_helper.rb
para-0.8.5 app/helpers/para/tag_helper.rb