treebis 0.0.1

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.
@@ -0,0 +1,136 @@
1
+ require 'minitest/spec'
2
+ require 'treebis'
3
+ require 'nandoc/spec-doc'
4
+ require 'pp'
5
+
6
+ MiniTest::Unit.autorun
7
+
8
+ class String
9
+ def unindent
10
+ this = (/\A([ \t]*)/ =~ self && $1)
11
+ this = /^#{Regexp.escape(this)}/m
12
+ ret = gsub(this, '')
13
+ ret
14
+ end
15
+ end
16
+
17
+ describe 'TestForDoc' do
18
+ NanDoc::SpecDoc.include_to(self)
19
+ Treebis::PersistentDotfile.include_to(self, 'treebis.persistent.json')
20
+
21
+ def prompt
22
+ @prompt ||= NanDoc::MockPrompt.new(self)
23
+ end
24
+
25
+ it 'using dir as hash' do
26
+ @mydir = empty_tmpdir('make-some-files')
27
+ FileUtils.cd(@mydir) do
28
+ nandoc.record_ruby
29
+ require 'treebis'
30
+
31
+ class FilemakerPro
32
+ include Treebis::DirAsHash # hash_to_dir(), dir_as_hash()
33
+
34
+ def make_files in_folder
35
+ hash = {
36
+ 'some-file.txt' => "happy mother's day, <%= name %>",
37
+ 'lists' => {
38
+ 'blah.txt' => 'foo',
39
+ 'favorite-foods.txt' => <<-HERE.gsub(/^ */,'')
40
+ two bite brownies
41
+ peanut cluster things
42
+ HERE
43
+ }
44
+ }
45
+ hash_to_dir(hash, in_folder)
46
+ end
47
+ end
48
+
49
+ FilemakerPro.new.make_files('./foo')
50
+ nandoc.out(<<-HERE.unindent
51
+ ["./foo/lists",
52
+ "./foo/lists/blah.txt",
53
+ "./foo/lists/favorite-foods.txt",
54
+ "./foo/some-file.txt"]
55
+ HERE
56
+ ) do
57
+ PP.pp Dir['./foo/**/*']
58
+ end
59
+ nandoc.record_ruby_stop
60
+ end
61
+ end
62
+
63
+ it 'first task' do
64
+ run_this_test_again 'using dir as hash'
65
+ FileUtils.cd(@mydir) do
66
+ nandoc.record_ruby
67
+ task = Treebis::Task.new do
68
+ from './foo'
69
+ mkdir_p 'lists'
70
+ copy 'lists/*foods.txt'
71
+ erb 'some-file.txt'
72
+ end
73
+
74
+ FileUtils.mkdir('./output')
75
+ erb_values = {:name => 'dear mom'}
76
+ task.erb_values(erb_values).on('./output').run
77
+
78
+ nandoc.out(<<-'HERE'.unindent
79
+ {"lists"=>{"favorite-foods.txt"=>"two bite brownies\npeanut cluster things\n"},
80
+ "some-file.txt"=>"happy mother's day, dear mom"}
81
+ HERE
82
+ ) do
83
+ PP.pp(Treebis::DirAsHash.dir_as_hash('./output'))
84
+ end
85
+ nandoc.record_ruby_stop
86
+ end
87
+ end
88
+
89
+ it 'persistent dotfile' do
90
+ mydir = empty_tmpdir('persitent-dotfile')
91
+ FileUtils.cd(mydir) do
92
+ nandoc.record_ruby
93
+ require 'treebis'
94
+ module SomeMod
95
+ extend self # cute way to get a singleton
96
+ Treebis::PersistentDotfile.include_to(self, 'somefile.json')
97
+ end
98
+
99
+ module OtherMod
100
+ extend self
101
+ Treebis::PersistentDotfile.include_to(self, 'somefile.json')
102
+ end
103
+
104
+ nandoc.inspect SomeMod.persistent_get('foo'), 'nil'
105
+
106
+ SomeMod.persistent_set('foo','bar')
107
+ nandoc.inspect SomeMod.persistent_get('foo'), '"bar"'
108
+
109
+ nandoc.inspect OtherMod.persistent_get('foo'), '"bar"'
110
+ nandoc.record_ruby_stop
111
+ nandoc.story 'see contents'
112
+ nandoc.record_ruby
113
+ nandoc.out(<<-HERE.unindent
114
+ {
115
+ "foo": "bar"
116
+ }
117
+ HERE
118
+ ) do
119
+ puts File.read('somefile.json')
120
+ end
121
+ nandoc.record_ruby_stop
122
+ end
123
+ end
124
+
125
+ # @todo etc
126
+ def run_this_test_again name
127
+ filter = /\Atest_\d{4}_#{name.gsub(/[^_a-z0-9]/i,'_')}\Z/
128
+ mm = self.class.test_methods.grep(filter)
129
+ case mm.size
130
+ when 0; fail("failed to find methods named #{name.inspect} with #{re}")
131
+ when 1;
132
+ else fail("found too many methods for #{name}: #{mm.join(', ')}")
133
+ end
134
+ send(mm.first)
135
+ end
136
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: treebis
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Chip Malice
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-11 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: json
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: json
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 1
41
+ - 2
42
+ - 3
43
+ version: 1.2.3
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ description: Treebis is a minimal, general scripting/task utility written in ruby that wraps common actions for moving, copying and altering filetrees. It is geared towards things like generators. It is comparable to a shell script that does a lot of mkdir, mv, cp commmands etc.
47
+ email: chip.malice@gmail.com
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - README
54
+ files:
55
+ - README
56
+ - Rakefile
57
+ - VERSION
58
+ - doc/additional-goodies/persistent-dotfile.md
59
+ - doc/svg/go-green.svg
60
+ - doc/usage-examples.md
61
+ - lib/treebis.rb
62
+ - test/test-for-doc.rb
63
+ has_rdoc: true
64
+ homepage: http://treebis.hipeland.org
65
+ licenses: []
66
+
67
+ post_install_message:
68
+ rdoc_options:
69
+ - --charset=UTF-8
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ requirements: []
87
+
88
+ rubyforge_project: treebis
89
+ rubygems_version: 1.3.6
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: minimal single-file rake-like task DSL for wrapping common filesystem tasks like copying files.
93
+ test_files:
94
+ - test/test-for-doc.rb