falsework 2.1.1 → 3.0.0

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.
Files changed (72) hide show
  1. data/README.rdoc +19 -59
  2. data/Rakefile +28 -20
  3. data/bin/falsework +266 -73
  4. data/doc/NEWS.rdoc +24 -0
  5. data/doc/README.rdoc +19 -59
  6. data/doc/TODO.org +16 -6
  7. data/doc/template-tutorial.rdoc +49 -12
  8. data/dynamic.yaml +4 -0
  9. data/falsework.gemspec +10 -1
  10. data/lib/falsework/cliconfig.rb +14 -9
  11. data/lib/falsework/cliutils.rb +0 -2
  12. data/lib/falsework/meta.rb +2 -1
  13. data/lib/falsework/mould.rb +121 -192
  14. data/lib/falsework/upgrader.rb +120 -0
  15. data/lib/falsework/utils.rb +23 -0
  16. data/templates/c-glib/#config.yaml +18 -0
  17. data/{lib/falsework/templates → templates}/c-glib/README +0 -0
  18. data/{lib/falsework/templates → templates}/c-glib/doc/#doc.ascii +0 -0
  19. data/{lib/falsework/templates → templates}/c-glib/doc/%%@project%%.1.asciidoc +0 -0
  20. data/{lib/falsework/templates → templates}/c-glib/doc/LICENSE +0 -0
  21. data/{lib/falsework/templates → templates}/c-glib/doc/Makefile +0 -0
  22. data/{lib/falsework/templates → templates}/c-glib/src/#exe.c +0 -0
  23. data/{lib/falsework/templates → templates}/c-glib/src/#exe.h +0 -0
  24. data/{lib/falsework/templates → templates}/c-glib/src/%%@project%%.c +0 -0
  25. data/{lib/falsework/templates → templates}/c-glib/src/%%@project%%.h +0 -0
  26. data/{lib/falsework/templates → templates}/c-glib/src/Makefile +0 -0
  27. data/{lib/falsework/templates → templates}/c-glib/src/untest.c +0 -0
  28. data/{lib/falsework/templates → templates}/c-glib/src/untest.h +0 -0
  29. data/{lib/falsework/templates → templates}/c-glib/src/utils.c +0 -0
  30. data/{lib/falsework/templates → templates}/c-glib/src/utils.h +0 -0
  31. data/{lib/falsework/templates → templates}/c-glib/test/#test.c +0 -0
  32. data/{lib/falsework/templates → templates}/c-glib/test/Makefile +0 -0
  33. data/{lib/falsework/templates → templates}/c-glib/test/Makefile.test.mk +0 -0
  34. data/{lib/falsework/templates → templates}/c-glib/test/mycat.c +0 -0
  35. data/{lib/falsework/templates → templates}/c-glib/test/semis/text/empty.txt +0 -0
  36. data/{lib/falsework/templates → templates}/c-glib/test/test_utils.c +0 -0
  37. data/templates/ruby-cli/#config.yaml +26 -0
  38. data/{lib/falsework/templates → templates}/ruby-cli/%%@project%%.gemspec +0 -0
  39. data/{lib/falsework/templates → templates}/ruby-cli/.gitignore +0 -0
  40. data/{lib/falsework/templates → templates}/ruby-cli/.gitignore.#erb +0 -0
  41. data/{lib/falsework/templates → templates}/ruby-cli/Gemfile +0 -0
  42. data/{lib/falsework/templates → templates}/ruby-cli/README.rdoc +17 -19
  43. data/{lib/falsework/templates → templates}/ruby-cli/Rakefile +0 -0
  44. data/{lib/falsework/templates → templates}/ruby-cli/bin/%%@project%% +3 -3
  45. data/{lib/falsework/templates → templates}/ruby-cli/doc/#doc.rdoc +16 -18
  46. data/{lib/falsework/templates → templates}/ruby-cli/doc/LICENSE +0 -0
  47. data/{lib/falsework/templates → templates}/ruby-cli/doc/NEWS.rdoc +0 -0
  48. data/{lib/falsework/templates → templates}/ruby-cli/doc/README.rdoc +17 -19
  49. data/templates/ruby-cli/etc/%%@project%%.yaml +2 -0
  50. data/{lib/falsework/templates → templates}/ruby-cli/lib/%%@project%%/cliconfig.rb +14 -11
  51. data/{lib/falsework/templates → templates}/ruby-cli/lib/%%@project%%/cliutils.rb +0 -4
  52. data/{lib/falsework/templates → templates}/ruby-cli/lib/%%@project%%/meta.rb +1 -0
  53. data/{lib/falsework/templates → templates}/ruby-cli/test/helper.rb +0 -0
  54. data/{lib/falsework/templates → templates}/ruby-cli/test/helper_cliutils.rb +0 -3
  55. data/{lib/falsework/templates → templates}/ruby-cli/test/test_%%@project%%.rb +0 -0
  56. data/test/example/note/full +10 -0
  57. data/test/example/note/project-too-old +8 -0
  58. data/test/example/note/template-unknown +8 -0
  59. data/test/helper.rb +11 -0
  60. data/test/helper_cliutils.rb +0 -1
  61. data/test/templates/config-01.yaml +1 -1
  62. data/test/{test_exe.rb → test_cli.rb} +52 -29
  63. data/test/test_mould.rb +41 -16
  64. data/test/test_upgrader.rb +96 -0
  65. metadata +76 -50
  66. data/dynamic.ruby-cli +0 -3
  67. data/lib/falsework/templates/c-glib/#config.yaml +0 -18
  68. data/lib/falsework/templates/ruby-cli/#config.yaml +0 -15
  69. data/lib/falsework/templates/ruby-cli/etc/%%@project%%.yaml +0 -2
  70. data/test/rake_erb_templates.rb +0 -60
  71. data/test/templates/config-02.yaml +0 -2
  72. data/test/test_cl.rb +0 -33
