Sha256: 4b65eaf7e026c602ee40b99d8af5d8756e89c14b3ca457117e0ca391dd78c1f7

Contents?: true

Size: 1.86 KB

Versions: 13

Compression:

Stored size: 1.86 KB

Contents

module Woo
  module StyleguideHelper

    BASE_PATH = "app/views/styleguide"

    def ui_elements
      ui_elements_partials = Dir.glob("#{BASE_PATH}/ui_elements/_*.html*")
      ui_elements_partials.map do |filepath|
        page_hash(filepath)
      end
    end

    def current_page(folder, page)
      filepath = Dir.glob("#{BASE_PATH}/#{folder}/#{page}.html*").first
      page_hash(filepath)
    end

    def render_haml_string(contents)
      Haml::Engine.new(contents).render
    end

    def load_notes(filepath)
      haml_frontmatter = /^-{1,3}$\n(?<notes_contents>.*)^-{1,3}$\n/m
      match = haml_frontmatter.match(File.read(filepath))
      match[:notes_contents] if match
    end

    def page_hash(filepath)
      lang     = filepath.match(/haml$/) ? 'haml' : 'markup'
      name     = File.basename(filepath)
                     .gsub(/^\_|.html.*/, '')

      {
        :name       => name,
        :filepath   => filepath,
        :contents   => File.read(filepath).sub(/^-{1,3}$\n.*^-{1,3}$\n/m, ''),
        :notes      => load_notes(filepath),
        :lang       => lang
      }
    end

    def navigation_hash
      folders = folders_names
      folders.each_with_object({}) do |filepath, collection|
        collection[filepath] = folder_files(filepath)
      end
    end

    def folders_names
      Dir.glob("#{BASE_PATH}/*").map do |filepath|
        name = File.basename(filepath)
        name if File.directory?(filepath) && name != 'shared'
      end.compact
    end

    def folder_files(folder_name)
      prefix = (folder_name == 'ui_elements') ? '#' : "#{folder_name}/"

      files = Dir.glob("#{BASE_PATH}/#{folder_name}/*.html*")
      files.map do |filepath|
        name = File.basename(filepath)
                   .gsub(/^\_|.html.*/, '')

        route = "/styleguide/#{prefix}#{name}"

        {:name => name, :route => route}
      end
    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
woo-0.1.12 app/helpers/woo/styleguide_helper.rb
woo-0.1.11 app/helpers/woo/styleguide_helper.rb
woo-0.1.10 app/helpers/woo/styleguide_helper.rb
woo-0.1.9 app/helpers/woo/styleguide_helper.rb
woo-0.1.8 app/helpers/woo/styleguide_helper.rb
woo-0.1.7 app/helpers/woo/styleguide_helper.rb
woo-0.1.6 app/helpers/woo/styleguide_helper.rb
woo-0.1.5 app/helpers/woo/styleguide_helper.rb
woo-0.1.4 app/helpers/woo/styleguide_helper.rb
woo-0.1.3 app/helpers/woo/styleguide_helper.rb
woo-0.1.2 app/helpers/woo/styleguide_helper.rb
woo-0.1.0 app/helpers/woo/styleguide_helper.rb
woo-0.1.0.pre1 app/helpers/woo/styleguide_helper.rb