wire-framework 0.1.4.26 → 0.1.5

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/lib/app/file.rb CHANGED
@@ -1,81 +1,85 @@
1
+ ##
2
+ # Copyright 2017 Bryan T. Meyers
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ ##
16
+
1
17
  require 'awesome_print'
2
- require_relative '../wire'
3
18
 
4
19
  # Static is a Wire::App for serving read-only, static files
5
20
  # @author Bryan T. Meyers
6
21
  module Static
7
- extend Wire::App
8
- extend Wire::Resource
9
-
10
- # Map a file folder to a sub-URI
11
- # @param [String] resource the sub-URI
12
- # @param [Class] path the file folder
13
- # @return [void]
14
- def self.local(resource, path)
15
- $current_app[:resources][resource] = { local: path }
16
- end
17
22
 
18
- # Get a file listing for this folder
19
- # @param [Hash] context the context for this request
20
- # @return [Response] a listing, or status code
21
- def self.do_read_all(context)
22
- path = context.resource[:local]
23
- if path
24
- return 404 unless File.exists?(path)
25
- if File.directory? path
26
- Dir.entries(path).sort.to_s
27
- else
28
- 401
29
- end
30
- else
31
- 404
32
- end
33
- end
23
+ # Get a file listing for this folder
24
+ # @param [Hash] context the context for this request
25
+ # @return [Response] a listing, or status code
26
+ def self.do_read_all(context)
27
+ path = context.config['path']
28
+ if path
29
+ return 404 unless File.exists?(path)
30
+ if File.directory? path
31
+ Dir.entries(path).sort.to_s
32
+ else
33
+ 401
34
+ end
35
+ else
36
+ 404
37
+ end
38
+ end
34
39
 
35
- # Get a file from this folder
36
- # @param [Hash] context the context for this request
37
- # @return [Response] a file, listing, or status code
38
- def self.do_read(context)
39
- path = context.resource[:local]
40
- id = context.uri[3..context.uri.length].join('/')
41
- if path
42
- ext_path = File.join(path, id)
43
- return 404 unless File.exists?(ext_path)
44
- if File.directory?(ext_path)
45
- "#{ap Dir.entries(ext_path).sort}"
46
- else
47
- if ext_path.end_with?('.wiki') || ext_path.end_with?('.mediawiki')
48
- mime = 'text/wiki'
49
- else
50
- mime = `mimetype --brief #{ext_path}`
51
- end
52
- headers = {}
53
- headers['Content-Type'] = mime
54
- headers['Cache-Control'] = 'public'
55
- headers['Expires'] = "#{(Time.now + 30000000).utc}"
56
- body = File.read(ext_path)
57
- [200, headers, body]
58
- end
59
- else
60
- 404
61
- end
62
- end
40
+ # Get a file from this folder
41
+ # @param [Hash] context the context for this request
42
+ # @return [Response] a file, listing, or status code
43
+ def self.do_read(context)
44
+ path = context.config['path']
45
+ if path
46
+ ext_path = File.join(path, context.resource, context.id)
47
+ return 404 unless File.exists?(ext_path)
48
+ if File.directory?(ext_path)
49
+ "#{ap Dir.entries(ext_path).sort}"
50
+ else
51
+ if ext_path.end_with?('.wiki') || ext_path.end_with?('.mediawiki')
52
+ mime = 'text/wiki'
53
+ else
54
+ mime = `mimetype --brief #{ext_path}`
55
+ end
56
+ headers = {}
57
+ headers['Content-Type'] = mime
58
+ headers['Cache-Control'] = 'public'
59
+ headers['Expires'] = "#{(Time.now + 30000000).utc}"
60
+ body = File.read(ext_path)
61
+ [200, headers, body]
62
+ end
63
+ else
64
+ 404
65
+ end
66
+ end
63
67
 
