bahuvrihi-tap 0.10.8 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -384,7 +384,7 @@ module Tap
384
384
  end
385
385
 
386
386
  # get output files from the block, expand and sort
387
- output_files = [block.call(input_files)].flatten.collect do |output_file|
387
+ output_files = [*block.call(input_files)].collect do |output_file|
388
388
  File.expand_path(output_file)
389
389
  end.sort
390
390
 
@@ -60,7 +60,7 @@ module Tap
60
60
  # # !> DereferenceError
61
61
  #
62
62
  def reference_map(source_dir, reference_dir, pattern='**/*.ref')
63
- Dir.glob(File.join(source_dir, pattern)).collect do |source|
63
+ Dir.glob(File.join(source_dir, pattern)).sort.collect do |source|
64
64
  # use the path specified in the source file
65
65
  relative_path = File.read(source).gsub(/#.*$/, "").strip
66
66
 
@@ -228,4 +228,4 @@ module Tap
228
228
  end
229
229
  end
230
230
  end
231
- end
231
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bahuvrihi-tap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.8
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Chiang
@@ -35,7 +35,6 @@ files:
35
35
  - cmd/generate.rb
36
36
  - cmd/manifest.rb
37
37
  - cmd/run.rb
38
- - cmd/server.rb
39
38
  - doc/Tutorial
40
39
  - doc/Class Reference
41
40
  - doc/Command Reference
@@ -90,7 +89,6 @@ files:
90
89
  - lib/tap/support/executable.rb
91
90
  - lib/tap/support/executable_queue.rb
92
91
  - lib/tap/support/gems/rake.rb
93
- - lib/tap/support/gems/rack.rb
94
92
  - lib/tap/support/gems.rb
95
93
  - lib/tap/support/instance_configuration.rb
96
94
  - lib/tap/support/intern.rb
@@ -139,9 +137,6 @@ files:
139
137
  - lib/tap/test/utils.rb
140
138
  - lib/tap/test.rb
141
139
  - lib/tap.rb
142
- - template/404.erb
143
- - template/index.erb
144
- - vendor/url_encoded_pair_parser.rb
145
140
  - README
146
141
  - MIT-LICENSE
147
142
  - History
@@ -1,42 +0,0 @@
1
- # tap server {options}
2
- #
3
- # Initializes a tap server.
4
-
5
- require 'tap'
6
- require 'tap/support/gems/rack'
7
-
8
- env = Tap::Env.instance
9
-
10
- #
11
- # handle options
12
- #
13
- options = {:Port => 8080}
14
- OptionParser.new do |opts|
15
-
16
- opts.separator ""
17
- opts.separator "options:"
18
-
19
- opts.on("-h", "--help", "Show this message") do
20
- opts.banner = Tap::Support::TDoc.usage(__FILE__)
21
- puts opts
22
- exit
23
- end
24
-
25
- opts.on("-p", "--port PORT", Integer, "Specifies the port (default #{options[:Port]})") do |value|
26
- options[:Port] = value
27
- end
28
-
29
- opts.on("-d", "--development", Integer, "Specifies development mode") do
30
- env.config[:development] = true
31
- end
32
-
33
- end.parse!(ARGV)
34
-
35
- #
36
- # cgi dir and public dir can be set in tap.yml
37
- #
38
-
39
- env.extend Tap::Support::Gems::Rack
40
- Rack::Handler::WEBrick.run(env, options) do |handler|
41
- env.handler = handler
42
- end
@@ -1,282 +0,0 @@
1
- require 'rack'
2
- require 'yaml'
3
-
4
- # in a future release, it looks like this will be changed
5
- require 'rack/file'
6
- #require 'rack/mime'
7
-
8
- module Tap
9
- module Support
10
- module Gems
11
-
12
- Tap::Env.manifest(:cgis) do |env|
13
- entries = []
14
- env.root.glob(:cgi, "**/*.rb").each do |path|
15
- env.root.relative_filepath(:cgi, path)
16
- end
17
-
18
- entries = entries.sort_by {|path| File.basename(path) }
19
- Support::Manifest.intern(entries) {|path| "/" + path }
20
- end
21
-
22
- # = UNDER CONSTRUCTION
23
- # Support for a Tap::Server, built on {Rack}[http://rack.rubyforge.org/].
24
- #
25
- # Tap::Support::Gems::Rack is intended to extend a Tap::Env
26
- module Rack
27
-
28
- # The handler for the server (ex Rack::Handler::WEBrick)
29
- attr_accessor :handler
30
-
31
- # The default error template used by response
32
- # when an error occurs.
33
- DEFAULT_ERROR_TEMPLATE = %Q{
34
- <html>
35
- <body>
36
- # Error handling request: <%= error.message %></br>
37
- # <%= error.backtrace.join("<br/># ") %>
38
-
39
- <code><pre>
40
- <%= cgi.to_yaml %>
41
- <%= rack.to_yaml %>
42
- </pre></code>
43
- </body>
44
- </html>
45
- }
46
-
47
- # Creates a [status, headers, body] response using the result of the
48
- # block as the body. The status and headers the defaults for
49
- # {Rack::Response}[http://rack.rubyforge.org/doc/classes/Rack/Response.html].
50
- # If an error occurs, a default error message is generated using the
51
- # DEFAULT_ERROR_TEMPLATE.
52
- def response(rack_env)
53
- ::Rack::Response.new.finish do |res|
54
- res.write begin
55
- yield(res)
56
- rescue
57
- template(DEFAULT_ERROR_TEMPLATE, env_attrs(rack_env).merge(:error => $!))
58
- end
59
- end
60
- end
61
-
62
- # The {Rack}[http://rack.rubyforge.org/doc/] interface method. Call
63
- # routesrequests (with preference) to:
64
- # * static pages
65
- # * cgi scripts
66
- # * default responses
67
- #
68
- # === Static pages
69
- # Static pages may be served from any env in self. A static page is
70
- # served if a file with the request path exists under the 'public'
71
- # directory for any env.
72
- #
73
- # Envs are searched in order, using the Env#search_path method.
74
- #
75
- # === CGI scripts
76
- # Like static pages, cgi scripts may be served from any env in self.
77
- # Scripts are discovered using a search of the cgi manifest. See
78
- # cgi_response for more details.
79
- #
80
- # === Default responses
81
- # The default response is path-dependent:
82
- #
83
- # path action
84
- # /, /index render the manifest.
85
- # all others render a 404 response
86
- #
87
- # The manifest may be refreshed by setting a query string:
88
- #
89
- # /?refresh=true
90
- # /index?refresh=true
91
- #
92
- def call(rack_env)
93
- path = rack_env['PATH_INFO']
94
-
95
- case
96
- when static_path = search_path(:public, path) {|file| File.file?(file) }
97
- # serve named static pages
98
- file_response(static_path, rack_env)
99
-
100
- when cgi_path = search(:cgis, path)
101
- # serve cgis
102
- cgi_response(cgi_path, rack_env)
103
-
104
- # when task_path = search(:tasks, path)
105
- # # serve tasks
106
- # cgi_response('task', rack_env)
107
-
108
- when path == "/" || path == "/index"
109
- # serve up the homepage
110
- if rack_env["QUERY_STRING"] == "refresh=true"
111
- # reset(:cgis) do |key, path|
112
- # Support::Lazydoc[path].resolved = false
113
- # end
114
- end
115
- render_response('index.erb', rack_env)
116
-
117
- else
118
- # handle all other requests as errors
119
- render_response('404.erb', rack_env)
120
-
121
- end
122
- end
123
-
124
- # Generates a [status, headers, body] response for the specified file.
125
- # Patterned after {Rack::File#._call}[http://rack.rubyforge.org/doc/classes/Rack/File.html].
126
- def file_response(path, rack_env)
127
- response(rack_env) do |res|
128
- content = File.read(path)
129
- res.headers.merge!(
130
- "Last-Modified" => File.mtime(path).httpdate,
131
- "Content-Type" => ::Rack::File::MIME_TYPES[File.extname(path)] || "text/plain", # Rack::Mime.mime_type(File.extname(path), 'text/plain'),
132
- "Content-Length" => content.size.to_s)
133
-
134
- content
135
- end
136
- end
137
-
138
- # Generates a [status, headers, body] response for the specified cgi.
139
- # The cgi will be run with ENV set as specified in rack_env.
140
- def cgi_response(cgi_path, rack_env)
141
-
142
- # setup standard ios for capture
143
- current_input = $stdin
144
- current_output = $stdout
145
-
146
- cgi_input = rack_env['rack.input']
147
- cgi_output = StringIO.new("")
148
-
149
- begin
150
- $stdin = cgi_input
151
- $stdout = cgi_output
152
-
153
- # run the cgi
154
- with_ENV(rack_env) { load(cgi_path) }
155
-
156
- # collect the headers and body from the output
157
- headers, body = cgi_output.string.split(/\r?\n\r?\n/, 2)
158
-
159
- raise "missing headers from: #{cgi_path}" if headers == nil
160
- body = "" if body == nil
161
-
162
- headers = headers.split(/\r?\n/).inject({}) do |hash, line|
163
- key, value = line.split(/:/, 2)
164
- hash[key] = value
165
- hash
166
- end
167
-
168
- # generate the response
169
- [headers.delete('Status') || 200, headers, body]
170
-
171
- rescue(Exception)
172
- # when an error occurs, return a standard cgi error with backtrace
173
- [500, {'Content-Type' => 'text/plain'}, %Q{#{$!.class}: #{$!.message}\n#{$!.backtrace.join("\n")}}]
174
-
175
- ensure
176
- $stdin = current_input
177
- $stdout = current_output
178
- end
179
- end
180
-
181
- # def cgi_template(name, attributes={})
182
- # path = root.filepath(:template, "#{name}.erb")
183
- # Templater.new( File.read(path), {:server => self}.merge(attributes) ).build
184
- # end
185
-
186
- # Generates a [status, headers, body] response using the first existing
187
- # template matching path (as determined by Env#search_path) and the
188
- # specified rack_env.
189
- def render_response(path, rack_env)
190
- # partition and sort the env variables into
191
- # cgi and rack variables.
192
- rack, cgi = rack_env.to_a.partition do |(key, value)|
193
- key =~ /^rack/
194
- end.collect do |part|
195
- part.sort_by do |key, value|
196
- key
197
- end.inject({}) do |hash, (key,value)|
198
- hash[key] = value
199
- hash
200
- end
201
- end
202
-
203
- response(rack_env) do
204
- render(path, env_attrs(rack_env))
205
- end
206
- end
207
-
208
- module Render
209
- def renderer(path)
210
- template = env.search_path(:template, path) {|file| File.file?(file) }
211
- raise("no such template: #{path}") if template == nil
212
- Tap::Support::Templater.new(File.read(template), marshal_dump).extend(Render)
213
- end
214
-
215
- def render(path, attrs={})
216
- renderer(path).build(attrs)
217
- end
218
- end
219
-
220
- # Builds the specified template using the rack_env and additional
221
- # attributes. The rack_env is partitioned into rack-related and
222
- # cgi-related hashes (all rack_env entries where the key starts
223
- # with 'rack' are rack-related, the others are cgi-related).
224
- #
225
- # The template is built with the following standard locals:
226
- #
227
- # server self
228
- # cgi the cgi-related hash
229
- # rack the rack-related hash
230
- #
231
- # Plus the attributes.
232
- def render(path, attributes={}) # :nodoc:
233
- path = search_path(:template, path) {|file| File.file?(file) }
234
- raise("no such template: #{path}") if path == nil
235
-
236
- template(File.read(path) , attributes)
237
- end
238
-
239
- def env_attrs(rack_env)
240
- # partition and sort the env variables into
241
- # cgi and rack variables.
242
- rack, cgi = rack_env.to_a.partition do |(key, value)|
243
- key =~ /^rack/
244
- end.collect do |part|
245
- part.sort_by do |key, value|
246
- key
247
- end.inject({}) do |hash, (key,value)|
248
- hash[key] = value
249
- hash
250
- end
251
- end
252
-
253
- {:env => self, :cgi => cgi, :rack => rack}
254
- end
255
-
256
- def template(template, attributes={}) # :nodoc:
257
- Templater.new(template, attributes).extend(Render).build
258
- end
259
-
260
- protected
261
-
262
- # Executes block with ENV set to the specified hash.
263
- # Non-string values in hash are skipped.
264
- def with_ENV(hash) # :nodoc:
265
- current_env = {}
266
- ENV.each_pair {|key, value| current_env[key] = value }
267
-
268
- begin
269
- ENV.clear
270
- hash.each_pair {|key, value| ENV[key] = value if value.kind_of?(String)}
271
-
272
- yield
273
- ensure
274
- ENV.clear
275
- current_env.each_pair {|key, value| ENV[key] = value }
276
- end
277
- end
278
-
279
- end
280
- end
281
- end
282
- end
@@ -1,12 +0,0 @@
1
- <html>
2
- <body>
3
- <p>
4
- # 404 error<br/>
5
- # Could not handle request:
6
- </p>
7
- <code><pre>
8
- <%= cgi.to_yaml %>
9
- <%= rack.to_yaml %>
10
- </pre></code>
11
- </body>
12
- </html>
@@ -1,49 +0,0 @@
1
- <% env_names = {} %>
2
- <% env.manifest(:envs, true).minimize.each do |name, environment| %>
3
- <% env_names[environment] = name %>
4
- <% end %>
5
- <html>
6
- <head>
7
- <title>Tap::Manifest</title>
8
- </head>
9
- <body>
10
-
11
- <div id="branding">
12
- <h1><a href="<%= Tap::WEBSITE %>">Tap (<ins>T</ins>ask <ins>Ap</ins>plication) <%= Tap::VERSION %> </a></h1>
13
- </div>
14
-
15
- <div id="content_main">
16
- <dl id="envs" class="manifest">
17
- <% env.each do |current| %>
18
- <dt class="key"><%= env_names[current] %> (<%= current.root.root %>)</dt>
19
- <dd class="value">
20
- <% manifest_keys = (Tap::Env.manifests.keys + current.manifests.keys).uniq %>
21
- <% manifest_keys -= [:envs] %>
22
- <% manifest_keys.each do |key| %>
23
- <% manifest = current.manifest(key, true) %>
24
- <% next if manifest.empty? %>
25
- <dl id="manifests" class="manifest">
26
- <dt class="key"><%= key %></dt>
27
- <dd class="value">
28
- <ol>
29
- <% manifest.each do |(name, path)| %>
30
- <% path = path.kind_of?(Tap::Support::Constant) ? path.require_path : path %>
31
- <li><%= name %> (<%= current.root.relative_filepath(:root, path) || path %>)</li>
32
- <% end %>
33
- </ol>
34
- </dd>
35
- </dl>
36
- <% end %>
37
- </dd>
38
- <% end %>
39
- </dl>
40
- </div>
41
-
42
- <div id="nav">
43
- <ul>
44
- <li><a href="index?refresh=true">Refresh</a></li>
45
- </ul>
46
- </div>
47
-
48
- </body>
49
- </html>
@@ -1,93 +0,0 @@
1
- require 'strscan'
2
-
3
- class UrlEncodedPairParser < StringScanner #:nodoc:
4
- attr_reader :top, :parent, :result
5
-
6
- def initialize(pairs = [])
7
- super('')
8
- @result = {}
9
- pairs.each { |key, value| parse(key, value) }
10
- end
11
-
12
- KEY_REGEXP = %r{([^\[\]=&]+)}
13
- BRACKETED_KEY_REGEXP = %r{\[([^\[\]=&]+)\]}
14
-
15
- # Parse the query string
16
- def parse(key, value)
17
- self.string = key
18
- @top, @parent = result, nil
19
-
20
- # First scan the bare key
21
- key = scan(KEY_REGEXP) or return
22
- key = post_key_check(key)
23
-
24
- # Then scan as many nestings as present
25
- until eos?
26
- r = scan(BRACKETED_KEY_REGEXP) or return
27
- key = self[1]
28
- key = post_key_check(key)
29
- end
30
-
31
- bind(key, value)
32
- end
33
-
34
- private
35
- # After we see a key, we must look ahead to determine our next action. Cases:
36
- #
37
- # [] follows the key. Then the value must be an array.
38
- # = follows the key. (A value comes next)
39
- # & or the end of string follows the key. Then the key is a flag.
40
- # otherwise, a hash follows the key.
41
- def post_key_check(key)
42
- if scan(/\[\]/) # a[b][] indicates that b is an array
43
- container(key, Array)
44
- nil
45
- elsif check(/\[[^\]]/) # a[b] indicates that a is a hash
46
- container(key, Hash)
47
- nil
48
- else # End of key? We do nothing.
49
- key
50
- end
51
- end
52
-
53
- # Add a container to the stack.
54
- def container(key, klass)
55
- type_conflict! klass, top[key] if top.is_a?(Hash) && top.key?(key) && ! top[key].is_a?(klass)
56
- value = bind(key, klass.new)
57
- type_conflict! klass, value unless value.is_a?(klass)
58
- push(value)
59
- end
60
-
61
- # Push a value onto the 'stack', which is actually only the top 2 items.
62
- def push(value)
63
- @parent, @top = @top, value
64
- end
65
-
66
- # Bind a key (which may be nil for items in an array) to the provided value.
67
- def bind(key, value)
68
- if top.is_a? Array
69
- if key
70
- if top[-1].is_a?(Hash) && ! top[-1].key?(key)
71
- top[-1][key] = value
72
- else
73
- top << {key => value}#.with_indifferent_access
74
- push top.last
75
- end
76
- else
77
- top << value
78
- end
79
- elsif top.is_a? Hash
80
- key = CGI.unescape(key)
81
- parent << (@top = {}) if top.key?(key) && parent.is_a?(Array)
82
- return top[key] ||= value
83
- else
84
- raise ArgumentError, "Don't know what to do: top is #{top.inspect}"
85
- end
86
-
87
- return value
88
- end
89
-
90
- def type_conflict!(klass, value)
91
- raise TypeError, "Conflicting types for parameter containers. Expected an instance of #{klass} but found an instance of #{value.class}. This can be caused by colliding Array and Hash parameters like qs[]=value&qs[key]=value."
92
- end
93
- end