data/test/test_mould.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'fakefs/safe'
2
+
1
3
  require_relative 'helper'
2
4
  require_relative '../lib/falsework/mould'
3
5
 
@@ -7,19 +9,27 @@ class TestMould < MiniTest::Unit::TestCase
7
9
  @cmd = cmd('falsework') # get path to the exe & cd to tests directory
8
10
  end
9
11
 
10
- def test_config_parse
11
- refute Mould.config_parse "DOESN'T EXIST", nil, nil
12
+ def test_configParse
13
+ ClearFakeFS do
14
+ FileUtils.mkdir_p 't/ruby-cli'
15
+ Mould.template_dirs.unshift Pathname.new('t')
16
+
17
+ # no template config file
18
+ m = Mould.new 'foo', nil
19
+ refute m.conf[:upgrade]
12
20
 
13
- o = {}
14
- r = Mould.config_parse File.dirname(@cmd) + '/../etc/falsework.yaml', [], o
15
- assert_equal true, r
21
+ # invalid template config file
22
+ File.open('t/ruby-cli/'+Mould::TEMPLATE_CONFIG, 'w+') {|fp|
23
+ fp.puts 'garbage'
24
+ }
25
+ out, err = capture_io { m = Mould.new 'foo', nil }
26
+ assert_match /cannot parse/, err
16
27
 
17
- o = { foo: 1 }
18
- out, err = capture_io do
19
- r = Mould.config_parse File.dirname(@cmd) + '/../etc/falsework.yaml', ['bar'], o
28
+ Mould.template_dirs.shift
20
29
  end
21
- assert_match "missing or nil 'bar' in", err
22
- refute r
30
+
31
+ m = Mould.new 'foo', nil
32
+ assert_equal 'lib/%%@project%%/cliconfig.rb', m.conf['upgrade']['files'].first
23
33
  end
24
34
 
25
35
  def test_name_project
