Sha256: b7f6c6167a232cf36baeae53439e0d3d418d3746936382b4841dd7c053c132dd

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

module MountainView
  class Component
    attr_reader :name

    def initialize(name)
      @name = name
    end

    def title
      @name.humanize
    end

    def styleguide_stubs
      YAML.load_file(stubs_file) || {}
    rescue Errno::ENOENT
      {}
    end

    def raw_stubs
      if styleguide_stubs.is_a?(Hash)
        # Stub is coming from Style Guide example file
        styleguide_stubs[:stubs] || {}
      elsif styleguide_stubs.is_a?(Array)
        # Stub is coming from use of component
        styleguide_stubs
      end
    end

    def component_stubs?
      component_stubs.any?
    end

    def component_stubs
      @component_stubs ||= raw_stubs.map do |component_properties|
        MountainView::Stub.new(component_properties)
      end
    end

    def stubs_file
      MountainView.configuration.components_path.join(name, "#{name}.yml")
    end

    def stubs?
      styleguide_stubs.any?
    end

    def stubs_extra_info?
      !stubs_extra_info.empty?
    end

    def stubs_extra_info
      if styleguide_stubs.is_a?(Hash) && styleguide_stubs.key?(:meta)
        styleguide_stubs[:meta]
      else
        {}
      end
    end

    def stubs_correct_format?
      stubs_are_a_hash_with_info? || styleguide_stubs.is_a?(Array)
    end

    def stubs_are_a_hash_with_info?
      styleguide_stubs.is_a?(Hash) && styleguide_stubs.key?(:stubs)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mountain_view-0.14.0 lib/mountain_view/component.rb