glog 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.markdown +42 -0
- data/spec/fixtures/example/plugins/canonical_host.rb +25 -0
- data/spec/fixtures/example/plugins/chrome_frame.rb +50 -0
- data/spec/fixtures/example/plugins/google_analytics.rb +45 -0
- data/spec/fixtures/example/plugins/no_ie.rb +38 -0
- data/spec/glog_spec.rb +82 -0
- data/spec/spec_helper.rb +18 -0
- metadata +124 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Antono Vasiljev
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
Glog - simplier than toto
|
2
|
+
=========================
|
3
|
+
|
4
|
+
Glog is Rack Middleware to serve directory of files as blog or site.
|
5
|
+
|
6
|
+
Glog inspired by [toto](http://github.com/cloudhead/toto) and based on
|
7
|
+
[JADOF](http://github.com/remi/jadof).
|
8
|
+
|
9
|
+
Glog makes less assumptions about your urls.
|
10
|
+
**J**ust **a** **D**irectory **o**f **F**iles.
|
11
|
+
|
12
|
+
|
13
|
+
TODO
|
14
|
+
|
15
|
+
|
16
|
+
Plugins
|
17
|
+
-------
|
18
|
+
|
19
|
+
Use rack middleware as plugins:
|
20
|
+
|
21
|
+
require 'rack/noie'
|
22
|
+
use Rack::NoIE, :redirect => '/noie.html'
|
23
|
+
|
24
|
+
require 'rack/google\_analytics'
|
25
|
+
use Rack::GoogleAnalytics, 'UA-1234567-0'
|
26
|
+
|
27
|
+
|
28
|
+
Note on Patches/Pull Requests
|
29
|
+
-----------------------------
|
30
|
+
|
31
|
+
- Fork the project.
|
32
|
+
- Make your feature addition or bug fix.
|
33
|
+
- Add tests for it. This is important so I don't break it in a
|
34
|
+
future version unintentionally.
|
35
|
+
- Commit, do not mess with rakefile, version, or history.
|
36
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
37
|
+
- Send me a pull request. Bonus points for topic branches.
|
38
|
+
|
39
|
+
Copyright
|
40
|
+
---------
|
41
|
+
|
42
|
+
Copyright (c) 2010 Antono Vasiljev. See LICENSE for details.
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# http://gist.github.com/206213
|
2
|
+
module Rack
|
3
|
+
class CanonicalHost
|
4
|
+
def initialize(app, host=nil, &block)
|
5
|
+
@app = app
|
6
|
+
@host = (block_given? && block.call) || host
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
if url = url(env)
|
11
|
+
[301, { 'Location' => url }, ['Redirecting...']]
|
12
|
+
else
|
13
|
+
@app.call(env)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def url(env)
|
18
|
+
if @host && env['SERVER_NAME'] != @host
|
19
|
+
url = Rack::Request.new(env).url
|
20
|
+
url.sub(%r{\A(https?://)(.*?)(:\d+)?(/|$)}, "\\1#{@host}\\3/")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
private :url
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# http://gist.github.com/206201
|
2
|
+
# http://coderack.org/users/luigi/entries/4-rackchromeframe
|
3
|
+
module Rack
|
4
|
+
class ChromeFrame
|
5
|
+
|
6
|
+
def initialize(app, options={})
|
7
|
+
@app = app
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
status, headers, response = @app.call(env)
|
12
|
+
if env['HTTP_USER_AGENT'] =~ /MSIE/ && response.content_type == 'text/html'
|
13
|
+
new_body = insert_goods(build_response_body(response))
|
14
|
+
new_headers = recalculate_body_length(headers, new_body)
|
15
|
+
[status, new_headers, new_body]
|
16
|
+
else
|
17
|
+
[status, headers, response]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def build_response_body(response)
|
22
|
+
response_body = ""
|
23
|
+
response.each { |part| response_body += part }
|
24
|
+
response_body
|
25
|
+
end
|
26
|
+
|
27
|
+
def recalculate_body_length(headers, body)
|
28
|
+
new_headers = headers
|
29
|
+
new_headers["Content-Length"] = body.length.to_s
|
30
|
+
new_headers
|
31
|
+
end
|
32
|
+
|
33
|
+
def insert_goods(body)
|
34
|
+
head = <<-HEAD
|
35
|
+
<meta http-equiv="X-UA-Compatible" content="chrome=1">
|
36
|
+
HEAD
|
37
|
+
|
38
|
+
bod = <<-BOD
|
39
|
+
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js"></script>
|
40
|
+
<div id="cf-placeholder"></div>
|
41
|
+
<script>CFInstall.check({node: "cf-placeholder"});</script>
|
42
|
+
BOD
|
43
|
+
|
44
|
+
body.gsub!(/<\/head>/, head + "\n</head>")
|
45
|
+
body.gsub!(/<\/body>/, bod + "\n</body>")
|
46
|
+
body
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# http://gist.github.com/207948
|
2
|
+
# http://coderack.org/users/sam/entries/21-rackgoogleanalytics
|
3
|
+
module Rack
|
4
|
+
class GoogleAnalytics
|
5
|
+
TRACKING_CODE = <<-EOCODE
|
6
|
+
<script type="text/javascript">
|
7
|
+
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
8
|
+
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
9
|
+
</script>
|
10
|
+
<script type="text/javascript">
|
11
|
+
try {
|
12
|
+
var pageTracker = _gat._getTracker("{{ID}}");
|
13
|
+
pageTracker._trackPageview();
|
14
|
+
} catch(err) {}</script>
|
15
|
+
EOCODE
|
16
|
+
|
17
|
+
def initialize(app, id)
|
18
|
+
@app = app
|
19
|
+
@id = id
|
20
|
+
end
|
21
|
+
|
22
|
+
def call(env)
|
23
|
+
status, headers, body = @app.call(env)
|
24
|
+
|
25
|
+
body.each do |part|
|
26
|
+
if part =~ /<\/body>/
|
27
|
+
part.sub!(/<\/body>/, "#{tracking_code}</body>")
|
28
|
+
|
29
|
+
if headers['Content-Length']
|
30
|
+
headers['Content-Length'] = (headers['Content-Length'].to_i + tracking_code.length).to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
break
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
[status, headers, body]
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def tracking_code
|
42
|
+
TRACKING_CODE.sub(/\{\{ID\}\}/, @id)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# http://gist.github.com/207947
|
2
|
+
# http://coderack.org/users/julioody/entries/20-racknoie
|
3
|
+
module Rack
|
4
|
+
class NoIE
|
5
|
+
def initialize(app, options = {})
|
6
|
+
@app = app
|
7
|
+
@options = options
|
8
|
+
@options[:redirect] ||= 'http://www.microsoft.com/windows/internet-explorer/default.aspx'
|
9
|
+
@options[:minimum] ||= 7.0
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
ie_found_in?(env) ? kick_it : @app.call(env)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def ie_found_in?(env)
|
18
|
+
if env['HTTP_USER_AGENT']
|
19
|
+
is_ie?(env['HTTP_USER_AGENT']) and ie_version(env['HTTP_USER_AGENT']) < @options[:minimum] and @options[:redirect] != env['PATH_INFO']
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def is_ie?(ua_string)
|
24
|
+
# We need at least one digit to be able to get the version, hence the \d
|
25
|
+
ua_string.match(/MSIE \d/) ? true : false
|
26
|
+
end
|
27
|
+
|
28
|
+
def ie_version(ua_string)
|
29
|
+
ua_string.match(/MSIE (\S+)/)[1].to_f
|
30
|
+
end
|
31
|
+
|
32
|
+
def kick_it
|
33
|
+
[301, {'Location' => @options[:redirect]}, 'Fail browser is fail']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
use Rack::NoIE, :redirect => Glog.config['plugins']['no_ie']
|
data/spec/glog_spec.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Glog" do
|
4
|
+
|
5
|
+
let(:app) { create_from_fixture('example') }
|
6
|
+
|
7
|
+
it "should have config accessor" do
|
8
|
+
Glog.config = 'config'
|
9
|
+
Glog.config.should == 'config'
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "Glog::Page" do
|
13
|
+
describe "Page.root" do
|
14
|
+
it "should return root page defined in Glog.config" do
|
15
|
+
Glog::Page.root.title.should == 'Hello All'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#template_path" do
|
20
|
+
describe "when template defined in file" do
|
21
|
+
it "should return templates/{Page#template}.haml" do
|
22
|
+
page = Glog::Page.get('template_test/template1_test')
|
23
|
+
page.should_not be_nil
|
24
|
+
page.template_path.should == 'templates/template1.haml'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "when Page#template is undefined" do
|
29
|
+
it "should should use default.html from tepmlates/{Page#parent}" do
|
30
|
+
page = Glog::Page.get("template_test/undefined_template")
|
31
|
+
page.parent.should == 'template_test'
|
32
|
+
page.template_path.should == "templates/#{page.parent}/default.haml"
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "if there is no defaut.html in templats/{Page#parent}" do
|
36
|
+
it "should inherit default.html template from parent dirs" do
|
37
|
+
page = Glog::Page.get("template_test/deep/template")
|
38
|
+
page.parent.should == 'template_test/deep'
|
39
|
+
page.template_path.should == "templates/template_test/default.haml"
|
40
|
+
# And very deep page...
|
41
|
+
page = Glog::Page.get("deep/deep/deep/page/with/undefined/template/here")
|
42
|
+
page.parent.should == 'deep/deep/deep/page/with/undefined/template'
|
43
|
+
page.template_path.should == "templates/default.haml"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "Glog::Server" do
|
51
|
+
include Rack::Test::Methods
|
52
|
+
|
53
|
+
describe "GET /" do
|
54
|
+
it "should be ok" do
|
55
|
+
get '/'
|
56
|
+
last_response.should be_ok
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should render text from page defined as root in Glog.config" do
|
60
|
+
get '/'
|
61
|
+
last_response.body.should =~ /Hello All/
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "GET /some/dir" do
|
66
|
+
it "should try to render /some/dir/index if index exists" do
|
67
|
+
dir = 'spec/fixtures/example/pages/epo/2010'
|
68
|
+
File.exists?(dir).should be_true
|
69
|
+
File.directory?(dir).should be_true
|
70
|
+
get '/epo/2010'
|
71
|
+
last_response.should be_ok
|
72
|
+
last_response.body.should match(/this is index/)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should return 404 if no index found" do
|
76
|
+
get '/epo/2010'
|
77
|
+
last_response.should be_ok
|
78
|
+
last_response.body.should match(/this is index/)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end # describe Server
|
82
|
+
end # describe Glog
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'glog'
|
6
|
+
require 'spec'
|
7
|
+
require 'spec/autorun'
|
8
|
+
require 'spec/interop/test'
|
9
|
+
require 'rack/test'
|
10
|
+
|
11
|
+
def create_from_fixture(name)
|
12
|
+
Dir.chdir(File.join(File.dirname(__FILE__), "fixtures", name))
|
13
|
+
Glog.config = YAML.load_file('glog.yaml')
|
14
|
+
@app = Glog::Server.new
|
15
|
+
end
|
16
|
+
|
17
|
+
Spec::Runner.configure do |config|
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: glog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Antono Vasiljev
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-03-28 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: jadof
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 1
|
30
|
+
- 6
|
31
|
+
version: 0.1.6
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: haml
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 2
|
43
|
+
- 2
|
44
|
+
- 0
|
45
|
+
version: 2.2.0
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rspec
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 1
|
57
|
+
- 3
|
58
|
+
- 0
|
59
|
+
version: 1.3.0
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rack-test
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
- 5
|
72
|
+
- 3
|
73
|
+
version: 0.5.3
|
74
|
+
type: :development
|
75
|
+
version_requirements: *id004
|
76
|
+
description: Blog your git repository
|
77
|
+
email: antono.vasiljev@gmail.com
|
78
|
+
executables: []
|
79
|
+
|
80
|
+
extensions: []
|
81
|
+
|
82
|
+
extra_rdoc_files:
|
83
|
+
- LICENSE
|
84
|
+
- README.markdown
|
85
|
+
files:
|
86
|
+
- LICENSE
|
87
|
+
- README.markdown
|
88
|
+
has_rdoc: true
|
89
|
+
homepage: http://github.com/antono/glog
|
90
|
+
licenses: []
|
91
|
+
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options:
|
94
|
+
- --charset=UTF-8
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
version: "0"
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
version: "0"
|
111
|
+
requirements: []
|
112
|
+
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 1.3.6
|
115
|
+
signing_key:
|
116
|
+
specification_version: 3
|
117
|
+
summary: Git powered bogging engine
|
118
|
+
test_files:
|
119
|
+
- spec/fixtures/example/plugins/google_analytics.rb
|
120
|
+
- spec/fixtures/example/plugins/chrome_frame.rb
|
121
|
+
- spec/fixtures/example/plugins/canonical_host.rb
|
122
|
+
- spec/fixtures/example/plugins/no_ie.rb
|
123
|
+
- spec/glog_spec.rb
|
124
|
+
- spec/spec_helper.rb
|