stoor 0.1.3 → 0.1.4

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/README.md CHANGED
@@ -128,8 +128,8 @@ Then in `/etc/apache2/httpd.conf`:
128
128
  SetEnv STOOR_EXPIRE_AFTER 60
129
129
  SetEnv WIKI_PATH /Users/jgn/Dropbox/wiki
130
130
  ServerName wiki.local
131
- DocumentRoot "/opt/boxen/rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/stoor-0.0.1/public"
132
- <Directory "/opt/boxen/rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/stoor-0.0.1/public">
131
+ DocumentRoot "/opt/boxen/rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/stoor-0.1.4/public"
132
+ <Directory "/opt/boxen/rbenv/versions/1.9.2-p320/lib/ruby/gems/1.9.1/gems/stoor-0.1.4/public">
133
133
  Allow from all
134
134
  Options -MultiViews
135
135
  </Directory>
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ desc 'Default: run the specs.'
4
+ task :default => [:spec]
5
+
6
+ desc 'Test the stoor gem.'
7
+ RSpec::Core::RakeTask.new(:spec) do |t|
8
+ t.rspec_opts = ['--color', "--format progress"]
9
+ t.pattern = 'spec/**/*_spec.rb'
10
+ end
data/config.ru CHANGED
@@ -45,7 +45,9 @@ use Rack::Session::Cookie, :domain => domain, :key => 'rack.session', :secret =>
45
45
  use Stoor::GithubAuth
46
46
  use Stoor::GitConfig
47
47
  use Stoor::Decorate
48
- use Stoor::FixCssWidth if ENV['STOOR_WIDE']
48
+ if ENV['STOOR_WIDE']
49
+ use Stoor::AddAfter, /<body>/, '<style type="text/css">#wiki-wrapper { width: 90%; } .markdown-body table { width: 100%; }</style>'
50
+ end
49
51
 
50
52
  Precious::App.set(:gollum_path, wiki_path)
51
53
  Precious::App.set(:default_markup, :markdown)
