wire-framework 0.1.5.8 → 0.1.5.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d79aa2208acd914eb50a86bd6f577a9144509e0
4
- data.tar.gz: 1bd6db517477eabc4f522dbf1322198664109ac4
3
+ metadata.gz: 2858d57db2bf499296459695b344266fc2ec03ad
4
+ data.tar.gz: 0d07178f4f4af3365e42b41b963d618e7eed237e
5
5
  SHA512:
6
- metadata.gz: ff82b680ab9e22972050943e833bac2be76010fd0a6446c2912e84c7e6619acefcc8738d5776f72e9ff3fcdd49dffe309667582d1c86fbfb997b76c1200cc3ac
7
- data.tar.gz: 2e23a270bbdb9de4f1e5ecc1ed81b53ee826d3d3a1fc2e1b8afd722fdcee452ff15602d7f48a22b47633aa5250aa0bee6e9a18688d053ed71b7f4469e6909e92
6
+ metadata.gz: 7f9ddc12f09de5f0826b5c1484a00ebad077bbe01651aa068b98907675c9f05626737cba9168b00a0d59eebd3aa84a4653e13eaea516c14b818acc102f213c60
7
+ data.tar.gz: 23aca561ecc20cc1d9473500d0b22c97f1b6450a54ff34948c7e43325439d40127e6dfdcd134003292e876ba17789629ef9844383816360c1a1f57a018bb54e2
data/lib/app.rb CHANGED
@@ -35,7 +35,7 @@ module Wire
35
35
  conf
36
36
  end
37
37
 
38
- # Read all of the configs in './configs/apps'
38
+ # Read all of the configs in './config/apps'
39
39
  # @return [void]
40
40
  def self.read_configs
41
41
  Wire::Config.read_config_dir('config/apps', method(:configure))
data/lib/app/db.rb CHANGED
@@ -21,7 +21,7 @@ require 'sequel'
21
21
  # @author Bryan T. Meyers
22
22
  module DB
23
23
 
24
- # DB-specific configuration
24
+ # Model-specific configuration
25
25
  # @param [Hash] conf the existing configuration
26
26
  # @return [Hash] post-processed configuration
27
27
  def self.configure(conf)
@@ -31,6 +31,24 @@ module DB
31
31
  conf
32
32
  end
33
33
 
34
+ # DB-specific configuration
35
+ # @param [Hash] conf the existing configuration
36
+ # @return [Hash] post-processed configuration
37
+ def self.init_db(conf)
38
+ config = {}
39
+ conf.each do |k,v|
40
+ config[k.to_sym] = v
41
+ end
42
+ config['db'] = Sequel.connect(config)
43
+ config
44
+ end
45
+
46
+ # Read all of the configs in './configs/dbs'
47
+ # @return [void]
48
+ def self.read_configs
49
+ Wire::Config.read_config_dir('config/dbs', method(:init_db))
50
+ end
51
+
34
52
  # Add a new object to the DB table
35
53
  # @param [Hash] context the context for this request
36
54
  # @return [Response] a valid Rack response triplet, or status code
data/lib/app/history.rb CHANGED
@@ -24,7 +24,7 @@ module History
24
24
  # Configure this History with a log template
25
25
  # @param [Hash] conf the raw configuration
26
26
  # @return [Hash] post-processed configuration
27
- def self.configure(conf)
27
+ def configure(conf)
28
28
  conf['log'] = Tilt.new(conf['log'], 1, { ugly: true })
29
29
  conf
30
30
  end
@@ -33,11 +33,8 @@ module History
33
33
  # @param [Hash] context the context for this request
34
34
  # @return [Response] the history, or status code
35
35
  def do_read(actions, context)