64
- # Proxy method used when routing
65
- # @param [Array] actions the allowed actions for this URI
66
- # @param [Hash] context the context for this request
67
- # @return [Response] a Rack Response triplet, or status code
68
- def self.invoke(actions, context)
69
- return 404 unless context.resource
70
- case context.action
71
- when :read
72
- if context.uri[3]
73
- do_read(context)
74
- else
75
- do_read_all(context)
76
- end
77
- else
78
- 403
79
- end
80
- end
68
+ # Proxy method used when routing
69
+ # @param [Array] actions the allowed actions for this URI
70
+ # @param [Hash] context the context for this request
71
+ # @return [Response] a Rack Response triplet, or status code
72
+ def self.invoke(actions, context)
73
+ return 404 unless context.resource
74
+ case context.action
75
+ when :read
76
+ if context.id
77
+ do_read(context)
78
+ else
79
+ do_read_all(context)
80
+ end
81
+ else
82
+ 403
83
+ end
84
+ end
81
85
  end
data/lib/app/history.rb CHANGED
@@ -1,59 +1,60 @@
1
- require 'awesome_print'
1
+ ##
2
+ # Copyright 2017 Bryan T. Meyers
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ ##
16
+
2
17
  require 'tilt'
3
- require_relative '../wire'
4
18
  require_relative 'history/svn'
5
19
 
6
20
  # History is a Wire::App for accessing the history of versioned content
7
21
  # @author Bryan T. Meyers
8
22
  module History
9
23
 
10
- # Select the location of the repositories
11
- # @param [Symbol] path location of the repositories
12
- # @return [void]
13
- def repos(path)
14
- $current_app[:repos_path] = path
15
- end
16
-
17
- # Select the render template for histories
18
- # @param [Symbol] path location of the Tilt compatible template
19
- # @return [void]
20
- def log(path)
21
- $current_app[:template] = Tilt.new(path, 1, { ugly: true })
22
- end
23
-
24
- # Select the sub-directory for web-serveable content
25
- # @param [Symbol] path the sub-directory path
26
- # @return [void]
27
- def web_folder(path)
28
- $current_app[:web] = path
29
- end
24
+ # Configure this History with a log template
25
+ # @param [Hash] conf the raw configuration
26
+ # @return [Hash] post-processed configuration
27
+ def self.configure(conf)
28
+ conf['log'] = Tilt.new(conf['log'], 1, { ugly: true })
29
+ conf
30
+ end
30
31
 
31
- # Get the history of a single file or directory
32
- # @param [Hash] context the context for this request
33
- # @return [Response] the history, or status code
34
- def do_read(actions, context)
35
- resource = context.uri[2]
36
- web = context.app[:web]
37
- id = context.uri[3...context.uri.length].join('/')
38
- list = get_log(web, resource, id)
39
- if list == 404
40
- return 404
41
- end
42
- template = context.app[:template]
43
- template.render(self, actions: actions, context: context, list: list)
44
- end
32
+ # Get the history of a single file or directory
33
+ # @param [Hash] context the context for this request
34
+ # @return [Response] the history, or status code
35
+ def do_read(actions, context)
36
+ list = get_log(context.config['host'],
37
+ context.resource,
38
+ context.config['web_folder'],
39
+ context.id)
40
+ if list == 404
41
+ return 404
42
+ end
43
+ template = context.config['log']
44
+ template.render(self, actions: actions, context: context, list: list)
45
+ end
45
46
 
46
- # Proxy method used when routing
47
- # @param [Array] actions the allowed actions for this URI
48
- # @param [Hash] context the context for this request
49
- # @return [Response] a Rack Response triplet, or status code
50
- def invoke(actions, context)
51
- return 404 unless context.uri[2]
52
- case context.action
53
- when :read
54
- do_read(actions, context)
55
- else
56
- 403
57
- end
58
- end
47
+ # Proxy method used when routing
48
+ # @param [Array] actions the allowed actions for this URI
49
+ # @param [Hash] context the context for this request
50
+ # @return [Response] a Rack Response triplet, or status code
51
+ def invoke(actions, context)
52
+ return 404 unless context.resource
53
+ case context.action
54
+ when :read
55
+ do_read(actions, context)
56
+ else
57
+ 403
58
+ end
59
+ end
59
60
  end
