teapot 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NWYwMzJlZTQ2ZGEzODQ4ODAwMzY1YWNlMDg2OWI0Mzg2MzFmODlhYQ==
4
+ NjhkODU0M2VmNzc4OWQwMGQzNGYyZTU4MzM0NTBjMWU1MTMxYmRjNg==
5
5
  data.tar.gz: !binary |-
6
- ODk0NTJjMjllMDEzNWFmOWFmMGFlOWUyMjFhMjA0YTllYmQ2NGUzMg==
6
+ MmFiZDE4M2VlNGJkNzgyYWY4MDk4ZDI1YjMzNmJlNjZhZDJjY2Q5Mg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- Y2NhNTdkYzgzZTRkZTFjZmFiNGZiMjVlNzkzZDc0ZTYwZThmMzQ3OGJiMjAy
10
- NWE3MGNlZjM3NTJjYmY5M2RmYjMxZGRhYzYxMWY4ZDgyYjA0ZGE4M2ExYTJl
11
- NTkxODQyNGU1NDk3NWRmMDkzODQ4Y2I1YTljNTIxNWNmYTdjOGM=
9
+ Y2ExNjk4YzUwM2UyM2QxYTYyOWIzZWQ2OTVlOGQyYWU0NTk4MTU3MWNlMDQ4
10
+ NTczNDgyZTA5YjdmNTljYTQ0MTM4ZTRmMzA1NjAyMzVjY2IzZWRmNGEyODVj
11
+ MmE3ZjU5ZjAyZDVmNWQwMjc0MmNkNWQzMjE4NzAwODg1NGZlZWY=
12
12
  data.tar.gz: !binary |-
13
- NzBmODAzNjJiYjgzYjk2ZWI3OTc2NGJjZjY0YTM3MDk0NWFiYjI1OTA2ZjE4
14
- NWExMGY0ZjAyZjNmZjMwMmZlMjIwMjU5ZDViNjU2N2M0OTkzN2RjMDUwMGNi
15
- ODIyMWY5ZGYxMTczZTBlMzEyZDM0MTRlY2FjNWU4YTFmZWUxZTg=
13
+ ZjRlOTE3MmIxOGYxY2ZiZmI0MTg1N2RjZWRjODM5MzRmMGM2MzMyN2YwZDk5
14
+ MzYwM2E1YWQ2NjY0ZDg3YjY2MmYxYjEyMDNlNTFiNDkwNjVjMTY0OTQxOTcx
15
+ ZTRlYmE1ZmVjYzFjNmMxZWRkMjFlMzhjNjg1ZDAyZDE3MGYwN2I=
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ dream-framework
data/README.md CHANGED
@@ -21,9 +21,11 @@ Teapot doesn't have a centralised package management system. As such, this examp
21
21
 
22
22
  Firstly, create your project by running:
23
23
 
24
- $ teapot init "My Project" https://github.com/dream-framework project
24
+ $ teapot create "My Project" https://github.com/dream-framework project
25
25
  $ cd my-project
26
26
 
27
+ You will be asked to merge the project file. At present, merge tools are not very good and thus you may need to take a moment to review the changes. You want to keep most of the original file, but you would like to add the `define_target` blocks which are being added.
28
+
27
29
  In the resulting project directory that has been created, you can see the list of dependencies:
28
30
 
29
31
  $ teapot list
@@ -39,6 +41,22 @@ The resulting libraries will be framework dependent, but are typically located i
39
41
  $ cd teapot/$PROJECT_NAME/platforms/$PLATFORM_NAME/bin/
40
42
  $ ./$PROJECT_NAME
41
43
 
44
+ ### Example: Compiling TaggedFormat
45
+
46
+ For Linux (requires `clang` and `libc++`):
47
+
48
+ $ teapot create "Local Tagged Format" https://github.com/dream-framework platform-linux variants tagged-format
49
+ $ cd local-tagged-format
50
+ $ teapot build Library/TaggedFormat variant-debug
51
+
52
+ For Mac OS X (requires Xcode Command Line Tools):
53
+
54
+ $ teapot create "Local Tagged Format" https://github.com/dream-framework platform-darwin-osx variants tagged-format
55
+ $ cd local-tagged-format
56
+ $ teapot build Library/TaggedFormat variant-debug
57
+
58
+ You need to make sure any basic tools, e.g. compilers, system libraries, are installed correctly before building. Consult the platform and library documentation for any dependencies.
59
+
42
60
  ## Contributing
43
61
 
44
62
  1. Fork it
data/bin/teapot CHANGED
@@ -82,14 +82,12 @@ module Application
82
82
  Teapot::Commands.run("git", "init")
83
83
  end
84
84
 
85
- controller = make_controller(root)
86
-
87
- controller.create(project_name, source, packages)
88
- controller.generate('project', [project_name])
85
+ make_controller(root).create(project_name, source, packages)
89
86
  end
90
87
 
91
88
  def self.generate(arguments = ARGV)
92
- make_controller.generate(arguments)
89
+ generator_name = arguments.shift
90
+ make_controller.generate(generator_name, arguments)
93
91
  end
94
92
  end
95
93
 