@@ -59,15 +69,15 @@ class TestMould < MiniTest::Unit::TestCase
59
69
  assert_equal 'FoobarPro', Mould.name_camelcase('foobar#pro,')
60
70
  end
61
71
 
62
- def test_get_filename
72
+ def test_resolve_filename
63
73
  f = 'foo'
64
74
  b = 'bar'
65
75
 
66
- assert_equal '', Mould.get_filename(nil, binding)
67
- assert_equal '', Mould.get_filename('', binding)
68
- assert_equal 'f/b', Mould.get_filename('f/b', binding)
69
- assert_equal 'f/bar/q.txt', Mould.get_filename('f/%%b%%/q.txt', binding)
70
- assert_equal 'foo/bar/q.txt', Mould.get_filename('%%f%%/%%b%%/q.txt', binding)
76
+ assert_equal '', Mould.resolve_filename(nil, binding)
77
+ assert_equal '', Mould.resolve_filename('', binding)
78
+ assert_equal 'f/b', Mould.resolve_filename('f/b', binding)
79
+ assert_equal 'f/bar/q.txt', Mould.resolve_filename('f/%%b%%/q.txt', binding)
80
+ assert_equal 'foo/bar/q.txt', Mould.resolve_filename('%%f%%/%%b%%/q.txt', binding)
71
81
  end
72
82
 
73
83
  def test_uuid
@@ -77,4 +87,19 @@ class TestMould < MiniTest::Unit::TestCase
77
87
  refute_match /\d/, t[0]
78
88
  }
79
89
  end
90
+
91
+ def test_listdirs
92
+ assert_equal 2, Mould.template_dirs.size
93
+ out, err = capture_io { Mould.template_dirs_add [Pathname.new("DOESN'T EXISI")] }
94
+ assert_equal 2, Mould.template_dirs.size
95
+
96
+ assert_raises(RuntimeError) { Mould.template_dirs_add([Dir.pwd]) }
97
+ assert_equal 2, Mould.template_dirs.size
98
+
99
+ Mould.template_dirs_add [Pathname.new(Dir.pwd)]
100
+ assert_equal 3, Mould.template_dirs.size
101
+
102
+ assert_equal true, Mould.templates.key?("templates")
103
+ end
104
+
80
105
  end