@@ -1,30 +1,49 @@
1
+ ##
2
+ # Copyright 2017 Bryan T. Meyers
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ ##
16
+
1
17
  require_relative '../repo'
2
18
  require 'cobravsmongoose'
3
19
 
4
20
  module History
5
- # History::SVN is a connector for viewing log information in SVN
6
- # @author Bryan T. Meyers
7
- module SVN
8
- extend Wire::App
9
- extend Wire::Resource
10
- extend History
21
+ # History::SVN is a connector for viewing log information in SVN
22
+ # @author Bryan T. Meyers
23
+ module SVN
24
+ extend History
11
25
 
12
- # Get the log information for any part of a Repo
13
- # @param [String] web the web path of the repo
14
- # @param [String] repo the name of the repository to access
15
- # @param [String] id the sub-URI of the item to access
16
- # @return [Hash] the history entries
17
- def self.get_log(web, repo, id = nil)
18
- options = "--username #{$environment[:repos_user]} --password #{$environment[:repos_password]}"
19
- uri = "svn://localhost/#{repo}"
20
- if id
21
- uri += "/#{web}" if web
22
- uri += "/#{id}"
23
- end
24
- log = `svn log #{options} -v --xml '#{uri}'`
25
- return 404 if $?.exitstatus != 0
26
- log = CobraVsMongoose.xml_to_hash(log)
27
- log['log']['logentry']
28
- end
29
- end
26
+ # Get the log information for any part of a Repo
27
+ # @param [String] host the name of the host to connect to
28
+ # @param [String] repo the name of the repository to access
29
+ # @param [String] web the web path of the repo
30
+ # @param [String] id the sub-URI of the item to access
31
+ # @return [Hash] the history entries
32
+ def self.get_log(host, repo, web, id = nil)
33
+ options = "--username #{$environment[:repos_user]} --password #{$environment[:repos_password]}"
34
+ uri = "svn://#{host}/#{repo}"
35
+ if id
36
+ if web
37
+ uri += "/#{web}"
38
+ end
39
+ uri += "/#{id}"
40
+ end
41
+ log = `svn log #{options} -v --xml '#{uri}'`
42
+ if $?.exitstatus != 0
43
+ return 404
44
+ end
45
+ log = CobraVsMongoose.xml_to_hash(log)
46
+ log['log']['logentry']
47
+ end
48
+ end
30
49
  end
data/lib/app/login.rb CHANGED
@@ -1,14 +1,29 @@
1
+ ##
2
+ # Copyright 2017 Bryan T. Meyers
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ ##
16
+
1
17
  # Login is a Wire::App for forcing user logins
2
18
  # @author Bryan T. Meyers
3
19
  module Login
4
20
 
5
- # Proxy method used when routing
6
- # @param [Array] actions the allowed actions for this URI
7
- # @param [Hash] context the context for this request
8
- # @return [Response] a redirect message returning to the previous page
9
- def self.invoke(actions, context)
10
- referer = context.referer
11
- [307, { 'Location' => referer.join('/') }, ['Login Redirect']]
12
- end
21
+ # Proxy method used when routing
22
+ # @param [Array] actions the allowed actions for this URI
23
+ # @param [Hash] context the context for this request
24
+ # @return [Response] a redirect message returning to the previous page
25
+ def self.invoke(actions, context)
26
+ [307, { 'Location': context.referer.join('/') }, ['Login Redirect']]
27
+ end
13
28
 
14
29
  end
data/lib/app/render.rb CHANGED
@@ -1,10 +1,19 @@
1
- require 'nokogiri'
2
- require 'awesome_print'
3
- require 'rest-less'
4
- require 'docile'
5
- require 'tilt'
6
- require 'json'
7
- require_relative '../wire'
1
+ ##
2
+ # Copyright 2017 Bryan T. Meyers
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ ##
16
+
8
17
  require_relative 'render/document'