@@ -46,7 +46,21 @@ module Teapot
46
46
  output.puts "end"
47
47
  end
48
48
 
49
+ # Fetch all packages:
49
50
  fetch
51
+
52
+ # Generate the default project if it is possible to do so:
53
+ generate_project(project_name)
54
+ end
55
+
56
+ private
57
+
58
+ def generate_project(project_name)
59
+ context, configuration = load_teapot
60
+
61
+ if context.generators.key? 'project'
62
+ generate('project', [project_name])
63
+ end
50
64
  end
51
65
  end
52
66
  end
@@ -19,6 +19,8 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  require 'teapot/definition'
22
+ require 'teapot/substitutions'
23
+
22
24
  require 'tempfile'
23
25
 
24
26
  module Teapot
@@ -40,10 +42,13 @@ module Teapot
40
42
  def substitute(text, substitutions)
41
43
  return text unless substitutions
42
44
 
43
- # Use positive look behind so that the pattern is just the substitution key:
44
- pattern = Regexp.new(substitutions.keys.map{|x| Regexp.escape(x)}.join('|'))
45
+ if Hash === substitutions
46
+ pattern = Regexp.new(substitutions.keys.map{|x| Regexp.escape(x)}.join('|'))
45
47
 
46
- text.gsub(pattern) {|key| substitutions[key]}
48
+ text.gsub(pattern) {|key| substitutions[key]}
49
+ else
50
+ substitutions.call(text)
51
+ end
47
52
  end
48
53
 
49
54
  def write(source, destination, substitutions = nil, mode = "a")
data/lib/teapot/name.rb CHANGED
@@ -33,5 +33,9 @@ module Teapot
33
33
  def target
34
34
  @target ||= @text.gsub(/\s+/, '-').downcase
35
35
  end
36
+
37
+ def macro
38
+ @guard ||= @text.upcase.gsub(/\s+/, '_')
39
+ end
36
40
  end
37
41
  end
@@ -65,8 +65,12 @@ module Teapot
65
65
  @options.key? :source
66
66
  end
67
67
 
68
+ def source
69
+ @options[:source].to_s + '/'
70
+ end
71
+
68
72
  def external_url(relative_root)
69
- base_uri = URI(@options[:source].to_s)
73
+ base_uri = URI(source)
70
74
 
71
75
  if base_uri.scheme == nil || base_uri.scheme == 'file'
72
76
  base_uri = URI "file://" + File.expand_path(base_uri.path, relative_root) + "/"
