Class: Chili::Generators::FeatureGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/chili/feature/feature_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_assets_overrideObject



88
89
90
91
92
93
94
95
# File 'lib/generators/chili/feature/feature_generator.rb', line 88

def add_assets_override
  create_file 'app/overrides/layouts/application/assets.html.erb.deface' do "<!-- insert_bottom 'head' -->\n<%= stylesheet_link_tag '\#{feature.name}/application' %>\n<%= javascript_include_tag '\#{feature.name}/application' %>\n"
  end
end

#add_dummy_overrideObject



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/generators/chili/feature/feature_generator.rb', line 75

def add_dummy_override
  example_file_path = "app/overrides/layouts/application/example.html.erb.deface"
  create_file example_file_path do "<!-- insert_bottom 'body' -->\n<div style='background: #FFF;text-align: center; padding: 4px 0;position: fixed;width: 100%;z-index: 9999;top: 0;'>\n\#{feature.name} active - edit/remove this file:<br/>\n<strong>\#{feature.path}/\#{example_file_path}</strong><br/>\n<%= link_to 'deface docs', 'https://github.com/spree/deface', target: '_blank' %>\n</div>\n"
  end
end

#add_gem_to_main_gemfileObject



29
30
31
32
33
34
35
# File 'lib/generators/chili/feature/feature_generator.rb', line 29

def add_gem_to_main_gemfile
  gemfile =  "../../../Gemfile"
  group = "group :chili do\n"
  append_to_file gemfile, group
  append_to_file gemfile, "  gem '#{feature.name}', path: '#{feature.path}'\nend", after: group
  gsub_file gemfile, 'end  gem', '  gem' #nasty cleanup
end

#add_generator_proxyObject



97
98
99
100
101
102
103
104
# File 'lib/generators/chili/feature/feature_generator.rb', line 97

def add_generator_proxy
  create_file "lib/generators/#{feature.name}_generator.rb" do "class \#{feature.name.camelcase}Generator < Rails::Generators::Base\ninclude Chili::GeneratorProxy\nend\n"
  end
end

#automount_engineObject



59
60
61
# File 'lib/generators/chili/feature/feature_generator.rb', line 59

def automount_engine
  prepend_to_file 'config/routes.rb', "#{feature.name.camelcase}::Engine.automount!\n"
end

#chilify_application_controllerObject



51
52
53
# File 'lib/generators/chili/feature/feature_generator.rb', line 51

def chilify_application_controller
  gsub_file "app/controllers/#{feature.name}/application_controller.rb", "ActionController::Base", 'Chili::ApplicationController'
end

#clean_up_gitignoreObject



55
56
57
# File 'lib/generators/chili/feature/feature_generator.rb', line 55

def clean_up_gitignore
  gsub_file ".gitignore", /test\/dummy.*\n/, ''
end

#edit_gemspecObject



20
21
22
23
24
25
26
27
# File 'lib/generators/chili/feature/feature_generator.rb', line 20

def edit_gemspec
  require File.expand_path('../../../../chili/version', __FILE__)
  gemspec = "#{feature.name}.gemspec"
  gsub_file gemspec, 'TODO: Your name', `git config user.NAME`.chomp
  gsub_file gemspec, 'TODO: Your email', `git config user.email`.chomp
  gsub_file gemspec, /TODO(:\s)?/, ''
  inject_into_file gemspec, "  s.add_dependency 'chili', '~> #{Chili::VERSION.sub(/\.\d+$/,'')}'\n\n", before: '  s.add_development_dependency "sqlite3"'
end

#include_base_and_active_ifObject



67
68
69
70
71
72
73
# File 'lib/generators/chili/feature/feature_generator.rb', line 67

def include_base_and_active_if
  inject_into_file "lib/#{feature.name}.rb", after: "module #{feature.name.camelcase}\n" do "extend Chili::Base\nactive_if { true } # edit this to activate/deactivate feature at runtime\n"
  end
end

#include_chili_libsObject



63
64
65
# File 'lib/generators/chili/feature/feature_generator.rb', line 63

def include_chili_libs
  prepend_to_file "lib/#{feature.name}.rb", "require \"chili\"\n"
end

#remove_jquery_stuffObject



46
47
48
49
# File 'lib/generators/chili/feature/feature_generator.rb', line 46

def remove_jquery_stuff
  gsub_file "app/assets/javascripts/#{feature.name}/application.js", "//= require jquery_ujs\n", ''
  gsub_file "app/assets/javascripts/#{feature.name}/application.js", "//= require jquery\n", ''
end

#remove_unused_filesObject



37
38
39
40
41
42
43
44
# File 'lib/generators/chili/feature/feature_generator.rb', line 37

def remove_unused_files
  remove_dir "app/helpers/#{feature.name}"
  remove_dir 'app/views/layouts'
  remove_dir 'script'
  remove_file 'Gemfile'
  remove_file 'Rakefile'
  remove_file 'MIT-LICENSE'
end

#reset_destination_rootObject



16
17
18
# File 'lib/generators/chili/feature/feature_generator.rb', line 16

def reset_destination_root
  self.destination_root = ''
end

#run_plugin_generatorObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/generators/chili/feature/feature_generator.rb', line 5

def run_plugin_generator
  ARGV[0] = feature.path
  ARGV[1] = '--mountable'
  ARGV[2] = '--skip-test-unit'
  ARGV[3] = '--skip-bundle'

  require 'rails/generators'
  require 'rails/generators/rails/plugin/plugin_generator'
  Rails::Generators::PluginGenerator.start
end