@@ -0,0 +1,96 @@
1
+ require 'fakefs/safe'
2
+
3
+ require_relative 'helper'
4
+ require_relative '../lib/falsework/upgrader'
5
+
6
+ class TestUpgrader < MiniTest::Unit::TestCase
7
+ def setup
8
+ # this runs every time before test_*
9
+ @cmd = cmd('falsework') # get path to the exe & cd to tests directory
10
+ end
11
+
12
+ # def test_note
13
+ # rm_rf 'templates/foo'
14
+ # r = CliUtils.exec "#{@cmd} new templates/foo"
15
+ # assert_equal 0, r[0]
16
+
17
+ # Dir.chdir('templates/foo') {
18
+
19
+ # }
20
+ # end
21
+
22
+ def test_load_note
23
+ assert Upgrader.noteLoad('example/note/full')
24
+ end
25
+
26
+ def test_upgradable
27
+ e = assert_raises(UpgradeError) { Upgrader.new '/DOES/NOT/EXIST' }
28
+ assert_match /directory .+ is unreadable/, e.message
29
+
30
+ e = assert_raises(UpgradeError) { Upgrader.new 'templates' }
31
+ assert_match /No such file or directory - .+\.#{Meta::NAME}/, e.message
32
+
33
+ e = assert_raises(UpgradeError) { Upgrader.new nil, nil }
34
+ assert_match /directory is unreadable/, e.message
35
+
36
+ e = assert_raises(UpgradeError) { Upgrader.new 'example/note', 'template-unknown' }
37
+ assert_match /unknown template/, e.message
38
+
39
+ u = Upgrader.new 'example/note', 'project-too-old'
40
+ refute u.able?
41
+
42
+ u = Upgrader.new 'example/note', 'full'
43
+ assert u.able?
44
+ end
45
+
46
+ def test_files
47
+ u = Upgrader.new 'example/note', 'full'
48
+ assert_operator u.files.size, :>, 1
49
+ assert_operator u.obsolete.size, :>=, 1
50
+ end
51
+
52
+ def test_upgrade_fail
53
+ u = Upgrader.new 'example/note', 'project-too-old'
54
+ e = assert_raises(UpgradeError) { u.upgrade }
55
+ assert_match /this project cannot be upgraded/, e.message
56
+ end
57
+
58
+ def test_upgrade
59
+ u = Upgrader.new 'example/note', 'full'
60
+ u.batch = true
61
+ temp = {}
62
+ u.files.each {|idx|
63
+ f = u.template_dir + idx
64
+ temp[f] = File.read f
65
+ }
66
+
67
+ ClearFakeFS do
68
+ # copy some template files into fakefs
69
+ temp.each {|key, val|
70
+ FileUtils.mkdir_p File.dirname(key)
71
+ File.open(key, 'w+') {|fp| fp.write val}
72
+ }
73
+
74
+ # make a skeleton
75
+ checksum_old = []
76
+ u.files.each {|idx|
77
+ f = Mould.resolve_filename(idx, u.getProjectBinding)
78
+ FileUtils.mkdir_p File.dirname(f)
79
+ FileUtils.touch f
80
+ checksum_old << Digest::MD5.file(f)
81
+ }
82
+
83
+ u.upgrade true
84
+
85
+ checksum_new = []
86
+ u.files.each {|idx|
87
+ f = Mould.resolve_filename(idx, u.getProjectBinding)
88
+ assert File.readable?(f + '.orig')
89
+ checksum_new << Digest::MD5.file(f)
90
+ }
91
+
92
+ refute_equal checksum_old, checksum_new
93
+ end
94
+ end
95
+
96
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: falsework
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 3.0.0
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: 2012-04-24 00:00:00.000000000 Z
12
+ date: 2012-04-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: open4
@@ -75,6 +75,22 @@ dependencies:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
77
  version: 1.2.5
78
+ - !ruby/object:Gem::Dependency
79
+ name: fakefs
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 0.4.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 0.4.0
78
94
  description: A primitive scaffold generator for writing CLI programs in Ruby
79
95
  email:
80
96
  - alexander.gromnitsky@gmail.com
@@ -98,65 +114,75 @@ files:
98
114
  - doc/README.rdoc
99
115
  - doc/TODO.org
100
116
  - doc/template-tutorial.rdoc
101
- - dynamic.ruby-cli
117
+ - dynamic.yaml
102
118
  - etc/falsework.yaml
103
119
  - falsework.gemspec
104
120
  - lib/falsework/cliconfig.rb
105
121
  - lib/falsework/cliutils.rb
106
122
  - lib/falsework/meta.rb
107
123
  - lib/falsework/mould.rb
