Class: Syntaxer::Wizzard
- Inherits:
-
Object
- Object
- Syntaxer::Wizzard
- Defined in:
- lib/syntaxer/wizzard.rb
Constant Summary collapse
- LANG =
Interactive console wizzard
[:ruby, :haml, :sass, :javascript]
- FOLDERS_RAILS =
{ :ruby => ["app/*", "app/**/*", "lib/*", "lib/**/*"], :haml => ["app/views/*", "app/views/**/*"], :sass => ["public/stylesheets/sass/*", "public/stylesheets/sass/**/*"], :javascript => ["public/javascript/*", "public/javascript/**/*"] }
- DEFAULT_GLOB =
["*/*", "**/*"]
- FOLDERS =
{ :ruby => DEFAULT_GLOB, :haml => DEFAULT_GLOB, :sass => DEFAULT_GLOB, :javascript => DEFAULT_GLOB }
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #config ⇒ Object
-
#initialize(options) ⇒ Wizzard
constructor
A new instance of Wizzard.
- #run ⇒ Object
Constructor Details
#initialize(options) ⇒ Wizzard
Returns a new instance of Wizzard.
21 22 23 |
# File 'lib/syntaxer/wizzard.rb', line 21 def initialize @options = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
19 20 21 |
# File 'lib/syntaxer/wizzard.rb', line 19 def @options end |
Class Method Details
.start ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/syntaxer/wizzard.rb', line 51 def start = {} [:root_path] = Dir.getwd rails = false say("Some greeting message. Hello God of this computer! Please answer in couple of question:".color(:green)) # ask for the languages to install to_install = [] LANG.each do |lang| if agree("Install support of #{lang.to_s.capitalize}? (y/n)".color(:yellow)) default_paths = rails? ? FOLDERS_RAILS[lang] : FOLDERS[lang] paths = ask("Paths to check separated by comma (default are #{default_paths.inspect}):".color(:yellow)) if paths.empty? paths = default_paths else paths = paths.split(',').map{|l| l.gsub(/\s/,'')} end to_install.push([lang, paths]) end end [:languages] = to_install # ask for path to save config if rails? say("Rails application detected. Config file saved to config/synaxer.rb".color(:green)) rails = true config_path = "config" else config_path = ask("Specify where to save syntaxer's config file (./ by default):".color(:yellow)) config_path = '.' if config_path.empty? = File.(config_path) [:config_dir_exists] = FileTest.directory?() [:create_config_dir] = agree("No such directory found #{}. Create it?".color(:green)) unless [:config_dir_not_exists] end [:rails] = rails [:config_path] = config_path # trying to detect GIT begin g = ::Git.open([:root_path]) [:git] = agree("Found git repo in #{File.([:root_path])}. Would you like install hook to check syntax before every commit? (y/n)".color(:yellow)) rescue [:git] = false end Wizzard.new().run # buy message say("Syntaxer is configured and installed. You can edit config in #{File.join(config_path, Syntaxer::SYNTAXER_CONFIG_FILE_NAME)}".color(:green)) rescue Interrupt => e # external quit puts "\nBuy" end |
Instance Method Details
#config ⇒ Object
43 44 45 46 47 |
# File 'lib/syntaxer/wizzard.rb', line 43 def config reader = Reader::DSLReader.build writer = Writer.new(@options[:languages], reader.rules) writer.get_config end |
#run ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/syntaxer/wizzard.rb', line 25 def run FileUtils.mkdir_p(@options[:config_path]) if !@options[:config_dir_exists] && @options[:create_config_dir] config_full_path = File.join(@options[:config_path], Syntaxer::SYNTAXER_CONFIG_FILE_NAME) File.open(config_full_path, 'w') do |f| f.write(config) end if @options[:git] = {:root_path => @options[:root_path], :repository => :git, :config_file => File.join(@options[:config_path], Syntaxer::SYNTAXER_CONFIG_FILE_NAME)} .merge!({:rails => true}) if [:rails] Syntaxer.make_hook() end if @options[:rails] && @options[:languages].include?(:javascript) system('rake jslint:copy_config') end end |