Sha256: 2c91ec4e9f9df950d8a82896f4cd8e1fb52b55febb8a99914ac6b2fa7b5eda81

Contents?: true

Size: 1.86 KB

Versions: 2

Compression:

Stored size: 1.86 KB

Contents

require 'rails/generators'

module Staple
  class ThemeGenerator < Rails::Generators::Base
    desc 'bring in the staple'
    source_root File.join(File.dirname(__FILE__), '..', '..')
    argument :actions, :type => :array, :default => []

    def call_generators
        if global?
            #call self with each
            components = %w(buttons colors forms tables typography)
            components.each do |c|
                generate "staple:theme", "#{c}", "#{theme}"
            end
        else
            if theme_definition
                if yes? "Any changes you have made to staple/#{component}.scss or builders will be overwritten. Continue? (Y/N)"
                    #tear down previous styles
                    copy_file "source/styles/staple/#{component}.scss", "app/assets/stylesheets/staple/#{component}.scss", :force => true
                    copy_file "source/styles/staple/builders/build_#{component}.scss", "app/assets/stylesheets/staple/builders/build_#{component}.scss", :force => true
                    patterns = theme_definition.split("\n")
                    patterns.each do |pattern|
                        generate "staple:#{component}", "import", "#{pattern}"
                    end
                end
            end
        end
    end

    private

    def theme_definition
        file = File.join(self.class.source_root, 'source', 'styles', "#{component}", "themes", "#{theme.dasherize}.theme")
        get_file(file)
    end

    def get_file(file)
        if File.file?(file)
            File.read(file)
        else
            false
        end
    end

    def global?
        if component=="global"
            true
        else
            false
        end
    end

    def component
        actions[0]
    end

    def theme
        actions[1]
    end

  end
end

#rails g staple:theme buttons plastic
#rails g staple:theme global plastic

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
staple-0.4.3 lib/staple/theme_generator.rb
staple-0.4.2 lib/staple/theme_generator.rb