108
- - lib/falsework/templates/c-glib/#config.yaml
109
- - lib/falsework/templates/c-glib/README
110
- - lib/falsework/templates/c-glib/doc/#doc.ascii
111
- - lib/falsework/templates/c-glib/doc/%%@project%%.1.asciidoc
112
- - lib/falsework/templates/c-glib/doc/LICENSE
113
- - lib/falsework/templates/c-glib/doc/Makefile
114
- - lib/falsework/templates/c-glib/src/#exe.c
115
- - lib/falsework/templates/c-glib/src/#exe.h
116
- - lib/falsework/templates/c-glib/src/%%@project%%.c
117
- - lib/falsework/templates/c-glib/src/%%@project%%.h
118
- - lib/falsework/templates/c-glib/src/Makefile
119
- - lib/falsework/templates/c-glib/src/untest.c
120
- - lib/falsework/templates/c-glib/src/untest.h
121
- - lib/falsework/templates/c-glib/src/utils.c
122
- - lib/falsework/templates/c-glib/src/utils.h
123
- - lib/falsework/templates/c-glib/test/#test.c
124
- - lib/falsework/templates/c-glib/test/Makefile
125
- - lib/falsework/templates/c-glib/test/Makefile.test.mk
126
- - lib/falsework/templates/c-glib/test/mycat.c
127
- - lib/falsework/templates/c-glib/test/semis/text/empty.txt
128
- - lib/falsework/templates/c-glib/test/test_utils.c
129
- - lib/falsework/templates/ruby-cli/#config.yaml
130
- - lib/falsework/templates/ruby-cli/%%@project%%.gemspec
131
- - lib/falsework/templates/ruby-cli/.gitignore
132
- - lib/falsework/templates/ruby-cli/.gitignore.#erb
133
- - lib/falsework/templates/ruby-cli/Gemfile
134
- - lib/falsework/templates/ruby-cli/README.rdoc
135
- - lib/falsework/templates/ruby-cli/Rakefile
136
- - lib/falsework/templates/ruby-cli/bin/%%@project%%
137
- - lib/falsework/templates/ruby-cli/doc/#doc.rdoc
138
- - lib/falsework/templates/ruby-cli/doc/LICENSE
139
- - lib/falsework/templates/ruby-cli/doc/NEWS.rdoc
140
- - lib/falsework/templates/ruby-cli/doc/README.rdoc
141
- - lib/falsework/templates/ruby-cli/etc/%%@project%%.yaml
142
- - lib/falsework/templates/ruby-cli/lib/%%@project%%/meta.rb
143
- - lib/falsework/templates/ruby-cli/test/helper.rb
144
- - lib/falsework/templates/ruby-cli/test/test_%%@project%%.rb
124
+ - lib/falsework/upgrader.rb
125
+ - lib/falsework/utils.rb
126
+ - templates/c-glib/#config.yaml
127
+ - templates/c-glib/README
128
+ - templates/c-glib/doc/#doc.ascii
129
+ - templates/c-glib/doc/%%@project%%.1.asciidoc
130
+ - templates/c-glib/doc/LICENSE
131
+ - templates/c-glib/doc/Makefile
132
+ - templates/c-glib/src/#exe.c
133
+ - templates/c-glib/src/#exe.h
134
+ - templates/c-glib/src/%%@project%%.c
135
+ - templates/c-glib/src/%%@project%%.h
136
+ - templates/c-glib/src/Makefile
137
+ - templates/c-glib/src/untest.c
138
+ - templates/c-glib/src/untest.h
139
+ - templates/c-glib/src/utils.c
140
+ - templates/c-glib/src/utils.h
141
+ - templates/c-glib/test/#test.c
142
+ - templates/c-glib/test/Makefile
143
+ - templates/c-glib/test/Makefile.test.mk
144
+ - templates/c-glib/test/mycat.c
145
+ - templates/c-glib/test/semis/text/empty.txt
146
+ - templates/c-glib/test/test_utils.c
147
+ - templates/ruby-cli/#config.yaml
148
+ - templates/ruby-cli/%%@project%%.gemspec
149
+ - templates/ruby-cli/.gitignore
150
+ - templates/ruby-cli/.gitignore.#erb
151
+ - templates/ruby-cli/Gemfile
152
+ - templates/ruby-cli/README.rdoc
153
+ - templates/ruby-cli/Rakefile
154
+ - templates/ruby-cli/bin/%%@project%%
155
+ - templates/ruby-cli/doc/#doc.rdoc
156
+ - templates/ruby-cli/doc/LICENSE
157
+ - templates/ruby-cli/doc/NEWS.rdoc
158
+ - templates/ruby-cli/doc/README.rdoc
159
+ - templates/ruby-cli/etc/%%@project%%.yaml
160
+ - templates/ruby-cli/lib/%%@project%%/meta.rb
161
+ - templates/ruby-cli/test/helper.rb
162
+ - templates/ruby-cli/test/test_%%@project%%.rb
163
+ - test/example/note/full
164
+ - test/example/note/project-too-old
165
+ - test/example/note/template-unknown
145
166
  - test/helper.rb
