codersdojo 1.0.1 → 1.0.2
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.
- data/app/codersdojo.rb +28 -17
- data/app/scaffolder.rb +12 -5
- data/app/shell_wrapper.rb +8 -0
- data/bin/codersdojo +0 -4
- data/spec/scaffolder_spec.rb +10 -3
- metadata +13 -13
- /data/templates/any/{run-endless.sh → run-endless.%sh%} +0 -0
- /data/templates/any/{run-once.sh → run-once.%sh%} +0 -0
- /data/templates/clojure.is-test/{run-endless.sh → run-endless.%sh%} +0 -0
- /data/templates/clojure.is-test/{run-once.sh → run-once.%sh%} +0 -0
- /data/templates/java.junit/{run-endless.sh → run-endless.%sh%} +0 -0
- /data/templates/java.junit/{run-once.sh → run-once.%sh%} +0 -0
- /data/templates/python.pyunit/{run-endless.sh → run-endless.%sh%} +0 -0
- /data/templates/python.pyunit/{run-once.sh → run-once.%sh%} +0 -0
- /data/templates/ruby.test-unit/{%kata_file%.rb → mykata.rb} +0 -0
data/app/codersdojo.rb
CHANGED
@@ -5,24 +5,35 @@ require 'controller'
|
|
5
5
|
require 'argument_parser'
|
6
6
|
require 'scaffolder'
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
class CodersDojo
|
9
|
+
|
10
|
+
def initialize params
|
11
|
+
@params = params
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
if called_from_spec? then return end
|
16
|
+
hostname = "http://www.codersdojo.com"
|
17
|
+
# hostname = "http://localhost:3000"
|
11
18
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
19
|
+
shell = ShellWrapper.new
|
20
|
+
scaffolder = Scaffolder.new shell
|
21
|
+
view = ConsoleView.new scaffolder
|
22
|
+
controller = Controller.new shell, view, scaffolder, hostname
|
16
23
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
begin
|
25
|
+
arg_parser = ArgumentParser.new controller
|
26
|
+
command = arg_parser.parse @params
|
27
|
+
rescue ShellArgumentException
|
28
|
+
controller.help
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def called_from_spec?
|
33
|
+
@params and @params[0] == "spec"
|
27
34
|
end
|
35
|
+
|
28
36
|
end
|
37
|
+
|
38
|
+
# entry from shell
|
39
|
+
CodersDojo.new(ARGV).run
|
data/app/scaffolder.rb
CHANGED
@@ -37,18 +37,25 @@ class Scaffolder
|
|
37
37
|
to_copy.each do |item|
|
38
38
|
file_path = "#{dir_path}/#{item}"
|
39
39
|
@shell.cp_r file_path, "."
|
40
|
-
|
40
|
+
transform_file_content item
|
41
|
+
transform_file_name item
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
44
|
-
def
|
45
|
-
if
|
45
|
+
def transform_file_content filename
|
46
|
+
if @shell.file?(filename)
|
46
47
|
content = @shell.read_file filename
|
47
48
|
content = @template_machine.render content
|
48
|
-
|
49
|
-
@shell.write_file new_filename, content
|
49
|
+
@shell.write_file filename, content
|
50
50
|
end
|
51
51
|
end
|
52
|
+
|
53
|
+
def transform_file_name filename
|
54
|
+
new_filename = @template_machine.render filename
|
55
|
+
if new_filename != filename
|
56
|
+
@shell.rename filename, new_filename
|
57
|
+
end
|
58
|
+
end
|
52
59
|
|
53
60
|
def template_path
|
54
61
|
file_path_elements = @shell.current_file.split '/'
|
data/app/shell_wrapper.rb
CHANGED
@@ -20,6 +20,10 @@ class ShellWrapper
|
|
20
20
|
FileUtils.mkdir_p dirs
|
21
21
|
end
|
22
22
|
|
23
|
+
def rename old_filename, new_filename
|
24
|
+
File.rename old_filename, new_filename
|
25
|
+
end
|
26
|
+
|
23
27
|
def current_file
|
24
28
|
__FILE__
|
25
29
|
end
|
@@ -64,6 +68,10 @@ class ShellWrapper
|
|
64
68
|
end
|
65
69
|
end
|
66
70
|
|
71
|
+
def file? filename
|
72
|
+
File.file? filename
|
73
|
+
end
|
74
|
+
|
67
75
|
def remove_command_name
|
68
76
|
windows? ? 'del' : 'rm'
|
69
77
|
end
|
data/bin/codersdojo
CHANGED
@@ -1,8 +1,4 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
codersdojo_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'app'))
|
3
|
-
infrastructure_dir = "#{codersdojo_dir}/infrastructure"
|
4
|
-
models_dir = "#{codersdojo_dir}/models"
|
5
3
|
$LOAD_PATH.unshift(codersdojo_dir) unless $LOAD_PATH.include?(codersdojo_dir)
|
6
|
-
$LOAD_PATH.unshift(infrastructure_dir) unless $LOAD_PATH.include?(infrastructure_dir)
|
7
|
-
$LOAD_PATH.unshift(models_dir) unless $LOAD_PATH.include?(models_dir)
|
8
4
|
require 'codersdojo'
|
data/spec/scaffolder_spec.rb
CHANGED
@@ -23,7 +23,9 @@ describe Scaffolder do
|
|
23
23
|
it "should scaffold the files and directories for a given template" do
|
24
24
|
@shell_mock.should_receive(:real_dir_entries).with("aDir/templates/a.template").and_return ["a", "b"]
|
25
25
|
@shell_mock.should_receive(:cp_r).with "aDir/templates/a.template/a", "."
|
26
|
+
@shell_mock.should_receive(:file?).with("a").and_return false
|
26
27
|
@shell_mock.should_receive(:cp_r).with "aDir/templates/a.template/b", "."
|
28
|
+
@shell_mock.should_receive(:file?).with("b").and_return false
|
27
29
|
@scaffolder.scaffold "a.template", 'myKata'
|
28
30
|
end
|
29
31
|
|
@@ -31,20 +33,25 @@ describe Scaffolder do
|
|
31
33
|
@shell_mock.should_receive(:real_dir_entries).with("aDir/templates/unknown.template").and_throw Exception
|
32
34
|
@shell_mock.should_receive(:real_dir_entries).with("aDir/templates/any").and_return ["a"]
|
33
35
|
@shell_mock.should_receive(:cp_r).with "aDir/templates/any/a", "."
|
36
|
+
@shell_mock.should_receive(:file?).with("a").and_return false
|
34
37
|
@scaffolder.scaffold "unknown.template", 'myKata'
|
35
38
|
end
|
36
39
|
|
37
40
|
it "should replace placeholder in template file README and shell scripts" do
|
38
41
|
@shell_mock.should_receive(:real_dir_entries).with("aDir/templates/a.template").
|
39
|
-
and_return ["a", "README", "run-once.sh", "run-endless.sh"]
|
42
|
+
and_return ["a", "README", "run-once.sh", "run-endless.sh"]
|
40
43
|
@shell_mock.should_receive(:cp_r).with "aDir/templates/a.template/a", "."
|
44
|
+
@shell_mock.should_receive(:file?).with("a").and_return false
|
41
45
|
@shell_mock.should_receive(:cp_r).with "aDir/templates/a.template/README", "."
|
42
|
-
@shell_mock.should_receive(:
|
43
|
-
@shell_mock.should_receive(:cp_r).with "aDir/templates/a.template/run-endless.sh", "."
|
46
|
+
@shell_mock.should_receive(:file?).with("README").and_return true
|
44
47
|
@shell_mock.should_receive(:read_file).with("README").and_return '%rm% %kata_file%\nb.%sh%\nc%:%d'
|
45
48
|
@shell_mock.should_receive(:write_file).with "README", 'del myKata\nb.cmd\nc;d'
|
49
|
+
@shell_mock.should_receive(:cp_r).with "aDir/templates/a.template/run-once.sh", "."
|
50
|
+
@shell_mock.should_receive(:file?).with("run-once.sh").and_return true
|
46
51
|
@shell_mock.should_receive(:read_file).with("run-once.sh").and_return "%rm% a\nb.%sh%\nc%:%d"
|
47
52
|
@shell_mock.should_receive(:write_file).with "run-once.sh", "del a\nb.cmd\nc;d"
|
53
|
+
@shell_mock.should_receive(:cp_r).with "aDir/templates/a.template/run-endless.sh", "."
|
54
|
+
@shell_mock.should_receive(:file?).with("run-endless.sh").and_return true
|
48
55
|
@shell_mock.should_receive(:read_file).with("run-endless.sh").and_return "%rm% a\nb.%sh%\nc%:%d"
|
49
56
|
@shell_mock.should_receive(:write_file).with "run-endless.sh", "del a\nb.cmd\nc;d"
|
50
57
|
@scaffolder.scaffold "a.template", 'myKata'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codersdojo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 2
|
10
|
+
version: 1.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- CodersDojo-Team
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-12-
|
18
|
+
date: 2010-12-29 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -58,24 +58,24 @@ files:
|
|
58
58
|
- app/uploader.rb
|
59
59
|
- app/xml_element_extractor.rb
|
60
60
|
- templates/any/README
|
61
|
-
- templates/any/run-endless
|
62
|
-
- templates/any/run-once
|
61
|
+
- templates/any/run-endless.%sh%
|
62
|
+
- templates/any/run-once.%sh%
|
63
63
|
- templates/clojure.is-test/%kata_file%.clj
|
64
64
|
- templates/clojure.is-test/lib/place_your_libs_here
|
65
65
|
- templates/clojure.is-test/README
|
66
|
-
- templates/clojure.is-test/run-endless
|
67
|
-
- templates/clojure.is-test/run-once
|
66
|
+
- templates/clojure.is-test/run-endless.%sh%
|
67
|
+
- templates/clojure.is-test/run-once.%sh%
|
68
68
|
- templates/java.junit/%Kata_file%Test.java
|
69
69
|
- templates/java.junit/bin/place_your_class_files_here
|
70
70
|
- templates/java.junit/lib/place_your_libs_here
|
71
71
|
- templates/java.junit/README
|
72
|
-
- templates/java.junit/run-endless
|
73
|
-
- templates/java.junit/run-once
|
72
|
+
- templates/java.junit/run-endless.%sh%
|
73
|
+
- templates/java.junit/run-once.%sh%
|
74
74
|
- templates/python.pyunit/%kata_file%.py
|
75
75
|
- templates/python.pyunit/README
|
76
|
-
- templates/python.pyunit/run-endless
|
77
|
-
- templates/python.pyunit/run-once
|
78
|
-
- templates/ruby.test-unit
|
76
|
+
- templates/python.pyunit/run-endless.%sh%
|
77
|
+
- templates/python.pyunit/run-once.%sh%
|
78
|
+
- templates/ruby.test-unit/mykata.rb
|
79
79
|
- templates/ruby.test-unit/README
|
80
80
|
- templates/ruby.test-unit/run-endless.sh
|
81
81
|
- templates/ruby.test-unit/run-once.sh
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|