fetty-generators 2.0.1 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,7 +16,7 @@ module Fetty
16
16
  else
17
17
  unless using_fetty_authentication?
18
18
  @orm = using_mongoid? ? 'mongoid' : 'active_record'
19
- add_gem { gem "bcrypt-ruby", :require => "bcrypt" }
19
+ gem "bcrypt-ruby", :require => "bcrypt"
20
20
  generate_users
21
21
  generate_sessions
22
22
  generate_reset_passwords
@@ -21,7 +21,7 @@ module Fetty
21
21
  if file_exists?(@model_path)
22
22
  unless using_mongoid?
23
23
  @orm = using_mongoid? ? 'mongoid' : 'active_record'
24
- add_gem { gem "ancestry" }
24
+ gem "ancestry"
25
25
  copy_models_and_migrations
26
26
  copy_controller_and_helper
27
27
  copy_views
@@ -25,7 +25,7 @@ module Fetty
25
25
  print_usage unless scaffold_name.underscore =~ /^[a-z][a-z0-9_\/]+$/ && !attributes.empty?
26
26
  print_usage unless attributes.drop_while { |arg| arg.include?(':') }.count == 0
27
27
 
28
- if check_required_gems? "jquery-rails", "simple_form", "kaminari", "ckeditor", "carrierwave"
28
+ if check_required_gems? "jquery-rails", "simple_form", "kaminari"
29
29
  @orm = using_mongoid? ? 'mongoid' : 'active_record'
30
30
 
31
31
  setting_model_attributes
@@ -49,7 +49,7 @@ module Fetty
49
49
  generate_specs if using_rspec?
50
50
  end
51
51
  else
52
- raise "Missing gems: jquery-rails, simple_form, kaminari, ckeditor, carrierwave"
52
+ raise "Missing gems: jquery-rails simple_form kaminari"
53
53
  end
54
54
  rescue Exception => e
55
55
  print_notes(e.message,"error",:red)
@@ -23,13 +23,15 @@ module Fetty
23
23
  @selected_gems = options.only.empty? ? options.reject { |k,v| k == "only" || k == "mongoid" || v == false }.keys : options.only
24
24
  @selected_gems.each do |gems|
25
25
  asking "Would you like to setup #{gems} gem?" do
26
- send("setup_#{gems}")
26
+ send("setup_#{gems.gsub('-','_')}")
27
27
  end
28
28
  end
29
- remove_file 'public/index.html' if file_exists?('public/index.html')
30
- remove_file 'public/images/rails.png' if file_exists?('public/images/rails.png')
31
- print_notes("Refreshing Bundle")
32
- refresh_bundle
29
+ if options.only.empty?
30
+ remove_file 'public/index.html' if file_exists?('public/index.html')
31
+ remove_file 'public/images/rails.png' if file_exists?('public/images/rails.png')
32
+ print_notes("Refreshing Bundle")
33
+ refresh_bundle
34
+ end
33
35
  rescue Exception => e
34
36
  print_notes(e.message,"error",:red)
35
37
  end
@@ -37,10 +39,8 @@ module Fetty
37
39
  private
38
40
 
39
41
  def setup_mongoid
40
- add_gem do
41
- gem "bson_ext"
42
- gem "mongoid"
43
- end
42
+ gem "bson_ext"
43
+ gem "mongoid"
44
44
  generate("mongoid:config")
45
45
  set_application_config { " config.mongoid.preload_models = true\n" }
46
46
  rescue Exception => e
@@ -48,7 +48,7 @@ private
48
48
  end
49
49
 
50
50
  def setup_cancan
51
- add_gem { gem "cancan" }
51
+ gem "cancan"
52
52
  copy_file 'ability.rb', 'app/models/ability.rb'
53
53
  inject_into_class 'app/controllers/application_controller.rb', ApplicationController do
54
54
  " rescue_from CanCan::AccessDenied do |exception| flash[:alert] = exception.message; redirect_to root_url end;\n"
@@ -58,24 +58,22 @@ private
58
58
  end
59
59
 
60
60
  def setup_jquery_rails
61
- add_gem { gem "jquery-rails" }
61
+ gem "jquery-rails"
62
62
  generate("jquery:install")
63
63
  rescue Exception => e
64
64
  raise e
65
65
  end
66
66
 
67
67
  def setup_simple_form
68
- add_gem { gem "simple_form" }
68
+ gem "simple_form"
69
69
  generate("simple_form:install")
70
70
  rescue Exception => e
71
71
  raise e
72
72
  end
73
73
 
74
74
  def setup_carrierwave
