trellis 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -2
- data/License.txt +1 -1
- data/README +17 -12
- data/README.txt +17 -12
- data/config/hoe.rb +1 -2
- data/lib/trellis/trellis.rb +33 -4
- data/lib/trellis/version.rb +1 -1
- data/test/router_spec.rb +32 -0
- metadata +4 -14
data/History.txt
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
+
== 0.0.8
|
2
|
+
* 1 major enhancement:
|
3
|
+
* implemented automatic route sorting
|
4
|
+
|
1
5
|
== 0.0.7
|
2
|
-
* 3 major
|
6
|
+
* 3 major enhancements:
|
7
|
+
* ripped out rexml/hpricot replaced with nokogiri
|
3
8
|
* implemented page get method to override default page rendering
|
4
|
-
* added trellis namespace xmlns method for markaby
|
9
|
+
* added trellis namespace xmlns method for markaby
|
5
10
|
* clean all examples to add trellis namespace
|
6
11
|
|
7
12
|
== 0.0.6
|
data/License.txt
CHANGED
data/README
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
= Project: Trellis
|
2
2
|
|
3
|
-
Trellis is a component-based Web Application Framework written in Ruby.
|
4
|
-
Its main goal is to bring component-driven development to the micro-framework world.
|
5
|
-
|
3
|
+
Trellis is a component-based Web Application Framework written in Ruby and based on Rack.
|
4
|
+
Its main goal is to bring component-driven development to the micro-framework world.
|
5
|
+
Trellis applications are composed of pages, pages have components, components emit events,
|
6
|
+
pages and components can listen and handle events.
|
7
|
+
Trellis aims to be a (close to) zero-configuration framework
|
6
8
|
|
7
9
|
It draws inspiration from:
|
8
10
|
|
@@ -18,7 +20,6 @@ Java Web Frameworks
|
|
18
20
|
===================
|
19
21
|
* Tapesty
|
20
22
|
* Wicket
|
21
|
-
* The good parts of JSF (components)
|
22
23
|
|
23
24
|
Others
|
24
25
|
======
|
@@ -26,17 +27,17 @@ Others
|
|
26
27
|
|
27
28
|
== Goals
|
28
29
|
Accomplished goals are marked with a (*)
|
29
|
-
- * Pure HTML templates or in-line template creation with Markaby
|
30
|
+
- * Pure HTML templates or in-line template creation with Markaby, HAML, erubis, Markdown and Textile
|
30
31
|
- * To abstract away the request-response nature of web development and replace
|
31
32
|
with events and listeners
|
32
33
|
- * Reusable, extensible components including invisible components (behavior
|
33
34
|
providers), tags (stateless components) or stateful components
|
34
|
-
- Easy component composition and markup inheritance
|
35
|
+
- * Easy component composition and markup inheritance
|
35
36
|
- * Multi-threading support
|
36
37
|
- * Heavy CoC :-) (Convention Over Configuration) ala Rails
|
37
38
|
- * No static code generation, no generators, just a Ruby file!
|
38
39
|
- * Component Libraries as Gems
|
39
|
-
-
|
40
|
+
- Solid Ajax support attached to the event model using a single* massively tested
|
40
41
|
Ajax framework/toolkit such as JQuery
|
41
42
|
- Skinnable components a la DotNet. That is the ability to apply a theme to a
|
42
43
|
page and cascade that to the contained components
|
@@ -62,6 +63,7 @@ Accomplished goals are marked with a (*)
|
|
62
63
|
Trellis::Application:: Base case for all Trellis applications
|
63
64
|
Trellis::Page:: Base class for all application Pages
|
64
65
|
Trellis::Renderer:: Renders XML/XHTML tags in the markup using Radius
|
66
|
+
Trellis::Router:: Encapsulated the base route for a page
|
65
67
|
Trellis::Component:: Base class for all Trellis components (work in progress)
|
66
68
|
Trellis::DefaultRouter:: Encapsulates the default routing logic
|
67
69
|
|
@@ -75,7 +77,7 @@ Trellis::DefaultRouter:: Encapsulates the default routing logic
|
|
75
77
|
* Navigation is a la Tapestry; Page methods can return the instance of a
|
76
78
|
injected Page or they can return self in which case the same page is
|
77
79
|
re-rendered.
|
78
|
-
*
|
80
|
+
* Components can register their event handlers with the page. The page wraps the
|
79
81
|
event handlers of the contained components and dispatches the events to the
|
80
82
|
component instance.
|
81
83
|
* Currently the Application is a single object, the multi-threading (which I had
|
@@ -118,16 +120,19 @@ mongrel => http://mongrel.rubyforge.org
|
|
118
120
|
radius => http://radius.rubyforge.org
|
119
121
|
builder => http://builder.rubyforge.org
|
120
122
|
paginator => http://paginator.rubyforge.org
|
121
|
-
hpricot => http://code.whytheluckystiff.net/hpricot
|
122
123
|
extensions => http://extensions.rubyforge.org
|
123
124
|
haml => http://haml.hamptoncatlin.com
|
124
125
|
markaby => http://code.whytheluckystiff.net/markaby
|
126
|
+
nokogiti => http://nokogiri.org/
|
127
|
+
facets => http://facets.rubyforge.org/
|
128
|
+
directory_watcher => http://rubyforge.org/projects/codeforpeople
|
129
|
+
erubis => http://www.kuwata-lab.com/erubis/
|
125
130
|
|
126
131
|
== LICENSE:
|
127
132
|
|
128
133
|
(The MIT License)
|
129
134
|
|
130
|
-
Copyright &169;2001-
|
135
|
+
Copyright &169;2001-2010 Integrallis Software, LLC.
|
131
136
|
|
132
137
|
Permission is hereby granted, free of charge, to any person obtaining
|
133
138
|
a copy of this software and associated documentation files (the
|
@@ -150,7 +155,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
150
155
|
|
151
156
|
== Contact
|
152
157
|
|
153
|
-
Author:: Brian Sam-Bodden
|
158
|
+
Author:: Brian Sam-Bodden & the Folks at Integrallis
|
154
159
|
Email:: bsbodden@integrallis.com
|
155
|
-
Home Page:: http://
|
160
|
+
Home Page:: http://trellisframework.org
|
156
161
|
License:: MIT Licence (http://www.opensource.org/licenses/mit-license.html)
|
data/README.txt
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
= Project: Trellis
|
2
2
|
|
3
|
-
Trellis is a component-based Web Application Framework written in Ruby.
|
4
|
-
Its main goal is to bring component-driven development to the micro-framework world.
|
5
|
-
|
3
|
+
Trellis is a component-based Web Application Framework written in Ruby and based on Rack.
|
4
|
+
Its main goal is to bring component-driven development to the micro-framework world.
|
5
|
+
Trellis applications are composed of pages, pages have components, components emit events,
|
6
|
+
pages and components can listen and handle events.
|
7
|
+
Trellis aims to be a (close to) zero-configuration framework
|
6
8
|
|
7
9
|
It draws inspiration from:
|
8
10
|
|
@@ -18,7 +20,6 @@ Java Web Frameworks
|
|
18
20
|
===================
|
19
21
|
* Tapesty
|
20
22
|
* Wicket
|
21
|
-
* The good parts of JSF (components)
|
22
23
|
|
23
24
|
Others
|
24
25
|
======
|
@@ -26,17 +27,17 @@ Others
|
|
26
27
|
|
27
28
|
== Goals
|
28
29
|
Accomplished goals are marked with a (*)
|
29
|
-
- * Pure HTML templates or in-line template creation with Markaby
|
30
|
+
- * Pure HTML templates or in-line template creation with Markaby, HAML, erubis, Markdown and Textile
|
30
31
|
- * To abstract away the request-response nature of web development and replace
|
31
32
|
with events and listeners
|
32
33
|
- * Reusable, extensible components including invisible components (behavior
|
33
34
|
providers), tags (stateless components) or stateful components
|
34
|
-
- Easy component composition and markup inheritance
|
35
|
+
- * Easy component composition and markup inheritance
|
35
36
|
- * Multi-threading support
|
36
37
|
- * Heavy CoC :-) (Convention Over Configuration) ala Rails
|
37
38
|
- * No static code generation, no generators, just a Ruby file!
|
38
39
|
- * Component Libraries as Gems
|
39
|
-
-
|
40
|
+
- Solid Ajax support attached to the event model using a single* massively tested
|
40
41
|
Ajax framework/toolkit such as JQuery
|
41
42
|
- Skinnable components a la DotNet. That is the ability to apply a theme to a
|
42
43
|
page and cascade that to the contained components
|
@@ -62,6 +63,7 @@ Accomplished goals are marked with a (*)
|
|
62
63
|
Trellis::Application:: Base case for all Trellis applications
|
63
64
|
Trellis::Page:: Base class for all application Pages
|
64
65
|
Trellis::Renderer:: Renders XML/XHTML tags in the markup using Radius
|
66
|
+
Trellis::Router:: Encapsulated the base route for a page
|
65
67
|
Trellis::Component:: Base class for all Trellis components (work in progress)
|
66
68
|
Trellis::DefaultRouter:: Encapsulates the default routing logic
|
67
69
|
|
@@ -75,7 +77,7 @@ Trellis::DefaultRouter:: Encapsulates the default routing logic
|
|
75
77
|
* Navigation is a la Tapestry; Page methods can return the instance of a
|
76
78
|
injected Page or they can return self in which case the same page is
|
77
79
|
re-rendered.
|
78
|
-
*
|
80
|
+
* Components can register their event handlers with the page. The page wraps the
|
79
81
|
event handlers of the contained components and dispatches the events to the
|
80
82
|
component instance.
|
81
83
|
* Currently the Application is a single object, the multi-threading (which I had
|
@@ -118,16 +120,19 @@ mongrel => http://mongrel.rubyforge.org
|
|
118
120
|
radius => http://radius.rubyforge.org
|
119
121
|
builder => http://builder.rubyforge.org
|
120
122
|
paginator => http://paginator.rubyforge.org
|
121
|
-
hpricot => http://code.whytheluckystiff.net/hpricot
|
122
123
|
extensions => http://extensions.rubyforge.org
|
123
124
|
haml => http://haml.hamptoncatlin.com
|
124
125
|
markaby => http://code.whytheluckystiff.net/markaby
|
126
|
+
nokogiti => http://nokogiri.org/
|
127
|
+
facets => http://facets.rubyforge.org/
|
128
|
+
directory_watcher => http://rubyforge.org/projects/codeforpeople
|
129
|
+
erubis => http://www.kuwata-lab.com/erubis/
|
125
130
|
|
126
131
|
== LICENSE:
|
127
132
|
|
128
133
|
(The MIT License)
|
129
134
|
|
130
|
-
Copyright &169;2001-
|
135
|
+
Copyright &169;2001-2010 Integrallis Software, LLC.
|
131
136
|
|
132
137
|
Permission is hereby granted, free of charge, to any person obtaining
|
133
138
|
a copy of this software and associated documentation files (the
|
@@ -150,7 +155,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
150
155
|
|
151
156
|
== Contact
|
152
157
|
|
153
|
-
Author:: Brian Sam-Bodden
|
158
|
+
Author:: Brian Sam-Bodden & the Folks at Integrallis
|
154
159
|
Email:: bsbodden@integrallis.com
|
155
|
-
Home Page:: http://
|
160
|
+
Home Page:: http://trellisframework.org
|
156
161
|
License:: MIT Licence (http://www.opensource.org/licenses/mit-license.html)
|
data/config/hoe.rb
CHANGED
@@ -12,12 +12,11 @@ EXTRA_DEPENDENCIES = [
|
|
12
12
|
['rack', '>= 1.0.1'],
|
13
13
|
['radius', '>= 0.6.1'],
|
14
14
|
['builder', '>= 2.1.2'],
|
15
|
-
['
|
15
|
+
['nokogiri', '>= 1.4.0'],
|
16
16
|
['extensions', '>= 0.6.0'],
|
17
17
|
['haml', '>= 2.2.9'],
|
18
18
|
['RedCloth', '>= 4.2.2'],
|
19
19
|
['bluecloth', '>= 2.0.5'],
|
20
|
-
['markaby', '>= 0.5'],
|
21
20
|
['log4r', '>= 1.1.2'],
|
22
21
|
['facets', '>= 2.7.0'],
|
23
22
|
['directory_watcher', '>= 1.2.0'],
|
data/lib/trellis/trellis.rb
CHANGED
@@ -63,6 +63,7 @@ module Trellis
|
|
63
63
|
child.attr_array(:persistents)
|
64
64
|
child.class_attr_reader(:session_config)
|
65
65
|
child.attr_array(:static_routes)
|
66
|
+
child.attr_array(:routers)
|
66
67
|
child.meta_def(:logger) { Application.logger }
|
67
68
|
child.instance_variable_set(:@session_config, OpenStruct.new({:impl => :cookie}))
|
68
69
|
super
|
@@ -148,11 +149,18 @@ module Trellis
|
|
148
149
|
end
|
149
150
|
application
|
150
151
|
end
|
152
|
+
|
153
|
+
def self.routers
|
154
|
+
unless @routers
|
155
|
+
@routers = Page.subclasses.values.collect { |page| page.router }.compact.sort {|a,b| b.score <=> a.score }
|
156
|
+
end
|
157
|
+
@routers
|
158
|
+
end
|
151
159
|
|
152
160
|
# find the first page with a suitable router, if none is found use the default router
|
153
161
|
def find_router_for(request)
|
154
|
-
match =
|
155
|
-
match
|
162
|
+
match = Application.routers.find { |router| router.matches?(request) }
|
163
|
+
match || DefaultRouter.new(:application => self)
|
156
164
|
end
|
157
165
|
|
158
166
|
# rack call interface.
|
@@ -334,13 +342,18 @@ module Trellis
|
|
334
342
|
class Router
|
335
343
|
EVENT_REGEX = %r{^(?:.+)/events/(?:([^/\.]+)(?:\.([^/\.]+)?)?)(?:/(?:([^\.]+)?))?}
|
336
344
|
|
337
|
-
attr_reader :application, :pattern, :keys, :path, :page
|
345
|
+
attr_reader :application, :pattern, :keys, :path, :page, :score
|
338
346
|
|
339
347
|
def initialize(options={})
|
340
348
|
@application = options[:application]
|
341
349
|
@path = options[:path]
|
342
350
|
@page = options[:page]
|
343
|
-
|
351
|
+
if @path
|
352
|
+
compile_path
|
353
|
+
compute_score
|
354
|
+
else
|
355
|
+
@score = 3 # since "/*" scores at 2
|
356
|
+
end
|
344
357
|
end
|
345
358
|
|
346
359
|
def route(request = nil)
|
@@ -376,6 +389,10 @@ module Trellis
|
|
376
389
|
params.each_pair { |name, value| page.instance_variable_set("@#{name}".to_sym, value) }
|
377
390
|
end
|
378
391
|
end
|
392
|
+
|
393
|
+
def to_s
|
394
|
+
@path
|
395
|
+
end
|
379
396
|
|
380
397
|
private
|
381
398
|
|
@@ -407,6 +424,18 @@ module Trellis
|
|
407
424
|
raise TypeError, @path
|
408
425
|
end
|
409
426
|
end
|
427
|
+
|
428
|
+
def compute_score
|
429
|
+
score = 0
|
430
|
+
parts = @path.split('/').delete_if {|part| part.empty? }
|
431
|
+
parts.each_index do |index|
|
432
|
+
part = parts[index]
|
433
|
+
power = parts.size - index
|
434
|
+
factor = part.match('\*') ? 1 : (part.match(':') ? 2 : 3)
|
435
|
+
score = score + (factor * (2**index))
|
436
|
+
end
|
437
|
+
@score = score
|
438
|
+
end
|
410
439
|
end
|
411
440
|
|
412
441
|
# -- DefaultRouter --
|
data/lib/trellis/version.rb
CHANGED
data/test/router_spec.rb
CHANGED
@@ -51,4 +51,36 @@ describe Trellis::Router, " when constructed" do
|
|
51
51
|
@router.keys.should include('splat')
|
52
52
|
end
|
53
53
|
|
54
|
+
it "should be able to be sorted by 'matchability'" do
|
55
|
+
route_1 = Trellis::Router.new(:path => '/hello/:one/:two')
|
56
|
+
route_2 = Trellis::Router.new(:path => '/hello/jim/:last')
|
57
|
+
route_3 = Trellis::Router.new(:path => '/hello/*')
|
58
|
+
route_4 = Trellis::Router.new(:path => '/hello/*/:foo/*')
|
59
|
+
|
60
|
+
routes = [ route_1, route_2, route_3, route_4 ].sort {|a,b| b.score <=> a.score }
|
61
|
+
|
62
|
+
routes[0].should be(route_4)
|
63
|
+
routes[1].should be(route_2)
|
64
|
+
routes[2].should be(route_1)
|
65
|
+
routes[3].should be(route_3)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "a catch all route should always be last when sorted with other routes" do
|
69
|
+
route_1 = Trellis::Router.new(:path => '/admin/login')
|
70
|
+
route_2 = Trellis::Router.new(:path => '/*')
|
71
|
+
route_3 = Trellis::Router.new(:path => '/admin/pages')
|
72
|
+
route_4 = Trellis::Router.new(:path => '/admin/new/page')
|
73
|
+
route_5 = Trellis::Router.new(:path => '/admin/page/:id')
|
74
|
+
route_6 = Trellis::Router.new(:path => '/admin/page/:id/delete')
|
75
|
+
|
76
|
+
routes = [ route_1, route_2, route_3, route_4, route_5, route_6 ].sort {|a,b| b.score <=> a.score }
|
77
|
+
|
78
|
+
routes[0].should be(route_6)
|
79
|
+
routes[1].should be(route_4)
|
80
|
+
routes[2].should be(route_5)
|
81
|
+
routes[3].should be(route_3)
|
82
|
+
routes[4].should be(route_1)
|
83
|
+
routes[5].should be(route_2)
|
84
|
+
end
|
85
|
+
|
54
86
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trellis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Sam-Bodden
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-12 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -53,14 +53,14 @@ dependencies:
|
|
53
53
|
version: 2.1.2
|
54
54
|
version:
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: nokogiri
|
57
57
|
type: :runtime
|
58
58
|
version_requirement:
|
59
59
|
version_requirements: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
61
|
- - ">="
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version:
|
63
|
+
version: 1.4.0
|
64
64
|
version:
|
65
65
|
- !ruby/object:Gem::Dependency
|
66
66
|
name: extensions
|
@@ -102,16 +102,6 @@ dependencies:
|
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: 2.0.5
|
104
104
|
version:
|
105
|
-
- !ruby/object:Gem::Dependency
|
106
|
-
name: markaby
|
107
|
-
type: :runtime
|
108
|
-
version_requirement:
|
109
|
-
version_requirements: !ruby/object:Gem::Requirement
|
110
|
-
requirements:
|
111
|
-
- - ">="
|
112
|
-
- !ruby/object:Gem::Version
|
113
|
-
version: "0.5"
|
114
|
-
version:
|
115
105
|
- !ruby/object:Gem::Dependency
|
116
106
|
name: log4r
|
117
107
|
type: :runtime
|