pineapples 0.3.34 → 0.3.345
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/pineapples +13 -13
- data/lib/pineapples.rb +3 -1
- data/lib/pineapples/actions.rb +6 -0
- data/lib/pineapples/actions/base/target.rb +41 -91
- data/lib/pineapples/actions/bundle.rb +16 -0
- data/lib/pineapples/actions/chmod.rb +3 -2
- data/lib/pineapples/actions/copy_file.rb +1 -1
- data/lib/pineapples/actions/empty_directory.rb +1 -1
- data/lib/pineapples/actions/gsub_file.rb +5 -3
- data/lib/pineapples/actions/inside.rb +5 -1
- data/lib/pineapples/actions/rails/erb_converters.rb +11 -4
- data/lib/pineapples/actions/rails/new_hash_syntax_converter.rb +36 -0
- data/lib/pineapples/actions/rails/rails.rb +1 -0
- data/lib/pineapples/actions/remove_file.rb +28 -28
- data/lib/pineapples/actions/shell.rb +43 -9
- data/lib/pineapples/app_generator.rb +154 -38
- data/lib/pineapples/helpers.rb +31 -0
- data/lib/pineapples/parser.rb +42 -37
- data/lib/pineapples/setting.rb +155 -155
- data/lib/pineapples/settings.rb +31 -31
- data/lib/pineapples/templates/.example.env.tt +15 -0
- data/lib/pineapples/templates/.gitignore +3 -0
- data/lib/pineapples/templates/.simplecov.tt +11 -0
- data/lib/pineapples/templates/Gemfile.tt +23 -5
- data/lib/pineapples/templates/Procfile +1 -1
- data/lib/pineapples/templates/Procfile.dev.tt +2 -0
- data/lib/pineapples/templates/app/assets/javascripts/libs.js +4 -2
- data/lib/pineapples/templates/app/assets/stylesheets/application.scss +4 -1
- data/lib/pineapples/templates/app/controllers/application_controller.rb.tt +0 -2
- data/lib/pineapples/templates/app/controllers/auth!=devise!/confirmations_controller.rb +11 -0
- data/lib/pineapples/templates/app/controllers/auth!=devise!/passwords_controller.rb.tt +12 -0
- data/lib/pineapples/templates/app/controllers/auth!=devise!/registrations_controller.rb.tt +25 -0
- data/lib/pineapples/templates/app/controllers/auth!=devise!/sessions_controller.rb.tt +59 -0
- data/lib/pineapples/templates/app/models/user!=needs_user_model!.rb.tt +7 -4
- data/lib/pineapples/templates/app/policies!=pundit!/application_policy.rb +49 -0
- data/lib/pineapples/templates/app/presenters/base_presenter.rb.tt +24 -0
- data/lib/pineapples/templates/app/responders/application_responder.rb +9 -0
- data/lib/pineapples/templates/app/services/service.rb +7 -0
- data/lib/pineapples/templates/app/views/common/_footer.html.erb +3 -3
- data/lib/pineapples/templates/app/views/common/_header.html.erb +5 -5
- data/lib/pineapples/templates/app/views/layouts/application.html.erb.tt +0 -1
- data/lib/pineapples/templates/app/views/pages/home.html.erb +0 -1
- data/lib/pineapples/templates/bin/nginx +4 -0
- data/lib/pineapples/templates/bin/rails +1 -0
- data/lib/pineapples/templates/bin/rspec +19 -0
- data/lib/pineapples/templates/bin/setup +111 -21
- data/lib/pineapples/templates/config.ru.tt +3 -0
- data/lib/pineapples/templates/config/application.rb.tt +3 -3
- data/lib/pineapples/templates/config/boot.rb +5 -5
- data/lib/pineapples/templates/config/database.yml.tt +1 -1
- data/lib/pineapples/templates/config/environments/{development.rb → development.rb.tt} +6 -1
- data/lib/pineapples/templates/config/environments/production.rb +1 -1
- data/lib/pineapples/templates/config/environments/test.rb +2 -2
- data/lib/pineapples/templates/config/i18n-tasks.yml +2 -0
- data/lib/pineapples/templates/config/initializers/{carrierwave.rb → carrierwave!=carrierwave!.rb} +22 -22
- data/lib/pineapples/templates/config/initializers/devise!=devise!.rb.tt +262 -0
- data/lib/pineapples/templates/config/initializers/kaminari.rb +10 -0
- data/lib/pineapples/templates/config/initializers/seed_migrations.rb +15 -0
- data/lib/pineapples/templates/config/initializers/simple_form.rb +165 -0
- data/lib/pineapples/templates/config/locales/devise.en.yml +60 -0
- data/lib/pineapples/templates/config/locales/{en.yml → en.yml.tt} +2 -0
- data/lib/pineapples/templates/config/locales/kaminari.en.yml +17 -0
- data/lib/pineapples/templates/config/locales/simple_form.en.yml +31 -0
- data/lib/pineapples/templates/config/nginx.conf.tt +147 -0
- data/lib/pineapples/templates/config/puma/development.rb.tt +27 -0
- data/lib/pineapples/templates/config/{puma.rb → puma/production.rb} +5 -5
- data/lib/pineapples/templates/config/routes.rb.tt +4 -0
- data/lib/pineapples/templates/config/spring.rb +4 -0
- data/lib/pineapples/templates/lib/devise!=devise!/{ajax_failure.rb → ajax_failure!=ajax_login!.rb} +0 -0
- data/lib/pineapples/templates/lib/logging/custom_rack_logger.rb +7 -9
- data/lib/pineapples/templates/lib/logging/custom_request_logger.rb +46 -48
- data/lib/pineapples/templates/lib/tasks/admin!=user_role_field!.rake +18 -19
- data/lib/pineapples/templates/lib/templates/{erb → erb!=erb!}/scaffold/_form.html.erb +0 -0
- data/lib/pineapples/templates/lib/templates/haml!=haml!/scaffold/_form.html.haml +9 -0
- data/lib/pineapples/templates/lib/templates/slim!=slim!/scaffold/_form.html.slim +9 -0
- data/lib/pineapples/templates/spec/i18n_spec.rb +17 -0
- data/lib/pineapples/templates/spec/rails_helper.rb +30 -0
- data/lib/pineapples/templates/spec/spec_helper.rb +44 -0
- data/lib/pineapples/templates/spec/support/capybara.rb +4 -0
- data/lib/pineapples/templates/spec/support/database_cleaner.rb +27 -0
- data/lib/pineapples/templates/spec/support/email_matchers.rb +17 -0
- data/lib/pineapples/templates/spec/support/factory_girl.rb +14 -0
- data/lib/pineapples/templates/spec/support/job_helpers.rb +8 -0
- data/lib/pineapples/templates/spec/support/matchers.rb +10 -0
- data/lib/pineapples/templates/spec/support/rake_tasks.rb +8 -0
- data/lib/pineapples/templates/spec/support/shoulda_matchers.rb +24 -0
- data/lib/pineapples/version.rb +2 -2
- data/pineapples.gemspec +1 -3
- metadata +46 -12
- data/lib/pineapples/app_builder.rb +0 -70
- data/lib/pineapples/build_tasks/root_files.rb +0 -23
- data/lib/pineapples/templates/app/controllers/auth/confirmations_controller.rb +0 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6f0f84c10a46a615eba4dfc22bf19092b18c9e2e
|
|
4
|
+
data.tar.gz: f5f427c5265408244a73c6369dc2a073b3dc3ade
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2b0c292b8573424558413899a0c3a70350eb9d3a35906c348d149b67690e85d2d8b376efecfc6db65219e9f432d8f864cc37e862f81fcab2c5fa71fe9ea797d2
|
|
7
|
+
data.tar.gz: 9926d77f2319243f47332624b82a8fda99595dc91f884bfe8f626903cf611f6704a5ac26ade0090ed84b6e0445aab8a156e298eebbf6f0f62fe608a6d0ca59b7
|
data/bin/pineapples
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
require 'pathname'
|
|
3
|
-
|
|
4
|
-
source_path = (Pathname.new(__FILE__).dirname + '../lib').expand_path
|
|
5
|
-
$LOAD_PATH << source_path
|
|
6
|
-
|
|
7
|
-
require 'pineapples'
|
|
8
|
-
|
|
9
|
-
$terminal.indent_size = 2
|
|
10
|
-
|
|
11
|
-
options = Pineapples::Parser.parse(ARGV)
|
|
12
|
-
generator = Pineapples::AppGenerator.new(options)
|
|
13
|
-
generator.start!
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require 'pathname'
|
|
3
|
+
|
|
4
|
+
source_path = (Pathname.new(__FILE__).dirname + '../lib').expand_path
|
|
5
|
+
$LOAD_PATH << source_path
|
|
6
|
+
|
|
7
|
+
require 'pineapples'
|
|
8
|
+
|
|
9
|
+
$terminal.indent_size = 2
|
|
10
|
+
|
|
11
|
+
options = Pineapples::Parser.parse(ARGV)
|
|
12
|
+
generator = Pineapples::AppGenerator.new(options)
|
|
13
|
+
generator.start!
|
data/lib/pineapples.rb
CHANGED
|
@@ -5,12 +5,14 @@ require 'active_support/core_ext/object/blank'
|
|
|
5
5
|
require 'active_support/core_ext/string/inflections'
|
|
6
6
|
|
|
7
7
|
require 'English'
|
|
8
|
-
#require 'erb'
|
|
9
8
|
require 'fileutils'
|
|
10
9
|
require 'ostruct'
|
|
10
|
+
require 'open3'
|
|
11
11
|
require 'optparse'
|
|
12
12
|
require 'pathname'
|
|
13
|
+
require 'pty'
|
|
13
14
|
require 'securerandom'
|
|
15
|
+
require 'shellwords'
|
|
14
16
|
|
|
15
17
|
require 'pineapples/version'
|
|
16
18
|
require 'pineapples/error'
|
data/lib/pineapples/actions.rb
CHANGED
|
@@ -4,6 +4,7 @@ require 'uri'
|
|
|
4
4
|
require 'pineapples/actions/base/action'
|
|
5
5
|
require 'pineapples/actions/base/target'
|
|
6
6
|
require 'pineapples/actions/apply'
|
|
7
|
+
require 'pineapples/actions/bundle'
|
|
7
8
|
require 'pineapples/actions/chmod'
|
|
8
9
|
require 'pineapples/actions/copy_file'
|
|
9
10
|
require 'pineapples/actions/create_file'
|
|
@@ -114,6 +115,11 @@ module Pineapples
|
|
|
114
115
|
say(output)
|
|
115
116
|
end
|
|
116
117
|
|
|
118
|
+
def say_title(title)
|
|
119
|
+
puts
|
|
120
|
+
puts "== #{title} ==".light_yellow
|
|
121
|
+
end
|
|
122
|
+
|
|
117
123
|
def indent(verbose = true, level_increment = 1)
|
|
118
124
|
$terminal.indent_level += level_increment if verbose
|
|
119
125
|
yield
|
|
@@ -1,134 +1,84 @@
|
|
|
1
1
|
module Pineapples
|
|
2
2
|
module Actions
|
|
3
3
|
class Target
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
PASS_REGEX = /!=(.*?)!/
|
|
5
|
+
GUARD_REGEX = /!(.*?)!/
|
|
6
|
+
FILENAME_REGEX = /%(.*?)%/
|
|
7
7
|
|
|
8
8
|
attr_reader :given,
|
|
9
9
|
:fullpath,
|
|
10
10
|
:relative,
|
|
11
|
-
:
|
|
11
|
+
:generator
|
|
12
12
|
|
|
13
|
-
def initialize(target,
|
|
13
|
+
def initialize(target, generator)
|
|
14
14
|
raise Error, 'Target should not be falsy' if !target
|
|
15
15
|
|
|
16
|
-
@
|
|
16
|
+
@generator = generator
|
|
17
17
|
@given = target.to_s
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
evaluate_guard_methods!
|
|
21
|
-
evaluate_filename_method!
|
|
19
|
+
match!
|
|
22
20
|
|
|
23
21
|
@fullpath = File.expand_path(@given, generator.current_app_dir)
|
|
24
22
|
@relative = generator.relative_to_current_app_dir(@fullpath)
|
|
25
23
|
end
|
|
26
24
|
|
|
27
|
-
def generator
|
|
28
|
-
action.generator
|
|
29
|
-
end
|
|
30
|
-
|
|
31
25
|
def skip?
|
|
32
|
-
@skip = false if @skip.nil?
|
|
33
26
|
@skip
|
|
34
27
|
end
|
|
35
28
|
|
|
36
29
|
private
|
|
37
30
|
|
|
38
|
-
def
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def evaluate_guard_methods!
|
|
48
|
-
if guard_match
|
|
49
|
-
raise Error, methods_missing_error_message(guard_methods) if !generator_guard_method
|
|
50
|
-
|
|
51
|
-
@skip = generator.send(generator_guard_method)
|
|
52
|
-
@given.gsub!(guard_match[0], '')
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def evaluate_filename_method!
|
|
57
|
-
if eval_match
|
|
58
|
-
raise Error, methods_missing_error_message(filename_method) if !generator_filename_method
|
|
59
|
-
|
|
60
|
-
filename = generator.send(filename_method)
|
|
61
|
-
@given.gsub!(eval_match[0], filename)
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def pass_match
|
|
66
|
-
PASS_MATCH.match(@given)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def guard_match
|
|
70
|
-
GUARD_MATCH.match(@given)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def eval_match
|
|
74
|
-
EVAL_MATCH.match(@given)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def generator_pass_method
|
|
78
|
-
if @pass_method.nil?
|
|
79
|
-
pass_methods.each do |method|
|
|
80
|
-
if generator.respond_to?(method, true)
|
|
81
|
-
@pass_method = method
|
|
82
|
-
break
|
|
31
|
+
def match!
|
|
32
|
+
loop do
|
|
33
|
+
matched = false
|
|
34
|
+
[:pass, :guard, :filename].each do |type|
|
|
35
|
+
if match(type)
|
|
36
|
+
send(:"evaluate_#{type}_method!")
|
|
37
|
+
matched = true and break
|
|
83
38
|
end
|
|
84
39
|
end
|
|
40
|
+
break if !matched || @skip
|
|
85
41
|
end
|
|
86
|
-
@pass_method = false if @pass_method.nil?
|
|
87
|
-
@pass_method
|
|
88
42
|
end
|
|
89
43
|
|
|
90
|
-
def
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
@guard_method = method
|
|
95
|
-
break
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
@guard_method = false if @guard_method.nil?
|
|
100
|
-
@guard_method
|
|
44
|
+
def evaluate_pass_method!
|
|
45
|
+
method = find_generator_method!(methods_to_find(:pass))
|
|
46
|
+
@skip = !generator.send(method)
|
|
47
|
+
@given.sub!(match(:pass)[0], '')
|
|
101
48
|
end
|
|
102
49
|
|
|
103
|
-
def
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
50
|
+
def evaluate_guard_method!
|
|
51
|
+
method = find_generator_method!(methods_to_find(:guard))
|
|
52
|
+
@skip = generator.send(method)
|
|
53
|
+
@given.sub!(match(:guard)[0], '')
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def evaluate_filename_method!
|
|
57
|
+
method = find_generator_method!(methods_to_find(:filename))
|
|
58
|
+
filename = generator.send(method)
|
|
59
|
+
@given.sub!(match(:filename)[0], filename)
|
|
108
60
|
end
|
|
109
61
|
|
|
110
|
-
def
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
[guard_method, predicate_method]
|
|
62
|
+
def match(type)
|
|
63
|
+
regexp = self.class.const_get(type.to_s.upcase + '_REGEX')
|
|
64
|
+
regexp.match(@given)
|
|
114
65
|
end
|
|
115
66
|
|
|
116
|
-
def
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
[pass_method, predicate_method]
|
|
67
|
+
def methods_to_find(type)
|
|
68
|
+
method = match(type)[1].strip
|
|
69
|
+
type == :filename ? method : [method, method + '?']
|
|
120
70
|
end
|
|
121
71
|
|
|
122
|
-
def
|
|
123
|
-
|
|
72
|
+
def find_generator_method!(methods)
|
|
73
|
+
Array(methods).each { |method| return method if generator.respond_to?(method, true) }
|
|
74
|
+
raise Error, methods_missing_error_message(methods)
|
|
124
75
|
end
|
|
125
76
|
|
|
126
77
|
def methods_missing_error_message(methods)
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
methods_message = plural ? 'methods' : 'method'
|
|
78
|
+
methods = Array(methods)
|
|
79
|
+
methods_message = methods.length > 1 ? 'methods' : 'method'
|
|
130
80
|
|
|
131
|
-
"No instance #{methods_message} #{methods} for AppGenerator, can't evaluate filepath #{given}"
|
|
81
|
+
"No instance #{methods_message} #{methods.join(', ')} for AppGenerator, can't evaluate filepath #{given}"
|
|
132
82
|
end
|
|
133
83
|
end
|
|
134
84
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Pineapples
|
|
2
|
+
module Actions
|
|
3
|
+
def bundle(command, options = {})
|
|
4
|
+
command = "#{command.first.first} #{command.first.last}" if command.is_a?(Hash)
|
|
5
|
+
say_status :bundle, "#{command}"
|
|
6
|
+
|
|
7
|
+
_bundle_command = Gem.bin_path('bundler', 'bundle')
|
|
8
|
+
|
|
9
|
+
require 'bundler'
|
|
10
|
+
Bundler.with_clean_env do
|
|
11
|
+
output = `"#{Gem.ruby}" "#{_bundle_command}" #{command} #{subcommands}`
|
|
12
|
+
print output if !options[:quiet]
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -18,11 +18,12 @@ module Pineapples
|
|
|
18
18
|
execute = !options.fetch(:pretend, pretend?)
|
|
19
19
|
color = options.fetch(:color, DEFAULT_COLOR)
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
full_path = File.join(app_root, path)
|
|
22
|
+
relative_path = relative_to_app_root(full_path)
|
|
22
23
|
|
|
23
24
|
say_status(:chmod, relative_path, color, verbose)
|
|
24
25
|
|
|
25
|
-
FileUtils.chmod_R(mode,
|
|
26
|
+
FileUtils.chmod_R(mode, full_path) if execute
|
|
26
27
|
end
|
|
27
28
|
end
|
|
28
29
|
end
|
|
@@ -23,13 +23,15 @@ module Pineapples
|
|
|
23
23
|
verbose = options.fetch(:verbose, verbose?)
|
|
24
24
|
execute = options.fetch(:pretend, execute?)
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
fullpath = File.expand_path(path, app_root)
|
|
27
|
+
raise Error, "File #{path} doesn't exist!" if !File.exist?(fullpath)
|
|
28
|
+
|
|
27
29
|
say_status :gsub, relative_to_app_root(path), :light_yellow, verbose
|
|
28
30
|
|
|
29
31
|
if execute
|
|
30
|
-
content = File.binread(
|
|
32
|
+
content = File.binread(fullpath)
|
|
31
33
|
content.gsub!(flag, *args, &block)
|
|
32
|
-
File.open(
|
|
34
|
+
File.open(fullpath, 'wb') { |file| file.write(content) }
|
|
33
35
|
end
|
|
34
36
|
end
|
|
35
37
|
end
|
|
@@ -50,9 +50,13 @@ module Pineapples
|
|
|
50
50
|
inside(:root, options) { yield }
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
+
def in_app_root(&block)
|
|
54
|
+
Dir.chdir(app_root, &block)
|
|
55
|
+
end
|
|
56
|
+
|
|
53
57
|
private
|
|
54
58
|
|
|
55
|
-
# helper method to abstract directory stack management in the
|
|
59
|
+
# helper method to abstract directory stack management in the #inside action
|
|
56
60
|
def with_directory(dir)
|
|
57
61
|
not_in_root = (dir != :root)
|
|
58
62
|
|
|
@@ -5,15 +5,20 @@ module Pineapples
|
|
|
5
5
|
recursive = options.fetch(:recursive, true)
|
|
6
6
|
verbose = options.fetch(:verbose, verbose?)
|
|
7
7
|
execute = !options.fetch(:pretend, pretend?)
|
|
8
|
+
preserve = options.fetch(:keep_old_files, false)
|
|
8
9
|
|
|
9
10
|
description = 'Convert ERB views to HAML'
|
|
10
|
-
|
|
11
|
+
say_status(:erb2haml, description, verbose)
|
|
11
12
|
|
|
12
13
|
if execute
|
|
13
14
|
target_path = File.expand_path(target, app_root)
|
|
14
|
-
target_path = File.join(target_path,
|
|
15
|
+
target_path = File.join(target_path, '**') if recursive
|
|
15
16
|
shell "find #{target_path} -name \\*.erb -print | sed 'p;s/.erb$/.haml/' | xargs -n2 html2haml",
|
|
16
17
|
verbose: false
|
|
18
|
+
if !preserve
|
|
19
|
+
erb_pattern = File.join(target_path, '*.erb')
|
|
20
|
+
Dir.glob(erb_pattern).each { |file| ::FileUtils.rm_f(file) }
|
|
21
|
+
end
|
|
17
22
|
end
|
|
18
23
|
end
|
|
19
24
|
|
|
@@ -21,17 +26,19 @@ module Pineapples
|
|
|
21
26
|
recursive = options.fetch(:recursive, true)
|
|
22
27
|
verbose = options.fetch(:verbose, verbose?)
|
|
23
28
|
execute = !options.fetch(:pretend, pretend?)
|
|
29
|
+
preserve = options.falsetch(:keep_old_files, false)
|
|
24
30
|
|
|
25
31
|
description = 'Convert ERB views to SLIM'
|
|
26
|
-
|
|
32
|
+
say_status(:erb2slim, description, verbose)
|
|
27
33
|
|
|
28
34
|
if execute
|
|
29
35
|
erb2haml(target, options)
|
|
30
36
|
target_path = File.expand_path(target, app_root)
|
|
31
37
|
target_path = File.join(target_path, '**') if recursive
|
|
32
|
-
shell "haml2slim #{target_path} --delete --trace", verbose: false
|
|
38
|
+
shell "haml2slim #{target_path} #{preserve ? '' : '--delete'} --trace", verbose: false
|
|
33
39
|
end
|
|
34
40
|
end
|
|
41
|
+
|
|
35
42
|
end
|
|
36
43
|
end
|
|
37
44
|
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module Pineapples
|
|
2
|
+
module Actions
|
|
3
|
+
FILE_WITH_RUBY_CODE = '.rb|.erb|.haml|.slim|.rake'
|
|
4
|
+
def convert_directory_to_new_hash_syntax(target, options = {})
|
|
5
|
+
recursive = options.delete(:recursive) || true
|
|
6
|
+
|
|
7
|
+
target_fullpath = File.expand_path(target, app_root)
|
|
8
|
+
target_fullpath = File.join(target_fullpath, '**') if recursive
|
|
9
|
+
|
|
10
|
+
excluded_files = Array(options[:exclude])
|
|
11
|
+
exclude_pattern = options[:exclude_pattern]
|
|
12
|
+
|
|
13
|
+
files = Dir.glob(target_fullpath, File::FNM_DOTMATCH)
|
|
14
|
+
files.sort.each do |file|
|
|
15
|
+
next if File.directory?(file)
|
|
16
|
+
next if exclude_pattern && file.match(exclude_pattern)
|
|
17
|
+
next if excluded_files.any? do |excluded_file|
|
|
18
|
+
File.basename(excluded_file) == File.basename(file_source)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
case file
|
|
22
|
+
when /#{FILE_WITH_RUBY_CODE}$/
|
|
23
|
+
convert_file_to_new_hash_syntax(file)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
# Converts file to new Ruby hash syntax, cause that is what I prefer
|
|
29
|
+
# Existing solutions on web usually use perl and shell, but we have
|
|
30
|
+
# power of Ruby and cool gsub_file action at our disposal!
|
|
31
|
+
def convert_file_to_new_hash_syntax(path)
|
|
32
|
+
regex = /:(\w+)(\s{1})(\s*)=>/
|
|
33
|
+
gsub_file(path, regex, '\1:\3')
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
module Pineapples
|
|
2
|
-
module Actions
|
|
3
|
-
# Removes a file at the given location.
|
|
4
|
-
#
|
|
5
|
-
# ==== Parameters
|
|
6
|
-
# path<String>:: path of the file to be changed
|
|
7
|
-
# options<Hash>:: give :verbose => false to not log the status.
|
|
8
|
-
#
|
|
9
|
-
# ==== Example
|
|
10
|
-
#
|
|
11
|
-
# remove_file 'README'
|
|
12
|
-
# remove_file 'app/controllers/application_controller.rb'
|
|
13
|
-
#
|
|
14
|
-
def remove_file(path, options = {})
|
|
15
|
-
return unless behaviour == :invoke
|
|
16
|
-
path = File.expand_path(path,
|
|
17
|
-
|
|
18
|
-
message = relative_to_app_root(path)
|
|
19
|
-
verbose = options.fetch(:verbose, verbose?)
|
|
20
|
-
color = options.fetch(:color, :light_red)
|
|
21
|
-
execute = options[:pretend] || execute?
|
|
22
|
-
|
|
23
|
-
say_status :remove, message, color, verbose
|
|
24
|
-
::FileUtils.rm_rf(path) if execute && File.exist?(path)
|
|
25
|
-
end
|
|
26
|
-
alias_method :remove_dir, :remove_file
|
|
27
|
-
end
|
|
28
|
-
end
|
|
1
|
+
module Pineapples
|
|
2
|
+
module Actions
|
|
3
|
+
# Removes a file at the given location.
|
|
4
|
+
#
|
|
5
|
+
# ==== Parameters
|
|
6
|
+
# path<String>:: path of the file to be changed
|
|
7
|
+
# options<Hash>:: give :verbose => false to not log the status.
|
|
8
|
+
#
|
|
9
|
+
# ==== Example
|
|
10
|
+
#
|
|
11
|
+
# remove_file 'README'
|
|
12
|
+
# remove_file 'app/controllers/application_controller.rb'
|
|
13
|
+
#
|
|
14
|
+
def remove_file(path, options = {})
|
|
15
|
+
return unless behaviour == :invoke
|
|
16
|
+
path = File.expand_path(path, app_root)
|
|
17
|
+
|
|
18
|
+
message = relative_to_app_root(path)
|
|
19
|
+
verbose = options.fetch(:verbose, verbose?)
|
|
20
|
+
color = options.fetch(:color, :light_red)
|
|
21
|
+
execute = options[:pretend] || execute?
|
|
22
|
+
|
|
23
|
+
say_status :remove, message, color, verbose
|
|
24
|
+
::FileUtils.rm_rf(path) if execute && File.exist?(path)
|
|
25
|
+
end
|
|
26
|
+
alias_method :remove_dir, :remove_file
|
|
27
|
+
end
|
|
28
|
+
end
|