146
167
  - test/helper_cliutils.rb
147
- - test/rake_erb_templates.rb
148
168
  - test/templates/.gitignore
149
169
  - test/templates/config-01.yaml
150
- - test/templates/config-02.yaml
151
- - test/test_cl.rb
152
- - test/test_exe.rb
170
+ - test/test_cli.rb
153
171
  - test/test_mould.rb
154
- - lib/falsework/templates/ruby-cli/lib/%%@project%%/cliconfig.rb
155
- - lib/falsework/templates/ruby-cli/lib/%%@project%%/cliutils.rb
156
- - lib/falsework/templates/ruby-cli/test/helper_cliutils.rb
172
+ - test/test_upgrader.rb
173
+ - templates/ruby-cli/lib/%%@project%%/cliconfig.rb
174
+ - templates/ruby-cli/lib/%%@project%%/cliutils.rb
175
+ - templates/ruby-cli/test/helper_cliutils.rb
157
176
  homepage: http://github.com/gromnitsky/falsework
158
177
  licenses: []
159
- post_install_message:
178
+ post_install_message: ! 'Users of 2.x! Your custom templates must be updated--format
179
+
180
+ of #config.yaml has changed.
181
+
182
+
183
+ See also doc/NEWS.rdoc file even if you don''t have custom templates.
184
+
185
+ '
160
186
  rdoc_options:
161
187
  - -m
162
188
  - doc/README.rdoc
@@ -183,6 +209,6 @@ signing_key:
183
209
  specification_version: 3
184
210
  summary: A primitive scaffold generator for writing CLI programs in Ruby.
185
211
  test_files:
186
- - test/test_cl.rb
187
- - test/test_exe.rb
212
+ - test/test_cli.rb
188
213
  - test/test_mould.rb