36
- list = get_log(context.config['host'],
36
+ list = get_log(context.closet.repos[context.config['repo']],
37
37
  context.resource,
38
- context.config['user'],
39
- context.config['pass'],
40
- context.config['web_folder'],
41
38
  context.id)
42
39
  if list == 404
43
40
  return 404
@@ -24,19 +24,16 @@ module History
24
24
  extend History
25
25
 
26
26
  # Get the log information for any part of a Repo
27
- # @param [String] host the name of the host to connect to
27
+ # @param [Hash] conf the repo config
28
28
  # @param [String] repo the name of the repository to access
29
- # @param [String] user the username for connecting to SVN
30
- # @param [String] pass the password for connecting to SVN
31
- # @param [String] web the web path of the repo
32
29
  # @param [String] id the sub-URI of the item to access
33
30
  # @return [Hash] the history entries
34
- def self.get_log(host, repo, user, pass, web, id = nil)
35
- options = "--username #{user} --password #{pass}"
36
- uri = "svn://#{host}/#{repo}"
31
+ def self.get_log(conf, repo, id = nil)
32
+ options = "--username #{conf['user']} --password #{conf['password']}"
33
+ uri = "#{conf['protocol']}://#{conf['host']}/#{repo}"
37
34
  if id
38
- if web
39
- uri += "/#{web}"
35
+ if conf['web_folder']
36
+ uri += "/#{conf['web_folder']}"
40
37
  end
41
38
  uri += "/#{id}"
42
39
  end
data/lib/app/login.rb CHANGED
@@ -23,7 +23,7 @@ module Login
23
23
  # @param [Hash] context the context for this request
24
24
  # @return [Response] a redirect message returning to the previous page
25
25
  def self.invoke(actions, context)
26
- [307, {'Location' => context.referer.join('/')}, ['Login Redirect']]
26
+ [307, { 'Location' => context.referer.join('/') }, ['Login Redirect']]
27
27
  end
28
28
 
29
29
  end
@@ -30,10 +30,10 @@ module Render
30
30
  renderer = context.closet.renderers[mime]
31
31
  if renderer
32
32
  template = renderer['partial']
33
- template.render(self, {actions: actions,
34
- context: context,
35
- mime: mime,
36
- response: response[2]})
33
+ template.render(self, { actions: actions,
34
+ context: context,
35
+ mime: mime,
36
+ response: response[2] })
37
37
  else
38
38
  response
39
39
  end
@@ -42,11 +42,11 @@ module Render
42
42
  end
43
43
  end
44
44
  if template
45
- template.render(self, {actions: actions,
46
- resource: context.resource,
47
- id: context.id,
48
- mime: mime,
49
- response: body})
45
+ template.render(self, { actions: actions,
46
+ resource: context.resource,
47
+ id: context.id,
48
+ mime: mime,
49
+ response: body })
50
50
  else
51
51
  body
52
52
  end
@@ -24,7 +24,7 @@ module Render
24
24
  # @return [Hash] post-processed configuration
25
25
  def self.configure(conf)
26
26
  conf['errors'].each do |k, v|
27
- conf['errors'][k] = Tilt.new(v, 1, {ugly: true})
27
+ conf['errors'][k] = Tilt.new(v, 1, { ugly: true })
28
28
  end
29
29
  conf
30
30
  end
@@ -34,9 +34,9 @@ module Render
34
34
  if errors
35
35
  template = errors[result[0]]
36
36
  if template
37
- result[2] = template.render(self, {actions: actions,
38
- context: context,
39
- result: result})
37
+ result[2] = template.render(self, { actions: actions,
38
+ context: context,
39
+ result: result })
40
40
  end
41
41
  end
42
42
  result
@@ -41,16 +41,16 @@ module Render
41
41
  renderer = context.closet.renderers["#{context.resource}/#{context.id}"]
42
42
  if renderer
43
43
  template = context.closet.templates[renderer]
44
- result = template.render(self, {actions: actions,
45
- context: context,
46
- mime: "#{context.resource}/#{context.id}",
47
- response: body, })
44
+ result = template.render(self, { actions: actions,
45
+ context: context,
46
+ mime: "#{context.resource}/#{context.id}",
47
+ response: body, })
48
48
  name = context.config['template']
49
49
  template = context.closet.templates[name]
50
50
  if template
51
- message = template['file'].render(self, {actions: actions,
52
- context: context,
53
- content: result})
51
+ message = template['file'].render(self, { actions: actions,
52
+ context: context,
53
+ content: result })
54
54
  else
55
55
  message = result
56
56
  end
@@ -27,7 +27,7 @@ module Render
27
27
  # @return [Response] a Rack Response triplet, or status code
28
28
  def self.render_template(actions, context, template, content)
29
29
  if template['file']
30
- hash = {actions: actions, context: context, content: content}
30
+ hash = { actions: actions, context: context, content: content }
31
31
  if template['sources']
32
32
  template['sources'].each do |k, s|
33
33
  uri = "http://#{context.config['remote'].split('/')[0]}"
@@ -49,7 +49,7 @@ module Render
49
49
  end
50
50
  temp = []
51
51
  if go_ahead
52
- temp = RL.request(:get, uri, {remote_user: context.user})
52
+ temp = RL.request(:get, uri, { remote_user: context.user })
53
53
  end
54
54
  if temp[0] == 200
55
55
  begin
@@ -28,10 +28,10 @@ module Render
28
28
  def self.configure(conf)
29
29
  conf['resources'].each do |k, v|
30
30
  if v.is_a? Hash
31
- conf['resources'][k]['multiple'] = Tilt.new(v['multiple'], 1, {ugly: true})
32
- conf['resources'][k]['single'] = Tilt.new(v['single'], 1, {ugly: true})
31
+ conf['resources'][k]['multiple'] = Tilt.new(v['multiple'], 1, { ugly: true })
32
+ conf['resources'][k]['single'] = Tilt.new(v['single'], 1, { ugly: true })
33
33
  elsif v.is_a? String
34
- conf['resources'][k] = {'all' => Tilt.new(v, 1, {ugly: true})}
34
+ conf['resources'][k] = { 'all' => Tilt.new(v, 1, { ugly: true }) }
35
35
  end
36
36
  end
37
37
  conf
@@ -57,15 +57,15 @@ module Render
57
57
  template = resource['multiple']
58
58
  end
59
59
  if template
60
- hash = {actions: actions,
61
- resource: resource,
62
- mime: mime,
63
- response: body}
60
+ hash = { actions: actions,
61
+ resource: resource,
62
+ mime: mime,
63
+ response: body }
64
64
  if resource['extras']
65
65
  resource['extras'].each do |k, v|
66
66
  temp = RL.request(:get,
67
67
  "http://#{context.config['remote'].split('/')[0]}/#{v}",
68
- {remote_user: context.user}
68
+ { remote_user: context.user }
69
69
  )[2]
70
70
  begin
71
71
  hash[k.to_sym] = JSON.parse_clean(temp)
@@ -78,7 +78,7 @@ module Render
78
78
  mime = 'text/html'
79
79
  body = template.render(self, hash)
80
80
  end
81
- [200, {'Content-Type' => mime}, body]
81
+ [200, { 'Content-Type' => mime }, body]
82
82
  end
83
83
 
84
84
  # Read a Partial and render it to HTML
@@ -102,12 +102,12 @@ module Render
102
102
  template = resource['single']
103
103
  end
104
104
  if template
105
- hash = {actions: actions,
106
- app: context.app,
107
- resource: context.resource,
108
- id: context.id,
109
- mime: mime,
110
- response: body}
105
+ hash = { actions: actions,
106
+ app: context.app,
107
+ resource: context.resource,
108
+ id: context.id,
109
+ mime: mime,
110
+ response: body }
111
111
  if resource['extras']
112
112
  resource['extras'].each do |k, v|
113
113
  temp = RL.request(:get, "http://#{context.config['remote'].split('/')[0]}/#{v}")[2]
@@ -121,7 +121,7 @@ module Render
121
121
  mime = 'text/html'
122
122
  body = template.render(self, hash)
123
123
  end
124
- [200, {'Content-Type' => mime}, body]
124
+ [200, { 'Content-Type' => mime }, body]
125
125
  end
126
126
 
127
127
  # Proxy method used when routing
@@ -26,7 +26,7 @@ module Render
26
26
  # @return [Hash] post-processed configuration
27
27
  def self.configure(conf)
28
28
  conf['styles'].each do |k, v|
29
- conf['styles'][k] = Tilt.new(v, 1, {ugly: true}).render
29
+ conf['styles'][k] = Tilt.new(v, 1, { ugly: true }).render
30
30
  end
31
31
  conf
32
32
  end
@@ -36,7 +36,7 @@ module Render
36
36
  # @return [Response] a Rack Response triplet, or status code
37
37
  def self.do_read_all(context)
38
38
  template = context.config['styles'][context.resource]
39
- headers = {'Cache-Control' => 'public,max-age=3600'}
39
+ headers = { 'Cache-Control' => 'public,max-age=3600' }
40
40
  if template
41
41
  headers['Content-Type'] = 'text/css'
42
42
  [200, headers, [template]]
data/lib/app/repo.rb CHANGED
@@ -25,25 +25,36 @@ module Repo
25
25
  # Configure repo with listing template
26
26
  # @param [Hash] conf the raw configuration
27
27
  # @return [Hash] post-processed configuration
28
- def self.configure(conf)
28
+ def configure(conf)
29
29
  conf['listing'] = Tilt.new(conf['listing'], 1, { ugly: true })
30
30
  conf
31
31
  end
32
32
 
33
- # Create a new Repo
33
+ # Read all of the configs in './configs/repos'
34
+ # @return [void]
35
+ def self.read_configs
36
+ Wire::Config.read_config_dir('config/repos', nil)
37
+ end
38
+
39
+ # Create a new file
34
40
  # @param [Hash] context the context for this request
35
41
  # @return [Response] status code
36
42
  def do_create(context)
37
- path = context.config['repos']
38
- resource = context.resource
39
- if path
40
- if Dir.exist?("#{path}/#{resource}")
41
- 401
43
+ conf = context.closet.repos[context.config['repo']]
44
+ repo = context.resource
45
+ content = context.json
46
+ id = context.id
47
+ if content[:file]
48
+ file = content[:file][:content].match(/base64,(.*)/)[1]
49
+ file = Base64.decode64(file)
50
+ if context.query[:type]
51
+ mime = context.query[:type]
42
52
  else
43
- do_create_file(path, resource)
53
+ mime = content[:file][:mime]
44
54
  end
55
+ do_create_file(conf, repo, id, file, content[:message], mime, context.user)
45
56
  else
46
- 400
57
+ do_create_file(conf, repo, id, URI.unescape(content[:updated]), content[:message], context.query[:type], context.user)
47
58
  end
48
59
  end
49
60
 
@@ -51,12 +62,9 @@ module Repo
51
62
  # @param [Hash] context the context for this request
52
63
  # @return [Response] the listing, or status code
53
64
  def do_read_all(context)
65
+ conf = context.closet.repos[context.config['repo']]
54
66
  mime = 'text/html'
55
- list = do_read_listing(context.config['web'],
56
- context.config['user'],
57
- context.config['pass'],
58
- context.config['repos'],
59
- context.resource)
67
+ list = do_read_listing(conf, context.resource)
60
68
  if list == 404
61
69
  return 404
62
70
  end
@@ -76,22 +84,19 @@ module Repo
76
84
  # @param [Hash] context the context for this request
77
85
  # @return [Response] the file, listing, or status code
78
86
  def do_read(context)
79
- user = context.config['user']
80
- pass = context.config['pass']
81
- repo = context.resource
87
+ conf = context.closet.repos[context.config['repo']]
82
88
  referrer = context.referer
83
- path = context.config['repos']
84
- web = context.config['web']
85
- rev = context.query[:rev]
89
+ repo = context.resource
86
90
  id = context.id
87
- info = do_read_info(rev, web, user, pass, path, repo, id)
91
+ rev = context.query[:rev]
92
+ info = do_read_info(conf, repo, id, rev)
88
93
  if info == 404
89
94
  return 404
90
95
  end
91
96
  type = info[:@kind]
92
97
  if type.eql? 'dir'
93
98
  mime = 'text/html'
94
- list = do_read_listing(web, user, pass, path, repo, id)
99
+ list = do_read_listing(conf, repo, id)
95
100
  template = context.config['listing']
96
101
  body = template.render(self,
97
102
  list: list,
@@ -99,11 +104,11 @@ module Repo
99
104
  id: id,
100
105
  referrer: referrer)
101
106
  else
102
- body = do_read_file(rev, web, user, pass, path, repo, id)
107
+ body = do_read_file(conf, repo, id, rev)
103
108
  if body == 500
104
109
  return body
105
110
  end
106
- mime = do_read_mime(rev, web, user, pass, path, repo, id)
111
+ mime = do_read_mime(conf, repo, id, rev)
107
112
  end
108
113
  headers = { 'Content-Type' => mime,
109
114
  'Cache-Control' => 'public',
@@ -115,11 +120,8 @@ module Repo
115
120
  # @param [Hash] context the context for this request
116
121
  # @return [Response] status code
117
122
  def do_update(context)
118
- user = context.config['user']
119
- pass = context.config['pass']
123
+ conf = context.closet.repos[context.config['repo']]
120
124
  repo = context.resource
121
- path = context.config['repos']
122
- web = context.config['web']
123
125
  content = context.json
124
126
  id = context.id
125
127
  if content[:file]
@@ -130,9 +132,9 @@ module Repo
130
132
  else
131
133
  mime = content[:file][:mime]
132
134
  end
133
- do_update_file(web, user, pass, path, repo, id, file, content[:message], mime, context.user)
135
+ do_update_file(conf, repo, id, file, content[:message], mime, context.user)
134
136
  else
135
- do_update_file(web, user, pass, path, repo, id, URI.unescape(content[:updated]), content[:message], context.query[:type], context.user)
137
+ do_update_file(conf, repo, id, URI.unescape(content[:updated]), content[:message], context.query[:type], context.user)
136
138
  end
137
139
  end
138
140
 
data/lib/app/repo/svn.rb CHANGED
@@ -27,37 +27,21 @@ module Repo
27
27
  # Force Nori to convert tag names to Symbols
28
28
  @@nori = Nori.new :convert_tags_to => lambda { |tag| tag.snakecase.to_sym }
29
29
 
30
- # Make a new SVN repo
31
- # @param [String] path the path to the repositories
32
- # @param [String] repo the new repo name
33
- # @return [Integer] status code
34
- def self.do_create_file(path, repo)
35
- `svnadmin create #{path}/#{repo}`
36
- if $?.exitstatus != 0
37
- 500
38
- else
39
- 200
40
- end
41
- end
42
-
43
30
  # Read a single file
44
- # @param [String] rev the revision number to access
45
- # @param [String] web the subdirectory for web content
46
- # @param [String] user the username for connecting to SVN
47
- # @param [String] pass the password for connecting to SVN
48
- # @param [String] path the path to the repositories
31
+ # @param [String] conf the repo config
49
32
  # @param [String] repo the new repo name
50
33
  # @param [String] id the relative path to the file
34
+ # @param [String] rev the revision number to access
51
35
  # @return [String] the file
52
- def self.do_read_file(rev, web, user, pass, path, repo, id)
53
- options = "--username #{user} --password #{pass}"
36
+ def self.do_read_file(conf, repo, id, rev)
37
+ options = "--username #{conf['user']} --password #{conf['password']}"
54
38
  if rev.nil?
55
39
  rev = 'HEAD'
56
40
  end
57
- if web.nil?
58
- body = `svn cat #{options} -r #{rev} 'svn://localhost/#{repo}/#{id}'`
41
+ if conf['web_folder'].nil?
42
+ body = `svn cat #{options} -r #{rev} '#{conf['protocol']}://#{conf['host']}/#{repo}/#{id}'`
59
43
  else
60
- body = `svn cat #{options} -r #{rev} 'svn://localhost/#{repo}/#{web}/#{id}'`
44
+ body = `svn cat #{options} -r #{rev} '#{conf['protocol']}://#{conf['host']}/#{repo}/#{conf['web_folder']}/#{id}'`
61
45
  end
62
46
 
63
47
  if $?.success?
@@ -68,26 +52,23 @@ module Repo
68
52
  end
69
53
 
70
54
  # Read a directory listing
71
- # @param [String] web the subdirectory for web content
72
- # @param [String] user the username for connecting to SVN
73
- # @param [String] pass the password for connecting to SVN
74
- # @param [String] path the path to the repositories
75
- # @param [String] repo the new repo name
55
+ # @param [String] conf the repo config
56
+ # @param [String] repo the repo name
76
57
  # @param [String] id the relative path to the file
77
58
  # @return [Array] the directory listing
78
- def self.do_read_listing(web, user, pass, path, repo, id = nil)
79
- options = "--username #{user} --password #{pass}"
80
- if web.nil?
59
+ def self.do_read_listing(conf, repo, id = nil)
60
+ options = "--username #{conf['user']} --password #{conf['password']}"
61
+ if conf['web_folder'].nil?
81
62
  if id.nil?
82
- list = `svn list #{options} --xml 'svn://localhost/#{repo}'`
63
+ list = `svn list #{options} --xml '#{conf['protocol']}://#{conf['host']}/#{repo}'`
83
64
  else
84
- list = `svn list #{options} --xml 'svn://localhost/#{repo}/#{id}'`
65
+ list = `svn list #{options} --xml '#{conf['protocol']}://#{conf['host']}/#{repo}/#{id}'`
85
66
  end
86
67
  else
87
68
  if id.nil?
88
- list = `svn list #{options} --xml 'svn://localhost/#{repo}/#{web}'`
69
+ list = `svn list #{options} --xml '#{conf['protocol']}://#{conf['host']}/#{repo}/#{conf['web_folder']}'`
89
70
  else
90
- list = `svn list #{options} --xml 'svn://localhost/#{repo}/#{web}/#{id}'`
71
+ list = `svn list #{options} --xml '#{conf['protocol']}://#{conf['host']}/#{repo}/#{conf['web_folder']}/#{id}'`
91
72
  end
92
73
  end
93
74
  unless $?.exitstatus == 0
@@ -98,23 +79,20 @@ module Repo
98
79
  end
99
80
 
100
81
  # Read Metadata for a single file
101
- # @param [String] rev the revision number to access
102
- # @param [String] web the subdirectory for web content
103
- # @param [String] user the username for connecting to SVN
104
- # @param [String] pass the password for connecting to SVN
105
- # @param [String] path the path to the repositories
82
+ # @param [String] conf the repo config
106
83
  # @param [String] repo the new repo name
107
84
  # @param [String] id the relative path to the file
85
+ # @param [String] rev the revision number to access
108
86
  # @return [Hash] the metadata
109
- def self.do_read_info(rev, web, user, pass, path, repo, id)
110
- options = "--username #{user} --password #{pass}"
87
+ def self.do_read_info(conf, repo, id, rev)
88
+ options = "--username #{conf['user']} --password #{conf['password']}"
111
89
  if rev.nil?
112
90
  rev = 'HEAD'
113
91
  end
114
- if web.nil?
115
- info = `svn info #{options} -r #{rev} --xml 'svn://localhost/#{repo}/#{id}'`
92
+ if conf['web_folder'].nil?
93
+ info = `svn info #{options} -r #{rev} --xml '#{conf['protocol']}://#{conf['host']}/#{repo}/#{id}'`
116
94
  else
117
- info = `svn info #{options} -r #{rev} --xml 'svn://localhost/#{repo}/#{web}/#{id}'`
95
+ info = `svn info #{options} -r #{rev} --xml '#{conf['protocol']}://#{conf['host']}/#{repo}/#{conf['web_folder']}/#{id}'`
118
96
  end
119
97
 
120
98
  unless $?.exitstatus == 0
@@ -125,23 +103,20 @@ module Repo
125
103
  end
126
104
 
127
105
  # Get a file's MIME type
128
- # @param [String] rev the revision number to access
129
- # @param [String] web the subdirectory for web content
130
- # @param [String] user the username for connecting to SVN
131
- # @param [String] pass the password for connecting to SVN
132
- # @param [String] path the path to the repositories
106
+ # @param [String] conf the repo config
133
107
  # @param [String] repo the new repo name
134
108
  # @param [String] id the relative path to the file
109
+ # @param [String] rev the revision number to access
135
110
  # @return [String] the MIME type
136
- def self.do_read_mime(rev, web, user, pass, path, repo, id)
137
- options = "--username #{user} --password #{pass}"
111
+ def self.do_read_mime(conf, repo, id, rev)
112
+ options = "--username #{conf['user']} --password #{conf['password']}"
138
113
  if rev.nil?
139
114
  rev = 'HEAD'
140
115
  end
141
- if web.nil?
142
- mime = `svn propget #{options} -r #{rev} --xml svn:mime-type 'svn://localhost/#{repo}/#{id}'`
116
+ if conf['web_folder'].nil?
117
+ mime = `svn propget #{options} -r #{rev} --xml svn:mime-type '#{conf['protocol']}://#{conf['host']}/#{repo}/#{id}'`
143
118
  else
144
- mime = `svn propget #{options} -r #{rev} --xml svn:mime-type 'svn://localhost/#{repo}/#{web}/#{id}'`
119
+ mime = `svn propget #{options} -r #{rev} --xml svn:mime-type '#{conf['protocol']}://#{conf['host']}/#{repo}/#{conf['web_folder']}/#{id}'`
145
120
  end
146
121
  unless $?.success?
147
122
  return 500
@@ -154,11 +129,8 @@ module Repo
154
129
  end
155
130
  end
156
131
 
157
- # Update a single file
158
- # @param [String] web the subdirectory for web content
159
- # @param [String] user the username for connecting to SVN
160
- # @param [String] pass the password for connecting to SVN
161
- # @param [String] path the path to the repositories
132
+ # Update or create a single file
133
+ # @param [String] conf the repo config
162
134
  # @param [String] repo the new repo name
163
135
  # @param [String] id the relative path to the file
164
136
  # @param [String] content the updated file
@@ -166,50 +138,56 @@ module Repo
166
138
  # @param [String] mime the mime-type to set
167
139
  # @param [String] username the Author of this change
168
140
  # @return [Integer] status code
169
- def self.do_update_file(web, user, pass, path, repo, id, content, message, mime, username)
170
- options = "--username #{user} --password #{pass}"
141
+ def self.do_update_file(conf, repo, id, content, message, mime, username)
142
+ options = "--depth empty --username #{conf['user']} --password #{conf['password']}"
171
143
  status = 500
172
- id = id.split('/')
173
- id.pop
174
- id = id.join('/')
175
- if web.nil?
176
- repo_path = "/tmp/svn/#{repo}/#{id}"
177
- else
178
- repo_path = "/tmp/svn/#{repo}/#{web}/#{id}"
179
- end
144
+ repo_path = "/tmp/#{username}/#{repo}"
180
145
  unless Dir.exist? repo_path
181
146
  FileUtils.mkdir_p(repo_path)
182
147
  end
183
148
 
184
- `svn checkout #{options} 'svn://localhost/#{repo}' '/tmp/svn/#{repo}'`
185
- id = CGI.unescape(id)
149
+ `svn checkout #{options} '#{conf['protocol']}://#{conf['host']}/#{repo}' '#{repo_path}'`
150
+
186
151
  if $?.exitstatus == 0
187
- id = id.split('/')
188
- id.pop
189
- id = id.join('/')
190
- if web.nil?
191
- file_path = "/tmp/svn/#{repo}/#{id}"
192
- else
193
- file_path = "/tmp/svn/#{repo}/#{web}/#{id}"
152
+ file_path = CGI.unescape(id)
153
+ if conf['web_folder']
154
+ file_path = "#{conf['web_folder']}/#{file_path}"
194
155
  end
156
+ folder_path = file_path.split('/')
157
+ folder_path.pop
158
+ folder_path = folder_path.join('/')
195
159
 
196
- unless Dir.exist? file_path
197
- FileUtils.mkdir_p(file_path)
160
+ unless Dir.exist? folder_path
161
+ FileUtils.mkdir_p(folder_path)
198
162
  end
199
163
 
200
164
  file = File.open(file_path, 'w+')
201
165
  file.syswrite(content)
202
166
  file.close
203
- `svn add --force "/tmp/svn/#{repo}/*"`
167
+ `svn add --force "#{repo_path}/*"`
204
168
  `svn propset svn:mime-type "#{mime}" "#{file_path}"`
205
- `svn commit #{options} -m "#{message}" "/tmp/svn/#{repo}"`
169
+ `svn commit #{options} -m "#{message}" "#{repo_path}"`
206
170
  if $?.exitstatus == 0
207
171
  status = 200
208
172
  end
209
- `svn propset #{options} --revprop -r HEAD svn:author '#{username}' "/tmp/svn/#{repo}"`
173
+ `svn propset #{options} --revprop -r HEAD svn:author '#{username}' "#{repo_path}"`
210
174
  end
211
- `rm -R '/tmp/svn/#{repo}'`
175
+ `rm -R '#{repo_path}'`
212
176
  status
213
177
  end
178
+
179
+ # Create a single file
180
+ # @param [String] conf the repo config
181
+ # @param [String] repo the new repo name
182
+ # @param [String] id the relative path to the file
183
+ # @param [String] content the updated file
184
+ # @param [String] message the commit message
185
+ # @param [String] mime the mime-type to set
186
+ # @param [String] username the Author of this change
187
+ # @return [Integer] status code
188
+ def self.do_create_file(conf, repo, id, content, message, mime, username)
189
+ do_update_file(conf, repo, id, content, message, mime, username)
190
+ end
191
+
214
192
  end
215
193
  end
data/lib/closet.rb CHANGED
@@ -28,15 +28,41 @@ module Wire
28
28
  class Closet
29
29
  include Wire::Auth
30
30
 
31
- attr_accessor :apps, :editors, :renderers, :templates
31
+ attr_reader :apps, :editors, :renderers, :templates
32
+ attr_reader :dbs, :env, :repos, :mode
32
33
 
33
- # Create an empty Closet
34
+ # Create an empty Closet and connect to datasources.
34
35
  # @return [Wire::Closet] the new closet
35
36
  def initialize
36
- @apps = {}
37
- @editors = {}
38
- @renderers = {}
39
- @templates = {}
37
+ @mode = ENV['RACK_ENV']
38
+ if @mode.eql? 'development'
39
+ $stderr.puts 'Starting Up Wire...'
40
+ $stderr.puts 'Reading Environment Config...'
41
+ end
42
+ @env = Wire::Config.read_config_dir('./config/env', nil)[@mode]
43
+ if @mode.eql? 'development'
44
+ $stderr.puts 'Reading DB Configs...'
45
+ end
46
+ @dbs = Wire::DB.read_configs
47
+ if @mode.eql? 'development'
48
+ $stderr.puts 'Reading Repo Configs...'
49
+ end
50
+ @repos = Wire::Repo.read_configs
51
+ end
52
+
53
+ # Setup the closet
54
+ def build
55
+ if @mode.eql? 'development'
56
+ $stderr.puts 'Reading App Configs...'
57
+ end
58
+ @apps = Wire::App.read_configs
59
+ if @mode.eql? 'development'
60
+ $stderr.puts 'Reading [Editor|Renderer|Template] Configs...'
61
+ end
62
+ @editors, @renderers, @templates = Wire::Renderer.read_configs
63
+ if @mode.eql? 'development'
64
+ info
65
+ end
40
66
  end
41
67
 
42
68
  # Route a Request to the correct Wire::App
@@ -77,23 +103,6 @@ module Wire
77
103
  response
78
104
  end
79
105
 
80
- # A factory method for configuring a Closet
81
- # @param [Proc] block the configuration routine
82
- # @return [Wire::Closet] the configured Closet
83
- def self.build
84
- closet = Wire::Closet.new
85
- if ENV['RACK_ENV'].eql? 'development'
86
- $stderr.puts 'Starting Up Wire...'
87
- $stderr.puts 'Starting Apps...'
88
- end
89
- closet.apps = Wire::App.read_configs
90
- closet.editors, closet.renderers, closet.templates = Wire::Renderer.read_configs
91
- if ENV['RACK_ENV'].eql? 'development'
92
- closet.info
93
- end
94
- closet
95
- end
96
-
97
106
  # Print out a human-readable configuration
98
107
  # @return [void]
99
108
  def info
@@ -136,8 +136,8 @@ module Wire
136
136
  # @param [Symbol] method the action to use when forwarding
137
137
  # @return [Response] a Rack Response triplet, or status code
138
138
  def forward(method)
139
- headers = {referer: @referer.join('/'),
140
- remote_user: @user}
139
+ headers = { referer: @referer.join('/'),
140
+ remote_user: @user }
141
141
  verb = CONVERT[method]
142
142
  uri = "http://#{@config['remote']}/#{@resource}"
143
143
  if [:update, :read, :delete].include?(method)
@@ -26,7 +26,7 @@ module Wire
26
26
  # @param [Hash] conf the raw configuration
27
27
  # @return [Hash] post-processed configuration
28
28
  def self.configure_partial(conf)
29
- conf['partial'] = Tilt.new(conf['partial'], 1, {ugly: true})
29
+ conf['partial'] = Tilt.new(conf['partial'], 1, { ugly: true })
30
30
  conf
31
31
  end
32
32
 
@@ -34,11 +34,11 @@ module Wire
34
34
  # @param [Hash] conf the raw configuration
35
35
  # @return [Hash] post-processed configuration
36
36
  def self.configure_template(conf)
37
- conf['file'] = Tilt.new(conf['file'], 1, {ugly: true})
37
+ conf['file'] = Tilt.new(conf['file'], 1, { ugly: true })
38
38
  conf
39
39
  end
40
40
 
41
- # Read all of the configs in './configs/apps'
41
+ # Read all of the configs in './config/editors', './config/renderers', '.config/templates'
42
42
  # @return [void]
43
43
  def self.read_configs
44
44
  editors = Wire::Config.read_config_dir('config/editors', method(:configure_template))
data/lib/wire.rb CHANGED
@@ -33,7 +33,7 @@ end
33
33
  # @author Bryan T. Meyers
34
34
  module Wire
35
35
  # Current version of the Wire Gem
36
- VERSION = '0.1.5.8'
36
+ VERSION = '0.1.5.9'
37
37
  end
38
38
 
39
39
  require_relative 'app'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wire-framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5.8
4
+ version: 0.1.5.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan T. Meyers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-19 00:00:00.000000000 Z
11
+ date: 2017-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print