@@ -0,0 +1,202 @@
1
+ # Copyright, 2013, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ module Teapot
22
+ class Indentation
23
+ def initialize(prefix, level, indent)
24
+ @prefix = prefix
25
+ @level = level
26
+ @indent = indent
27
+ end
28
+
29
+ def indentation
30
+ @indentation ||= @prefix + (@indent * @level)
31
+ end
32
+
33
+ def + other
34
+ indentation + other
35
+ end
36
+
37
+ def << text
38
+ text.gsub(/^/){|m| m + indentation}
39
+ end
40
+
41
+ def by(depth)
42
+ Indentation.new(@prefix, @level + depth, @indent)
43
+ end
44
+
45
+ def with_prefix(prefix)
46
+ Indentation.new(prefix, @level, @indent)
47
+ end
48
+
49
+ def self.none
50
+ self.new('', 0, "\t")
51
+ end
52
+ end
53
+
54
+ class Substitutions
55
+ def initialize
56
+ @ordered = []
57
+ end
58
+
59
+ def []= keyword, value
60
+ if Array === value
61
+ open, close = *value.each_slice(value.length / 2)
62
+ @ordered << NestedSubstitution.new(keyword, open, close)
63
+ else
64
+ @ordered << SymbolicSubstitution.new('$' + keyword, value.to_s)
65
+ end
66
+ end
67
+
68
+ def << substitution
69
+ @ordered << substition
70
+ end
71
+
72
+ attr :ordered
73
+
74
+ def call(text)
75
+ apply(text)
76
+ end
77
+
78
+ def apply(text)
79
+ return text unless @ordered.count
80
+
81
+ grouped = [[@ordered.first]]
82
+
83
+ @ordered.drop(1).each do |substitution|
84
+ if grouped.last[0].class == substitution.class
85
+ grouped.last << substitution
86
+ else
87
+ grouped << [substitution]
88
+ end
89
+ end
90
+
91
+ grouped.each do |group|
92
+ text = group.first.class.apply(text, group)
93
+ end
94
+
95
+ return text
96
+ end
97
+
98
+ class SymbolicSubstitution
99
+ def initialize(keyword, value)
100
+ @keyword = keyword
101
+ @value = value
102
+ end
103
+
104
+ attr :keyword
105
+ attr :value
106
+
107
+ def apply(text)
108
+ text.gsub(@keyword, @value)
109
+ end
110
+
111
+ def self.apply(text, group)
112
+ substitutions = Hash[group.collect{|substitution| [substitution.keyword, substitution.value]}]
113
+
114
+ pattern = Regexp.new(substitutions.keys.map{|key| Regexp.escape(key)}.join('|'))
115
+
116
+ text.gsub(pattern) {|key| substitutions[key]}
117
+ end
118
+ end
119
+
120
+ class NestedSubstitution
121
+ def initialize(keyword, open, close, indent = "\t")
122
+ @keyword = keyword
123
+
124
+ @open = open
125
+ @close = close
126
+
127
+ @indent = indent
128
+ end
129
+
130
+ def line_pattern(prefix = '')
131
+ tag_pattern = Regexp.escape('<' + prefix + @keyword + '>')
132
+
133
+ # Line matching pattern:
134
+ Regexp.new('^(.*?)' + tag_pattern + '(.*)$', Regexp::MULTILINE | Regexp::EXTENDED)
135
+ end
136
+
137
+ def write_open(prefix, postfix, output, indentation)
138
+ depth = @open.size
139
+ indentation = indentation.with_prefix(prefix)
140
+
141
+ #output.write(prefix)
142
+ (0...depth).each do |i|
143
+ chunk = @open[i]
144
+ chunk.chomp! if i == depth-1
145
+
146
+ output.write(indentation.by(i) << chunk)
147
+ end
148
+ output.write(postfix)
149
+ end
150
+
151
+ def write_close(prefix, postfix, output, indentation)
152
+ depth = @close.size
153
+ indentation = indentation.with_prefix(prefix)
154
+
155
+ #output.write(prefix)
156
+ (0...depth).reverse_each do |i|
157
+ chunk = @close[-1 - i]
158
+ chunk.chomp! if i == 0
159
+
160
+ output.write(indentation.by(i) << chunk)
161
+ end
162
+ output.write(postfix)
163
+ end
164
+
165
+ def apply(text, level = 0)
166
+ open_pattern = line_pattern
167
+ close_pattern = line_pattern('/')
168
+
169
+ lines = text.each_line
170
+ output = StringIO.new
171
+
172
+ indent = lambda do |level, indentation|
173
+ while line = lines.next rescue nil
174
+ if line =~ open_pattern
175
+ write_open($1, $2, output, indentation)
176
+
177
+ indent[level + @open.count, indentation.by(@open.count)]
178
+
179
+ write_close($1, $2, output, indentation)
180
+ elsif line =~ close_pattern
181
+ break
182
+ else
183
+ output.write(indentation + line)
184
+ end
185
+ end
186
+ end
187
+
188
+ indent[0, Indentation.none]
189
+
190
+ return output.string
191
+ end
192
+
193
+ def self.apply(text, group)
194
+ group.each do |substitution|
195
+ text = substitution.apply(text)
196
+ end
197
+
198
+ return text
199
+ end
200
+ end
201
+ end
202
+ end
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Teapot
22
- VERSION = "0.7.0"
22
+ VERSION = "0.7.1"
23
23
  end
@@ -0,0 +1,67 @@
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'pathname'
22
+ require 'test/unit'
23
+ require 'stringio'
24
+
25
+ require 'teapot/substitutions'
26
+
27
+ class TestSubstitutions < Test::Unit::TestCase
28
+ def test_symobolic_substitutions
29
+ input = <<-EOF
30
+ $FOO $BAR
31
+ EOF
32
+
33
+ output = <<-EOF
34
+ baz bar
35
+ EOF
36
+
37
+ substitutions = Teapot::Substitutions.new
38
+ substitutions['FOO'] = 'baz'
39
+ substitutions['BAR'] = 'bar'
40
+
41
+ assert_equal output, substitutions.apply(input)
42
+ end
43
+
44
+ def test_nested_substitutions
45
+ input = <<-EOF
46
+ <FOO>
47
+ $BAR
48
+ </FOO>
49
+ EOF
50
+
51
+ output = <<-EOF
52
+ enter
53
+ {
54
+ foo
55
+ Hello World
56
+ bar
57
+ }
58
+ exit
59
+ EOF
60
+
61
+ substitutions = Teapot::Substitutions.new
62
+ substitutions['FOO'] = ["enter\n{\n", "foo\n", "bar\n", "}\nexit\n"]
63
+ substitutions['BAR'] = 'Hello World'
64
+
65
+ assert_equal output, substitutions.apply(input)
66
+ end
67
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teapot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-24 00:00:00.000000000 Z
11
+ date: 2013-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
@@ -117,12 +117,14 @@ files:
117
117
  - lib/teapot/loader.rb
118
118
  - lib/teapot/name.rb
119
119
  - lib/teapot/package.rb
120
+ - lib/teapot/substitutions.rb
120
121
  - lib/teapot/target.rb
121
122
  - lib/teapot/version.rb
122
123
  - teapot.gemspec
123
124
  - test/teapot.rb
124
125
  - test/test_dependency.rb
125
126
  - test/test_environment.rb
127
+ - test/test_substitutions.rb
126
128
  - test/test_teapot.rb
127
129
  homepage: ''
128
130
  licenses: []
@@ -151,4 +153,5 @@ test_files:
151
153
  - test/teapot.rb
152
154
  - test/test_dependency.rb
153
155
  - test/test_environment.rb
156
+ - test/test_substitutions.rb
154
157
  - test/test_teapot.rb