Sha256: 2ae718adc8760e5560ce5232952ba0f3bde883a16c8fd007a2655ffd0fd90a61
Contents?: true
Size: 1.91 KB
Versions: 4
Compression:
Stored size: 1.91 KB
Contents
require 'rails/generators' module Staple class ColorsGenerator < Rails::Generators::Base desc 'pending' source_root File.join(File.dirname(__FILE__), '..', '..') argument :actions, :type => :array, :default => [] def delegate case "#{action}" when "import" import when "remove" remove else puts "unknown command" end end private #ACTIONS def import puts "#{component} import #{variable} -> #{color}" if File.readlines(filename).any?{ |l| l["$#{variable}:"] } #replace line w/ new gsub_file(filename, /\$#{variable}:.*$/, "$#{variable}: #{contents};") if contents gsub_file(filename, /\$#{variable}:.*$/, "$#{variable}: #{color};") if !contents else #create variable w/color gsub_file(filename, "//&*append", "$#{variable}: #{contents};\n//&*append") if contents gsub_file(filename, "//&*append", "$#{variable}: #{color};\n//&*append") if !contents end #check for variable, if yes: replace line, if no, create end def remove #check for variable, and remove line gsub_file(filename, /\$#{variable}:.*$/, "") end #HELPER METHODS def contents file = File.join(self.class.source_root, 'source', 'styles', "#{component}", "#{color.dasherize}.color") get_file(file) end def get_file(file) if File.file?(file) return File.read(file) else return false end end def filename "app/assets/stylesheets/staple/#{component}.scss" end def not_valid !contents end #DEFINE def action actions[0] end def variable actions[1].split(":").first end def color actions[1].split(":").last end def component "colors" end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
staple-0.4.5 | lib/staple/colors_generator.rb |
staple-0.4.4 | lib/staple/colors_generator.rb |
staple-0.4.3 | lib/staple/colors_generator.rb |
staple-0.4.2 | lib/staple/colors_generator.rb |