75
- add_gem do
76
- gem "mini_magick"
77
- gem "carrierwave"
78
- end
75
+ gem "mini_magick"
76
+ gem "carrierwave"
79
77
  copy_file 'image_uploader.rb', 'app/uploaders/image_uploader.rb'
80
78
  copy_file 'file_uploader.rb', 'app/uploaders/file_uploader.rb'
81
79
  print_notes("carrierwave will use mini_magick by default!")
@@ -84,7 +82,7 @@ private
84
82
  end
85
83
 
86
84
  def setup_kaminari
87
- add_gem { gem "kaminari" }
85
+ gem "kaminari"
88
86
  rescue Exception => e
89
87
  raise e
90
88
  end
@@ -94,11 +92,11 @@ private
94
92
  destroy("public/javascripts/ckeditor")
95
93
  ver = ask("==> What version of CKEditor javascript files do you need? [default 3.5.4]")
96
94
  if ver == "3.5.4" || ver.blank?
97
- add_gem { gem "ckeditor", "3.5.4" }
95
+ gem "ckeditor", "3.5.4"
98
96
  template "ckeditor.rb", "config/initializers/ckeditor.rb"
99
97
  extract("setup/templates/ckeditor.tar.gz","public/javascripts","ckeditor")
100
98
  else
101
- add_gem { gem "ckeditor", ver }
99
+ gem "ckeditor", ver
102
100
  generate("ckeditor:base --version=#{ver}")
103
101
  end
104
102
  rescue Exception => e
@@ -109,18 +107,16 @@ private
109
107
  # remove the existing install (if any)
110
108
  destroy("Guardfile")
111
109
 
112
- add_gem do
113
- gem 'rspec-rails', :group => [:development, :test]
114
- gem 'capybara', :group => [:development, :test]
115
- gem 'factory_girl_rails', :group => [:development, :test]
116
- gem 'faker', :group => [:development, :test]
117
- gem 'database_cleaner', :group => [:development, :test]
118
- gem 'escape_utils', :group => [:development, :test]
119
- gem 'guard-rspec', :group => [:development, :test]
120
- if RUBY_PLATFORM =~ /darwin/i
121
- gem 'rb-fsevent', :group => [:development, :test], :require => false
122
- gem 'growl', :group => [:development, :test]
123
- end
110
+ gem 'rspec-rails', :group => [:development, :test]
111
+ gem 'capybara', :group => [:development, :test]
112
+ gem 'factory_girl_rails', :group => [:development, :test]
113
+ gem 'faker', :group => [:development, :test]
114
+ gem 'database_cleaner', :group => [:development, :test]
115
+ gem 'escape_utils', :group => [:development, :test]
116
+ gem 'guard-rspec', :group => [:development, :test]
117
+ if RUBY_PLATFORM =~ /darwin/i
118
+ gem 'rb-fsevent', :group => [:development, :test], :require => false
119
+ gem 'growl', :group => [:development, :test]
124
120
  end
125
121
 
126
122
  copy_file 'escape_utils.rb', 'config/initializers/escape_utils.rb'
@@ -132,10 +128,8 @@ private
132
128
 
133
129
  asking "Would you like to install Cucumber?" do
134
130
  destroy("features")
135
- add_gem do
136
- gem "cucumber-rails", :group => [:development, :test]
137
- gem "guard-cucumber", :group => [:development, :test]
138
- end
131
+ gem "cucumber-rails", :group => [:development, :test]
132
+ gem "guard-cucumber", :group => [:development, :test]
139
133
  generate("cucumber:install", "--rspec", "--capybara")
140
134
  template 'env.rb', 'features/support/env.rb', :force => true
141
135
  `guard init cucumber`
@@ -2,4 +2,4 @@ Description:
2
2
  The fetty:views generator creates a basic layout, stylesheet and
3
3
  helper which will give some structure to starting your Rails app.
4
4
 
5
- Also able to convert your template views from ERB to HAML or vice versa.
5
+ Also able to convert your template views from ERB to HAML.
@@ -4,16 +4,14 @@ module Fetty
4
4
  module Generators
5
5
  class ViewsGenerator < Base
6
6
 
7
- argument :arg, :type => :string, :required => true, :banner => 'layout | erb:to:haml | haml:to:erb'
7
+ argument :arg, :type => :string, :required => true, :banner => 'layout | erb_to_haml'
8
8
 
9
9
  def generate_views
10
10
  case arg
11
11
  when "layout"
12
- generate_layout
13
- when "erb:to:haml"
12
+ generate_layout
13
+ when "erb_to_haml"
14
14
  erb_to_haml
15
- when "haml:to:erb"
16
- haml_to_erb
17
15
  end
18
16
  rescue Exception => e
