lib/staple/import_generator.rb in staple-0.1.7 vs lib/staple/import_generator.rb in staple-0.2.0
- old
+ new
@@ -1,50 +1,46 @@
require 'rails/generators'
module Staple
class ImportGenerator < Rails::Generators::Base
- desc 'Copy refills'
- # source_root File.expand_path("../../../source", __FILE__)
- # argument :snippet, type: :string, required: true
+ desc 'bring in the staple'
+ source_root File.join(File.dirname(__FILE__), '..', '..')
+ argument :actions, :type => :array, :default => []
- # def copy_html
- # copy_file_if_exists(
- # partial_name,
- # File.join('app', 'views', 'refills', partial_name),
- # )
- # end
+ def import_styles
+ gsub_file "app/assets/stylesheets/staple/#{component}.scss", "//&*default", "\n\t#{contents}//&*default" if contents
+ gsub_file "app/assets/stylesheets/staple/builders/build_#{component}.scss", "//&*default", "\n\t\t#{contents}//&*default" if contents
+ gsub_file "app/assets/stylesheets/staple/#{component}.scss", "//&*hover", "\n\t#{hover}//&*hover" if hover
+ gsub_file "app/assets/stylesheets/staple/builders/build_#{component}.scss", "//&*hover", "\n\t\t#{hover}//&*hover" if hover
+ puts "invalid operation. for available actions: rails g staple:list [option]" if !contents
+ end
- # def copy_styles
- # copy_file_if_exists(
- # File.join('stylesheets', 'refills', stylesheet_name),
- # File.join('app', 'assets', 'stylesheets', 'refills', stylesheet_name),
- # )
- # end
+ private
- # def copy_javascripts
- # copy_file_if_exists(
- # File.join('javascripts', 'refills', javascript_name),
- # File.join('app', 'assets', 'javascripts', 'refills', javascript_name),
- # )
- # end
+ def contents
+ file = File.join(self.class.source_root, 'source', 'styles', "#{component}", "#{pattern.dasherize}.scss")
+ get_file(file)
+ end
- # private
+ def hover
+ file = File.join(self.class.source_root, 'source', 'styles', "#{component}", "#{pattern.dasherize}-hover.scss")
+ get_file(file)
+ end
- # def copy_file_if_exists(source, destination)
- # if File.exists?(File.join(self.class.source_root, source))
- # copy_file source, destination
- # end
- # end
+ def get_file(file)
+ if File.file?(file)
+ return File.read(file)
+ else
+ return false
+ end
+ end
- # def partial_name
- # "_#{snippet.underscore}.html.erb"
- # end
+ def component
+ actions[0]
+ end
- # def stylesheet_name
- # "_#{snippet.dasherize}.scss"
- # end
+ def pattern
+ actions[1]
+ end
- # def javascript_name
- # "#{snippet.underscore}.js"
- # end
end
end