@@ -0,0 +1,44 @@
1
+ require 'rack'
2
+
3
+ module Stoor
4
+ class AddAfter
5
+ include Rack::Utils
6
+
7
+ attr_reader :status, :headers
8
+ attr_reader :rxp, :string, :content_type
9
+
10
+ def initialize(app, rxp, string, content_type = 'text/html')
11
+ @app, @rxp, @string, @content_type = app, rxp, string, content_type
12
+ end
13
+
14
+ def call(env)
15
+ @status, @headers, response = @app.call(env)
16
+ @headers = HeaderHash.new(@headers)
17
+
18
+ if has_body && not_encoded && headers['content-type'] &&
19
+ headers['content-type'].index(content_type)
20
+
21
+ content = Array(response).join('')
22
+
23
+ if content =~ rxp
24
+ pre, match, post = $`, $&, $'
25
+ new_body = pre + match + string + post
26
+ headers['Content-Length'] = new_body.bytesize.to_s
27
+ return [status, headers, [new_body]]
28
+ end
29
+ end
30
+
31
+ [status, headers, response]
32
+ end
33
+
34
+ private
35
+
36
+ def has_body
37
+ !STATUS_WITH_NO_ENTITY_BODY.include?(status)
38
+ end
39
+
40
+ def not_encoded
41
+ !headers['transfer-encoding']
42
+ end
43
+ end
44
+ end
data/lib/stoor/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Stoor
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
data/lib/stoor.rb CHANGED
@@ -2,7 +2,7 @@ require 'stoor/logger'
2
2
  require 'stoor/github_auth'
3
3
  require 'stoor/git_config'
4
4
  require 'stoor/decorate'
5
- require 'stoor/fix_css_width'
5
+ require 'stoor/add_after'
6
6
  require 'stoor/views/layout'
7
7
  require 'stoor/views/logout'
8
8
 
@@ -0,0 +1,99 @@
1
+ require 'stoor/add_after'
2
+ require 'spec_helper'
3
+
4
+ module Stoor
5
+
6
+ describe AddAfter, 'content-type matching' do
7
+
8
+ context 'default with text/plain response' do
9
+ let(:inner_app) { ->(env) { [200, { 'Content-Type' => 'text/plain' }, '<body>'] } }
10
+ let(:app) { AddAfter.new(inner_app, /<body>/, 'stuff') }
11
+
12
+ it "skips" do
13
+ get '/'
14
+ expect(last_response.body).to eq('<body>')
15
+ end
16
+ end
17
+
18
+ context 'default with text/html response' do
19
+ let(:inner_app) { ->(env) { [200, { 'Content-Type' => 'text/html' }, '<body>'] } }
20
+ let(:app) { AddAfter.new(inner_app, /<body>/, 'stuff') }
21
+
22
+ it "processes" do
23
+ get '/'
24
+ expect(last_response.body).to eq('<body>stuff')
25
+ end
26
+ end
27
+
28
+ context 'specifying text/plain with text/html response' do
29
+ let(:inner_app) { ->(env) { [200, { 'Content-Type' => 'text/html' }, '<body>'] } }
30
+ let(:app) { AddAfter.new(inner_app, /<body>/, 'stuff', 'text/plain') }
31
+
32
+ it "skips" do
33
+ get '/'
34
+ expect(last_response.body).to eq('<body>')
35
+ end
36
+ end
37
+
38
+ context 'specifying regexp with text/html response' do
39
+ let(:inner_app) { ->(env) { [200, { 'Content-Type' => 'text/whatever' }, '<body>'] } }
40
+ let(:app) { AddAfter.new(inner_app, /<body>/, 'stuff', /\Atext\//) }
41
+
42
+ it "processes" do
43
+ get '/'
44
+ expect(last_response.body).to eq('<body>stuff')
45
+ end
46
+ end
47
+
48
+ end
49
+
50
+ describe AddAfter, 'insertion' do
51
+ let(:inner_app) { ->(env) { [200, { 'Content-Type' => 'text/html' }, '<body>'] } }
52
+ let(:app) { AddAfter.new(inner_app, /<body>/, 'stuff') }
53
+
54
+ it 'adds text after the first occurrence of a search string' do
55
+ get '/'
56
+ expect(last_response.body).to eq('<body>stuff')
57
+ end
58
+ end
59
+
60
+ describe AddAfter, 'insertion with two potential matches' do
61
+ let(:inner_app) { ->(env) { [200, { 'Content-Type' => 'text/html' }, '<body> <body>'] } }
62
+ let(:app) { AddAfter.new(inner_app, /<body>/, 'stuff') }
63
+
64
+ it 'adds text only after the first occurrence of a search string' do
65
+ get '/'
66
+ expect(last_response.body).to eq('<body>stuff <body>')
67
+ end
68
+ end
69
+
70
+ describe AddAfter, 'insertion if response is an Array' do
71
+ let(:inner_app) { ->(env) { [200, { 'Content-Type' => 'text/html' }, [ '<bo', 'dy>' ] ] } }
72
+ let(:app) { AddAfter.new(inner_app, /<body>/, 'stuff') }
73
+
74
+ it 'adds text after the first occurrence of a search string' do
75
+ get '/'
76
+ expect(last_response.body).to eq('<body>stuff')
77
+ end
78
+ end
79
+
80
+ describe AddAfter, 'status code implies no body' do
81
+ let(:inner_app) { ->(env) { [204, { 'Content-Type' => 'text/html' }, '<body>' ] } }
82
+ let(:app) { AddAfter.new(inner_app, /<body>/, 'stuff') }
83
+
84
+ it 'skips' do
85
+ get '/'
86
+ expect(last_response.body).to eq('<body>')
87
+ end
88
+ end
89
+
90
+ describe AddAfter, 'response is transfer-encoded' do
91
+ let(:inner_app) { ->(env) { [200, { 'Transfer-Encoding' => 'Chunked', 'Content-Type' => 'text/html' }, '<body>' ] } }
92
+ let(:app) { AddAfter.new(inner_app, /<body>/, 'stuff') }
93
+
94
+ it 'skips' do
95
+ get '/'
96
+ expect(last_response.body).to eq('<body>')
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,5 @@
1
+ require 'rack/test'
2
+
3
+ RSpec.configure do |conf|
4
+ conf.include Rack::Test::Methods
5
+ end
data/stoor.gemspec CHANGED
@@ -19,4 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.add_dependency 'sinatra_auth_github', '~> 1.0.0'
20
20
  s.add_dependency 'json', '~> 1.8.0'
21
21
  s.executables << 'stoor'
22
+
23
+ s.add_development_dependency 'rack-test'
24
+ s.add_development_dependency 'rspec'
22
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stoor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-25 00:00:00.000000000 Z
12
+ date: 2013-09-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thin
@@ -75,6 +75,38 @@ dependencies:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
77
  version: 1.8.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: rack-test
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
78
110
  description: Front-end for Gollum
79
111
  email: john@7fff.com
80
112
  executables:
@@ -85,11 +117,12 @@ files:
85
117
  - .gitignore
86
118
  - Gemfile
87
119
  - README.md
120
+ - Rakefile
88
121
  - bin/stoor
89
122
  - config.ru
90
123
  - lib/stoor.rb
124
+ - lib/stoor/add_after.rb
91
125
  - lib/stoor/decorate.rb
92
- - lib/stoor/fix_css_width.rb
93
126
  - lib/stoor/git_config.rb
94
127
  - lib/stoor/github_auth.rb
95
128
  - lib/stoor/logger.rb
@@ -99,6 +132,8 @@ files:
99
132
  - lib/stoor/views/logout.rb
100
133
  - log/.gitignore
101
134
  - public/.gitignore
135
+ - spec/lib/stoor/add_after_spec.rb
136
+ - spec/spec_helper.rb
102
137
  - stoor.gemspec
103
138
  homepage: https://rubygems.org/gems/stoor
104
139
  licenses: []
@@ -125,4 +160,6 @@ rubygems_version: 1.8.23
125
160
  signing_key:
126
161
  specification_version: 3
127
162
  summary: Front-end for Gollum
128
- test_files: []
163
+ test_files:
164
+ - spec/lib/stoor/add_after_spec.rb
165
+ - spec/spec_helper.rb
@@ -1,35 +0,0 @@
1
- module Stoor
2
- class FixCssWidth
3
- include Rack::Utils
4
-
5
- ADDITIONAL_STYLES = '<style type="text/css">#wiki-wrapper { width: 90%; } .markdown-body table { width: 100%; }</style>'
6
-
7
- def initialize(app); @app = app; end
8
-
9
- def call(env)
10
- @request = Rack::Request.new(env)
11
-
12
- status, headers, response = @app.call(env)
13
- headers = HeaderHash.new(headers)
14
-
15
- if !STATUS_WITH_NO_ENTITY_BODY.include?(status) &&
16
- !headers['transfer-encoding'] &&
17
- headers['content-type'] &&
18
- headers['content-type'].include?("text/html")
19
-
20
- # TODO: If the response isn't an Array, it's a Rack::File or something, so ignore
21
- if response.respond_to? :inject
22
- content = response.inject("") { |content, part| content << part }
23
- if content =~ /<body>/
24
- pre, match, post = $`, $&, $'
25
- new_body = pre + match + ADDITIONAL_STYLES + post
26
- headers['Content-Length'] = new_body.bytesize.to_s
27
- return [status, headers, [new_body]]
28
- end
29
- end
30
- end
31
-
32
- [status, headers, response]
33
- end
34
- end
35
- end