Sha256: e606cbd6c27a13f6763a96f431084c76b755e0cc41eb5c409cbfd0f76835215b

Contents?: true

Size: 1.11 KB

Versions: 12

Compression:

Stored size: 1.11 KB

Contents

module Lookbook
  module Taggable
    def lookbook_hidden?
      if code_object&.tag(:hidden)
        code_object.tag(:hidden).text.strip != "false"
      end
    end

    def lookbook_label
      code_object&.tag(:label)&.text
    end

    def lookbook_notes
      if code_object&.docstring
        code_object.docstring.to_s.strip
      end
    end

    def lookbook_group
      code_object&.group
    end

    def lookbook_display_params
      display_params = {}.with_indifferent_access
      if code_object&.tags(:display).present?
        code_object.tags(:display).each do |tag|
          parts = tag.text.strip.match(/^([^\s]*)\s?(.*)$/)
          if parts.present?
            begin
              display_params[parts[1]] = YAML.safe_load(parts[2] || "~")
            rescue SyntaxError => err
              Rails.logger.error("\nšŸ‘€ [Lookbook] Invalid JSON in @display tag.\nšŸ‘€ [Lookbook] (#{err})\n")
            end
          end
        end
      end
      display_params
    end

    # private

    def code_object
      @code_object ||= Lookbook::Engine.parser.get_code_object(taggable_object_path)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
lookbook-0.6.1 lib/lookbook/taggable.rb
lookbook-0.6.0 lib/lookbook/taggable.rb
lookbook-0.5.2 lib/lookbook/taggable.rb
lookbook-0.5.1 lib/lookbook/taggable.rb
lookbook-0.5.0 lib/lookbook/taggable.rb
lookbook-0.5.0.beta.2 lib/lookbook/taggable.rb
lookbook-0.5.0.beta.1 lib/lookbook/taggable.rb
lookbook-0.5.0.beta.0 lib/lookbook/taggable.rb
lookbook-0.4.8 lib/lookbook/taggable.rb
lookbook-0.4.7 lib/lookbook/taggable.rb
lookbook-0.4.6 lib/lookbook/taggable.rb
lookbook-0.4.5 lib/lookbook/taggable.rb