214
+ - test/test_upgrader.rb
data/dynamic.ruby-cli DELETED
@@ -1,3 +0,0 @@
1
- lib/falsework/templates/ruby-cli/lib/%%@project%%/cliconfig.rb
2
- lib/falsework/templates/ruby-cli/lib/%%@project%%/cliutils.rb
3
- lib/falsework/templates/ruby-cli/test/helper_cliutils.rb
@@ -1,18 +0,0 @@
1
- ---
2
- :exe:
3
- - :src: 'src/#exe.h'
4
- :dest: 'src/%s.h'
5
- :mode_int: null
6
- - :src: 'src/#exe.c'
7
- :dest: 'src/%s.c'
8
- :mode_int: null
9
-
10
- :doc:
11
- - :src: 'doc/#doc.ascii'
12
- :dest: 'doc/%s.1.asciidoc'
13
- :mode_int: null
14
-
15
- :test:
16
- - :src: 'test/#test.c'
17
- :dest: 'test/test_%s.c'
18
- :mode_int: null
@@ -1,15 +0,0 @@
1
- ---
2
- :exe:
3
- - :src: 'bin/%%@project%%'
4
- :dest: 'bin/%s'
5
- :mode_int: 0744
6
-
7
- :doc:
8
- - :src: 'doc/#doc.rdoc'
9
- :dest: 'doc/%s.rdoc'
10
- :mode_int: null
11
-
12
- :test:
13
- - :src: 'test/test_%%@project%%.rb'
14
- :dest: 'test/test_%s.rb'
15
- :mode_int: null
@@ -1,2 +0,0 @@
1
- ---
2
- :foobar: foobar
@@ -1,60 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # -*-ruby-*-
3
-
4
- require_relative '../lib/falsework/mould'
5
-
6
- # Search for all files in the project (except .git directory) for the line
7
- #
8
- # /^..? :erb: [^ ]+/
9
- #
10
- # in first 4 lines. If the line is found, the file is considered a
11
- # skeleton for a template. Return a hash {target:template}
12
- def erb_skeletons(local_prj, template)
13
- line_max = 4
14
- target = File.absolute_path("lib/#{local_prj}/templates/#{template}")
15
- r = {}
16
- skiplist = ['/.git[^i]?', "lib/#{local_prj}/templates", '/html', '/pkg',
17
- '/test/templates', 'rake_erb_templates.rb']
18
-
19
- Falsework::Mould.traverse('.') {|i|
20
- next if File.directory?(i)
21
- next if File.symlink?(i)
22
- if skiplist.index {|ign| i.match(/\/?#{ign}\/?/) }
23
- # puts "skipped: #{i}"
24
- next
25
- end
26
- # puts "looking into: #{i}"
27
-
28
- File.open(i) {|fp|
29
- n = 0
30
- while n < line_max && line = fp.gets
31
- # puts line
32
- if line =~ /^..? :erb: [^\s]+/
33
- t = i.sub(/^.+?\//, '')
34
- r[target + '/' + t.sub(/#{local_prj}/, '%%@project%%')] = t
35
- break
36
- end
37
- n += 1
38
- end
39
- }
40
- }
41
-
42
- r
43
- end
44
-
45
- def erb_make(local_prj, template, target, tmplt)
46
- raw = File.read(tmplt)
47
- raw.gsub!(/#{local_prj}/, '<%= @project %>')
48
- raw.gsub!(/#{Mould.name_camelcase(local_prj)}/, '<%= @camelcase %>')
49
-
50
- mark = <<-EOF
51
-
52
- # Don't remove this: <%= #{Mould.name_camelcase(local_prj)}::Meta::NAME %>/<%= #{local_prj.capitalize}::Meta::VERSION %>/#{template}/<%= DateTime.now %>
53
- EOF
54
- File.open(target, 'w+') {
55
- |fp| fp.puts raw + ERB.new(mark).result(binding)
56
- }
57
- end
58
-
59
-
60
- pp erb_skeletons(Falsework::Meta::NAME, 'ruby-cli') if __FILE__ == $0
@@ -1,2 +0,0 @@
1
- ---
2
- :tdir: 'templates'
data/test/test_cl.rb DELETED
@@ -1,33 +0,0 @@
1
- require_relative 'helper'
2
- require_relative '../lib/falsework/mould'
3
-
4
- class Test3867654745 < MiniTest::Unit::TestCase
5
- def setup
6
- # this runs every time before test_*
7
- @cmd = cmd('falsework') # get path to the exe & cd to tests directory
8
- end
9
-
10
- def test_listdirs
11
- assert_equal 2, Mould.class_variable_get(:@@template_dirs).size
12
- out, err = capture_io { Mould.template_dirs_add [Pathname.new("DOESN'T EXISI")] }
13
- assert_equal 2, Mould.class_variable_get(:@@template_dirs).size
14
-
15
- assert_raises(RuntimeError) { Mould.template_dirs_add([Dir.pwd]) }
16
- assert_equal 2, Mould.class_variable_get(:@@template_dirs).size
17
-
18
- Mould.template_dirs_add [Pathname.new(Dir.pwd)]
19
- assert_equal 3, Mould.class_variable_get(:@@template_dirs).size
20
-
21
- assert_equal true, Mould.templates.key?("templates")
22
- end
23
-
24
- def test_new_dir_from_config
25
- r = CliUtils.exec "#{@cmd} --config /NO_SUCH_FILE.yaml listdirs"
26
- assert_equal(0, r[0])
27
- assert_equal(2, r[2].split("\n").size)
28
-
29
- r = CliUtils.exec "#{@cmd} --config templates/config-01.yaml listdirs"
30
- assert_equal(0, r[0])
31
- assert_equal(3, r[2].split("\n").size)
32
- end
33
- end