19
17
  print_notes(e.message,"error",:red)
@@ -37,50 +35,32 @@ private
37
35
  def erb_to_haml
38
36
  asking "Are you sure want to convert all your views from ERB to HAML ?" do
39
37
  # => Cycles through the views folder and searches for erb files
40
- # prepare_convert_gems
41
- # Dir.glob("app/views/**/*.erb").each do |file|
42
- # puts "Convert ERB: #{file}"
43
- # unless file_exists? file.gsub(/erb$/, "haml")
44
- # `html2haml #{file} | cat > #{file.gsub(/erb$/, "haml")}`
45
- # File.delete(file)
46
- # end
47
- # end
48
- end
49
- rescue Exception => e
50
- raise e
51
- end
52
-
53
- def haml_to_erb
54
- asking "Are you sure want to convert all your views from HAML to ERB ? [yes]" do
55
- # => Cycles through the views folder and searches for haml files
38
+ prepare_convert_gems
39
+ ::Bundler.with_clean_env do
40
+ Dir.glob("app/views/**/*.erb").each do |file|
41
+ out_file = file.gsub(/erb$/, "haml")
42
+ unless file_exists? out_file
43
+ puts "Convert ERB: #{file} => HAML: #{out_file}"
44
+ `html2haml #{file} | cat > #{out_file}`
45
+ File.delete(file) if $? == 0
46
+ else
47
+ puts "WARNING: '#{out_file}' already exists!"
48
+ end
49
+ end
50
+ end
56
51
  end
57
52
  rescue Exception => e
58
53
  raise e
59
54
  end
60
55
 
61
56
  def prepare_convert_gems
62
- # install_gem "haml-rails" unless check_installed_gem? "haml-rails"
63
- # install_gem "hpricot" unless check_installed_gem? "hpricot"
64
- # install_gem "ruby_parser" unless check_installed_gem? "ruby_parser"
57
+ gem "haml-rails"
58
+ install_local_gem "hpricot" unless check_local_gem? "hpricot"
59
+ install_local_gem "ruby_parser" unless check_local_gem? "ruby_parser"
65
60
  rescue Exception => e
66
61
  raise e
67
62
  end
68
63
 
69
- def convert_views(in_type,out_type)
70
- # Dir["app/views/**/*.#{in_type}"].each do |file_name|
71
- # puts "Convert #{first_type.capitalize}: #{file_name}"
72
- # out_file_name = file_name.gsub(/#{first_type}$/, second_type)
73
- # unless file_exists? out_file_name
74
- # erb_string = File.open(file_name).read
75
- # haml_string = Haml::HTML.new(erb_string, :erb => true).render
76
- # f = File.new(haml_file_name, "w")
77
- # f.write(haml_string)
78
- # File.delete(file_name)
79
- # end
80
- # end
81
- rescue Exception => e
82
- raise e
83
- end
84
64
 
85
65
  end
86
66
  end
@@ -16,13 +16,6 @@ module Fetty
16
16
 
17
17
  protected
18
18
 
19
- def add_gem(&block)
20
- yield
21
- refresh_bundle
22
- rescue Exception => e
23
- raise e
24
- end
25
-
26
19
  def root_path(path)
27
20
  File.expand_path(File.join(File.dirname(__FILE__), 'fetty', path))
28
21
  end
@@ -193,3 +186,7 @@ protected
193
186
  end
194
187
  end
195
188
 
189
+ # => set callback on when calling +gem+
190
+ set_trace_func proc { |event, file, line, id, binding, classname|
191
+ ::Bundler.with_clean_env { `bundle` } if classname == Rails::Generators::Actions && id == :gem && event == 'return'
192
+ }
@@ -18,8 +18,10 @@ module Fetty
18
18
  if arg.include?(':file') || arg.include?(':image') || arg.include?(':editor')
19
19
  self.special_types[arg.split(':').first] = arg.split(':').last.to_sym
20
20
  if arg.include?(':editor')
21
+ raise "Missing gems: ckeditor" unless check_required_gems? "ckeditor"
21
22
  self.model_attributes << Rails::Generators::GeneratedAttribute.new(arg.split(':').first, "text")
22
23
  else
24
+ raise "Missing gems: carrierwave" unless check_required_gems? "carrierwave"
23
25
  self.model_attributes << Rails::Generators::GeneratedAttribute.new(arg.split(':').first, "string")
24
26
  end
25
27
  else
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fetty-generators
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-13 00:00:00.000000000Z
12
+ date: 2011-08-19 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: This generators provide you to easily setup your Rails 3 application,
15
15
  create authentication, messages, admin style scaffolding and many more