scharfie-bones 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/bones +2 -1
- data/lib/bones.rb +1 -74
- data/lib/bones/bones.rb +73 -0
- data/lib/{boot.rb → bones/boot.rb} +3 -2
- data/lib/{extensions.rb → bones/extensions.rb} +0 -0
- data/lib/bones/template.rb +2 -2
- data/lib/tasks/bones.rb +1 -1
- data/pushables/boot.rb +2 -2
- data/scharfie-bones.gemspec +7 -5
- data/test/example_site/layouts/example_layout.html.erb +1 -0
- data/test/example_site/pages/index.html.erb +1 -1
- data/test/example_site/pages/partials/{_footer.html.erb → common/_footer.html.erb} +0 -0
- data/test/test_bones.rb +4 -4
- data/test/test_cache.rb +17 -0
- data/test/test_helper.rb +5 -5
- data/test/test_template.rb +3 -2
- metadata +6 -5
data/bin/bones
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require File.join(File.dirname(__FILE__), '../lib/boot')
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/bones/boot.rb'))
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/bones/initializer.rb'))
|
3
4
|
path = ARGV.shift
|
4
5
|
|
5
6
|
if path.nil?
|
data/lib/bones.rb
CHANGED
@@ -1,74 +1 @@
|
|
1
|
-
|
2
|
-
# which BonesProxy loads and calls upon to
|
3
|
-
# do the dirty work.
|
4
|
-
class Bones
|
5
|
-
class << self
|
6
|
-
attr_accessor :base, :root
|
7
|
-
attr_accessor :system_path, :pages_path, :layouts_path
|
8
|
-
attr_accessor :booted
|
9
|
-
|
10
|
-
def base
|
11
|
-
@base || ''
|
12
|
-
end
|
13
|
-
|
14
|
-
# Path to the root of the bones project
|
15
|
-
# Defaults to current directory
|
16
|
-
def root
|
17
|
-
@root ||= File.expand_path(File.dirname(__FILE__) + '/../../')
|
18
|
-
end
|
19
|
-
|
20
|
-
# Path to the bones system files
|
21
|
-
# Defaults to the directory containing this file
|
22
|
-
def system_path
|
23
|
-
@system_path ||= File.expand_path(File.dirname(__FILE__))
|
24
|
-
end
|
25
|
-
|
26
|
-
# Path to the directory containing the page templates
|
27
|
-
# [root]/pages
|
28
|
-
def pages_path
|
29
|
-
@pages_path || root / 'pages'
|
30
|
-
end
|
31
|
-
|
32
|
-
# Path to the directory containing the layout templates
|
33
|
-
# [root]/layouts
|
34
|
-
def layouts_path
|
35
|
-
@layouts_path || root / 'layouts'
|
36
|
-
end
|
37
|
-
|
38
|
-
def booted?
|
39
|
-
@booted
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# Resets root, pages, and layouts paths and the base setting
|
44
|
-
def self.reset
|
45
|
-
@pages_path = @layouts_path = @root = @base = nil
|
46
|
-
end
|
47
|
-
|
48
|
-
# Process incoming request (for real this time!)
|
49
|
-
def call(env)
|
50
|
-
# Grab the request
|
51
|
-
request = Rack::Request.new(env)
|
52
|
-
|
53
|
-
# Create a new template for the given path
|
54
|
-
# and compile it
|
55
|
-
template = Template.new(request.path_info)
|
56
|
-
template.request = request
|
57
|
-
output = template.compile
|
58
|
-
|
59
|
-
# Build a rack response
|
60
|
-
# Rack::Response.new.finish do |response|
|
61
|
-
# response.write output
|
62
|
-
# end
|
63
|
-
[200, { 'Content-Type' => 'text/html'}, output]
|
64
|
-
end
|
65
|
-
|
66
|
-
# Returns array of all pages (excluding partials)
|
67
|
-
def self.pages
|
68
|
-
Dir.chdir(Bones.pages_path) do
|
69
|
-
Dir.glob('**/*.html.erb').map do |f|
|
70
|
-
f.starts_with?('_') ? nil : f.gsub('.html.erb', '')
|
71
|
-
end.compact
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
1
|
+
require File.join(File.dirname(__FILE__), "bones/bones.rb")
|
data/lib/bones/bones.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# Bones - the _real_ request handler,
|
2
|
+
# which BonesProxy loads and calls upon to
|
3
|
+
# do the dirty work.
|
4
|
+
class Bones
|
5
|
+
class << self
|
6
|
+
attr_accessor :base, :root
|
7
|
+
attr_accessor :system_path, :pages_path, :layouts_path
|
8
|
+
attr_accessor :booted
|
9
|
+
|
10
|
+
def base
|
11
|
+
@base || ''
|
12
|
+
end
|
13
|
+
|
14
|
+
# Path to the root of the bones project
|
15
|
+
def root
|
16
|
+
@root ||= Pathname.new(__FILE__).dirname.dirname.expand_path.to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
# Path to the bones system files
|
20
|
+
# Defaults to the lib
|
21
|
+
def system_path
|
22
|
+
@system_path ||= Pathname.new(__FILE__).dirname.dirname.expand_path.to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
# Path to the directory containing the page templates
|
26
|
+
# [root]/pages
|
27
|
+
def pages_path
|
28
|
+
@pages_path || root / 'pages'
|
29
|
+
end
|
30
|
+
|
31
|
+
# Path to the directory containing the layout templates
|
32
|
+
# [root]/layouts
|
33
|
+
def layouts_path
|
34
|
+
@layouts_path || root / 'layouts'
|
35
|
+
end
|
36
|
+
|
37
|
+
def booted?
|
38
|
+
@booted
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Resets root, pages, and layouts paths and the base setting
|
43
|
+
def self.reset
|
44
|
+
@pages_path = @layouts_path = @root = @base = nil
|
45
|
+
end
|
46
|
+
|
47
|
+
# Process incoming request (for real this time!)
|
48
|
+
def call(env)
|
49
|
+
# Grab the request
|
50
|
+
request = Rack::Request.new(env)
|
51
|
+
|
52
|
+
# Create a new template for the given path
|
53
|
+
# and compile it
|
54
|
+
template = Template.new(request.path_info)
|
55
|
+
template.request = request
|
56
|
+
output = template.compile
|
57
|
+
|
58
|
+
# Build a rack response
|
59
|
+
# Rack::Response.new.finish do |response|
|
60
|
+
# response.write output
|
61
|
+
# end
|
62
|
+
[200, { 'Content-Type' => 'text/html'}, output]
|
63
|
+
end
|
64
|
+
|
65
|
+
# Returns array of all pages (excluding partials)
|
66
|
+
def self.pages
|
67
|
+
Dir.chdir(Bones.pages_path) do
|
68
|
+
Dir.glob('**/*.html.erb').map do |f|
|
69
|
+
f.starts_with?('_') ? nil : f.gsub('.html.erb', '')
|
70
|
+
end.compact
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'activesupport'
|
3
3
|
require 'rack'
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require 'pathname'
|
5
|
+
require Pathname.new(__FILE__).dirname.join('bones.rb')
|
6
|
+
require Pathname.new(__FILE__).dirname.join('extensions.rb')
|
6
7
|
|
7
8
|
ActiveSupport::Dependencies.load_paths.push Bones.system_path
|
8
9
|
$:.push Bones.system_path
|
File without changes
|
data/lib/bones/template.rb
CHANGED
@@ -85,7 +85,7 @@ class Bones
|
|
85
85
|
|
86
86
|
src = ERB.new(File.read(filename)).src
|
87
87
|
src = (local_assigns_source || '') + (src || '')
|
88
|
-
@content_for_layout = eval(src)
|
88
|
+
@content_for_layout = eval(src)
|
89
89
|
|
90
90
|
if layout && File.file?(layout_filename)
|
91
91
|
erb = ERB.new(File.read(layout_filename))
|
@@ -118,7 +118,7 @@ class Bones
|
|
118
118
|
# the '_footer.html.erb' template.
|
119
119
|
def partial(name, options={})
|
120
120
|
path = name.to_s.split('/')
|
121
|
-
path
|
121
|
+
path.last.gsub!(/^([^_])/, '_\1')
|
122
122
|
name = path.join('/')
|
123
123
|
template = Template.new(name, false, options)
|
124
124
|
template.request = request
|
data/lib/tasks/bones.rb
CHANGED
data/pushables/boot.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
bones_boot = File.join(File.dirname(__FILE__), 'bones
|
1
|
+
bones_boot = File.join(File.dirname(__FILE__), 'vendor/bones/lib/bones/boot.rb')
|
2
2
|
|
3
3
|
if File.file?(bones_boot)
|
4
4
|
require bones_boot
|
5
5
|
else
|
6
6
|
require 'rubygems'
|
7
7
|
require 'bones'
|
8
|
-
require 'boot'
|
8
|
+
require 'bones/boot'
|
9
9
|
end
|
10
10
|
|
11
11
|
Bones.root = File.expand_path(File.dirname(__FILE__))
|
data/scharfie-bones.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "scharfie-bones"
|
3
|
-
s.version = "0.2.
|
4
|
-
s.date = "2009-
|
3
|
+
s.version = "0.2.4"
|
4
|
+
s.date = "2009-10-24"
|
5
5
|
s.authors = ["Chris Scharf", "Ryan Heath"]
|
6
6
|
s.email = "scharfie@gmail.com"
|
7
7
|
|
@@ -28,9 +28,10 @@ Gem::Specification.new do |s|
|
|
28
28
|
'lib/bones/static.rb',
|
29
29
|
'lib/bones/template.rb',
|
30
30
|
'lib/bones/versioned_release.rb',
|
31
|
+
'lib/bones/bones.rb',
|
32
|
+
'lib/bones/boot.rb',
|
33
|
+
'lib/bones/extensions.rb',
|
31
34
|
'lib/bones.rb',
|
32
|
-
'lib/boot.rb',
|
33
|
-
'lib/extensions.rb',
|
34
35
|
'lib/helpers',
|
35
36
|
'lib/helpers/application_helper.rb',
|
36
37
|
'lib/helpers/core_helper.rb',
|
@@ -52,7 +53,8 @@ Gem::Specification.new do |s|
|
|
52
53
|
'test/example_site/pages/about.html.erb',
|
53
54
|
'test/example_site/pages/index.html.erb',
|
54
55
|
'test/example_site/pages/partials',
|
55
|
-
'test/example_site/pages/partials/
|
56
|
+
'test/example_site/pages/partials/common',
|
57
|
+
'test/example_site/pages/partials/common/_footer.html.erb',
|
56
58
|
'test/example_site/pages/things',
|
57
59
|
'test/example_site/pages/things/a.html.erb',
|
58
60
|
'test/example_site/public',
|
File without changes
|
data/test/test_bones.rb
CHANGED
@@ -2,10 +2,10 @@ require File.dirname(__FILE__) + '/test_helper'
|
|
2
2
|
|
3
3
|
context 'Bones' do
|
4
4
|
test "should have proper paths" do
|
5
|
-
assert_equal relative_path('
|
6
|
-
assert_equal relative_path('../lib'),
|
7
|
-
assert_equal relative_path('
|
8
|
-
assert_equal relative_path('
|
5
|
+
assert_equal relative_path('../lib'), Bones.root
|
6
|
+
assert_equal relative_path('../lib'), Bones.system_path
|
7
|
+
assert_equal relative_path('../lib/pages'), Bones.pages_path
|
8
|
+
assert_equal relative_path('../lib/layouts'), Bones.layouts_path
|
9
9
|
end
|
10
10
|
|
11
11
|
test "should allow getting/setting Bones.base" do
|
data/test/test_cache.rb
CHANGED
@@ -14,6 +14,23 @@ context "Bones::Cache with default options" do
|
|
14
14
|
assert_include @page, 'href="/things/a.html"'
|
15
15
|
end
|
16
16
|
end
|
17
|
+
|
18
|
+
context 'Bones::Cache with default options, layout' do
|
19
|
+
uses_example_site
|
20
|
+
|
21
|
+
setup do
|
22
|
+
@cache = Bones::Cache.new
|
23
|
+
@page = @cache.process_page('about')
|
24
|
+
end
|
25
|
+
|
26
|
+
test "should have layout" do
|
27
|
+
assert_include @page, 'Example Layout'
|
28
|
+
end
|
29
|
+
|
30
|
+
test "should have footer" do
|
31
|
+
assert_include @page, 'Footer text'
|
32
|
+
end
|
33
|
+
end
|
17
34
|
|
18
35
|
context "Bones::Cache with custom base" do
|
19
36
|
uses_example_site
|
data/test/test_helper.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__) + '/../')
|
2
|
-
require 'lib/boot'
|
2
|
+
require 'lib/bones/boot'
|
3
3
|
require 'test/unit'
|
4
4
|
|
5
5
|
class String
|
@@ -18,8 +18,7 @@ end
|
|
18
18
|
|
19
19
|
def context(name, &block)
|
20
20
|
Object.const_set(name.to_s.to_test_class_name, Class.new(Test::Unit::TestCase, &block))
|
21
|
-
end
|
22
|
-
|
21
|
+
end
|
23
22
|
|
24
23
|
class Test::Unit::TestCase
|
25
24
|
class << self; attr_accessor :bones_root; end
|
@@ -38,7 +37,7 @@ class Test::Unit::TestCase
|
|
38
37
|
# end
|
39
38
|
|
40
39
|
def self.uses_example_site
|
41
|
-
self.bones_root =
|
40
|
+
self.bones_root = Pathname.new(__FILE__).dirname.join('example_site').expand_path.to_s
|
42
41
|
end
|
43
42
|
|
44
43
|
def run_with_bones_root(*args, &block)
|
@@ -56,10 +55,11 @@ class Test::Unit::TestCase
|
|
56
55
|
end
|
57
56
|
|
58
57
|
def relative_path(path)
|
59
|
-
|
58
|
+
Pathname.new(__FILE__).dirname.join(path).expand_path.to_s
|
60
59
|
end
|
61
60
|
|
62
61
|
def assert_include(collection, obj, message=nil)
|
62
|
+
message ||= "expected #{collection.inspect} to include #{obj.inspect}"
|
63
63
|
assert collection.include?(obj), message
|
64
64
|
end
|
65
65
|
end
|
data/test/test_template.rb
CHANGED
@@ -31,8 +31,9 @@ context "Bones Template" do
|
|
31
31
|
assert_include @template.some_custom_helper, 'Some custom helper'
|
32
32
|
end
|
33
33
|
|
34
|
-
test "should render partial partials/footer" do
|
35
|
-
|
34
|
+
test "should render partial partials/common/footer" do
|
35
|
+
# @template.layout = 'example_layout'
|
36
|
+
assert_include @template.partial('partials/common/footer'), 'Footer text'
|
36
37
|
end
|
37
38
|
|
38
39
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scharfie-bones
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Scharf
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-
|
13
|
+
date: 2009-10-24 00:00:00 -04:00
|
14
14
|
default_executable: bones
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -52,9 +52,10 @@ files:
|
|
52
52
|
- lib/bones/static.rb
|
53
53
|
- lib/bones/template.rb
|
54
54
|
- lib/bones/versioned_release.rb
|
55
|
+
- lib/bones/bones.rb
|
56
|
+
- lib/bones/boot.rb
|
57
|
+
- lib/bones/extensions.rb
|
55
58
|
- lib/bones.rb
|
56
|
-
- lib/boot.rb
|
57
|
-
- lib/extensions.rb
|
58
59
|
- lib/helpers/application_helper.rb
|
59
60
|
- lib/helpers/core_helper.rb
|
60
61
|
- lib/layouts/application.html.erb
|
@@ -67,7 +68,7 @@ files:
|
|
67
68
|
- test/example_site/layouts/example_layout.html.erb
|
68
69
|
- test/example_site/pages/about.html.erb
|
69
70
|
- test/example_site/pages/index.html.erb
|
70
|
-
- test/example_site/pages/partials/_footer.html.erb
|
71
|
+
- test/example_site/pages/partials/common/_footer.html.erb
|
71
72
|
- test/example_site/pages/things/a.html.erb
|
72
73
|
- test/example_site/public/images/.gitignore
|
73
74
|
- test/example_site/public/javascripts/.gitignore
|