9
18
  require_relative 'render/editor'
10
19
  require_relative 'render/error'
@@ -16,103 +25,5 @@ require_relative 'render/style'
16
25
  # Render is an Abstract Wire::App for transforming content
17
26
  # @author Bryan T. Meyers
18
27
  module Render
19
- include Wire::Resource
20
-
21
- # Setup the remote connection for content
22
- # @param [String] hostname http hostname and port of remote
23
- # @param [String] uri the base URI for content on the remote
24
- # @return [void]
25
- def remote(hostname, uri)
26
- $current_app[:remote_host] = hostname
27
- $current_app[:remote_uri] = uri
28
- end
29
-
30
- # Setup the template for rendering
31
- # @param [String] path location of the template
32
- # @param [Proc] block block to execute for setting up template
33
- # @return [void]
34
- def template(path, &block)
35
- $current_app[:template] = { path: path.nil? ? nil : Tilt.new(path, 1, { ugly: true }), sources: {} }
36
- if block
37
- Docile.dsl_eval(self, &block)
38
- end
39
- end
40
-
41
- # Enable the use of an outer layout, for the current template
42
- def use_layout
43
- $current_app[:template][:use_layout] = true
44
- end
45
-
46
- # Setup the source for additional template information
47
- # @param [Symbol] key the type of key for this source
48
- # @param [String] uri the path for a remote source
49
- # @param [Proc] block block to execute for setting up source
50
- # @return [void]
51
- def source(key, uri, &block)
52
- $current_app[:template][:sources][key] = { uri: uri, key: nil }
53
- $current_source = $current_app[:template][:sources][key]
54
- if block
55
- Docile.dsl_eval(self, &block)
56
- end
57
- end
58
-
59
- # Setup the key for additional source information
60
- # @param [Symbol] type the type of key for this source
61
- # @return [void]
62
- def key(type)
63
- $current_source[:key] = type
64
- end
65
-
66
- # Setup the template for rendering single items
67
- # @param [String] template the path to the template
68
- # @return [void]
69
- def single(template)
70
- partial = Tilt.new(template, 1, { ugly: true })
71
- $current_resource[:single] = partial
72
- end
73
-
74
- # Setup the template for rendering multiple items
75
- # @param [String] template the path to the template
76
- # @return [void]
77
- def multiple(template)
78
- partial = Tilt.new(template, 1, { ugly: true })
79
- $current_resource[:multiple] = partial
80
- end
81
-
82
- # Setup the template for rendering one or more items
83
- # @param [String] template the path to the template
84
- # @return [void]
85
- def all(template)
86
- multiple(template)
87
- single(template)
88
- end
89
-
90
- CONVERT = {
91
- create: :post,
92
- read: :get,
93
- readAll: :get,
94
- update: :put,
95
- delete: :delete
96
- }
97
28
 
98
- # Proxy method used when forwarding requests
99
- # @param [Symbol] method the action to use when forwarding
100
- # @param [Hash] context the context for this request
101
- # @return [Response] a Rack Response triplet, or status code
102
- def forward(method, context)
103
- host = context.app[:remote_host]
104
- path = context.app[:remote_uri]
105
- resource = context.uri[2]
106
- referer = context.referer.join('/')
107
- q = '?' + context.query_string
108
- id = context.uri[3...context.uri.length].join('/')
109
- headers = {referer: referer, remote_user: context.user}
110
- verb = CONVERT[method]
111
- uri = "http://#{host}/#{path}/#{resource}"
112
- uri += "/#{id}" if [:update,:read,:delete].include?( method )
113
- uri += q
114
- body = [:create,:update].include?(method) ? context.body : nil
115
- $stderr.puts "#{verb.upcase}: Forward Request to #{uri}"
116
- RL.request verb, uri, headers, body
117
- end
118
29
  end