ramaze 0.1.1 → 0.1.2
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/Rakefile +14 -29
- data/bin/ramaze +2 -3
- data/doc/AUTHORS +5 -2
- data/doc/CHANGELOG +262 -9
- data/doc/FAQ +6 -6
- data/doc/meta/announcement.txt +5 -19
- data/doc/tutorial/todolist.html +47 -57
- data/doc/tutorial/todolist.mkd +47 -55
- data/examples/memleak_detector.rb +31 -0
- data/examples/todolist/src/controller/main.rb +14 -13
- data/examples/todolist/src/element/page.rb +2 -2
- data/examples/todolist/src/model.rb +2 -2
- data/examples/todolist/todolist.db +0 -4
- data/examples/whywiki/main.rb +2 -2
- data/examples/whywiki/template/edit.xhtml +1 -1
- data/examples/whywiki/template/show.xhtml +3 -3
- data/lib/proto/src/controller/main.rb +18 -1
- data/lib/proto/template/index.xhtml +11 -2
- data/lib/ramaze.rb +1 -1
- data/lib/ramaze/action.rb +104 -5
- data/lib/ramaze/action/render.rb +54 -0
- data/lib/ramaze/adapter.rb +2 -1
- data/lib/ramaze/adapter/mongrel.rb +13 -4
- data/lib/ramaze/cache.rb +17 -8
- data/lib/ramaze/cache/memcached.rb +1 -5
- data/lib/ramaze/controller.rb +51 -18
- data/lib/ramaze/controller/resolve.rb +19 -14
- data/lib/ramaze/dispatcher.rb +13 -16
- data/lib/ramaze/dispatcher/action.rb +2 -3
- data/lib/ramaze/dispatcher/error.rb +8 -3
- data/lib/ramaze/dispatcher/file.rb +1 -4
- data/lib/ramaze/error.rb +5 -5
- data/lib/ramaze/global.rb +7 -1
- data/lib/ramaze/global/globalstruct.rb +1 -3
- data/lib/ramaze/helper/aspect.rb +8 -10
- data/lib/ramaze/helper/cgi.rb +21 -3
- data/lib/ramaze/helper/identity.rb +4 -6
- data/lib/ramaze/helper/link.rb +4 -4
- data/lib/ramaze/helper/pager.rb +316 -0
- data/lib/ramaze/helper/partial.rb +37 -0
- data/lib/ramaze/helper/stack.rb +1 -1
- data/lib/ramaze/inform.rb +9 -0
- data/lib/ramaze/inform/hub.rb +5 -0
- data/lib/ramaze/inform/informer.rb +12 -6
- data/lib/ramaze/inform/informing.rb +32 -7
- data/lib/ramaze/inform/knotify.rb +21 -0
- data/lib/ramaze/inform/xosd.rb +58 -24
- data/lib/ramaze/sourcereload.rb +30 -1
- data/lib/ramaze/template.rb +33 -12
- data/lib/ramaze/template/amrita2.rb +21 -20
- data/lib/ramaze/template/erubis.rb +18 -14
- data/lib/ramaze/template/ezamar.rb +15 -26
- data/lib/ramaze/template/ezamar/element.rb +1 -1
- data/lib/ramaze/template/ezamar/engine.rb +45 -36
- data/lib/ramaze/template/ezamar/morpher.rb +3 -3
- data/lib/ramaze/template/ezamar/render_partial.rb +26 -0
- data/lib/ramaze/template/haml.rb +23 -18
- data/lib/ramaze/template/liquid.rb +5 -3
- data/lib/ramaze/template/markaby.rb +14 -11
- data/lib/ramaze/template/remarkably.rb +11 -5
- data/lib/ramaze/tool/localize.rb +12 -4
- data/lib/ramaze/tool/tidy.rb +26 -23
- data/lib/ramaze/trinity/request.rb +11 -7
- data/lib/ramaze/trinity/session.rb +24 -8
- data/lib/ramaze/version.rb +1 -1
- data/rake_tasks/maintaince.rake +136 -11
- data/spec/examples/templates/template_liquid.rb +6 -3
- data/spec/examples/todolist.rb +1 -2
- data/spec/helper/minimal.rb +7 -7
- data/spec/ramaze/action/basics.rb +19 -0
- data/spec/ramaze/action/render.rb +18 -0
- data/spec/ramaze/controller.rb +1 -1
- data/spec/ramaze/controller/template_resolving.rb +1 -1
- data/spec/ramaze/dispatcher/file.rb +24 -0
- data/spec/ramaze/error.rb +28 -29
- data/spec/ramaze/helper/cgi.rb +43 -0
- data/spec/ramaze/helper/pager.rb +27 -0
- data/spec/ramaze/helper/partial.rb +38 -0
- data/spec/ramaze/helper/template/partial.xhtml +1 -0
- data/spec/ramaze/inform/informer.rb +1 -1
- data/spec/ramaze/localize.rb +1 -1
- data/spec/ramaze/morpher.rb +3 -3
- data/spec/ramaze/request.rb +1 -3
- data/spec/ramaze/template.rb +9 -7
- data/spec/ramaze/template/haml.rb +2 -1
- metadata +21 -7
- data/examples/todolist/public/404.jpg +0 -0
- data/examples/todolist/public/error.xhtml +0 -74
- data/lib/ramaze/controller/render.rb +0 -90
@@ -3,27 +3,31 @@
|
|
3
3
|
|
4
4
|
require 'erubis'
|
5
5
|
|
6
|
-
module Ramaze
|
6
|
+
module Ramaze
|
7
|
+
module Template
|
7
8
|
|
8
|
-
|
9
|
+
# Is responsible for compiling a template using the Erubis templating engine.
|
9
10
|
|
10
|
-
|
11
|
+
class Erubis < Template
|
11
12
|
|
12
|
-
|
13
|
+
ENGINES[self] = %w[ rhtml ]
|
13
14
|
|
14
|
-
|
15
|
+
class << self
|
15
16
|
|
16
|
-
|
17
|
-
#
|
18
|
-
# Builds a template out of the method on the controller and the
|
19
|
-
# template-file.
|
17
|
+
# Entry-point for Action#render
|
20
18
|
|
21
|
-
|
22
|
-
|
19
|
+
def transform action
|
20
|
+
eruby = wrap_compile(action)
|
21
|
+
eruby.result(action.binding)
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
# Creates an instance of ::Erubis::Eruby, sets the filename
|
25
|
+
# from the template and returns the instance.
|
26
|
+
def compile(action, template)
|
27
|
+
eruby = ::Erubis::Eruby.new(template)
|
28
|
+
eruby.init_evaluator(:filename => (action.template || __FILE__))
|
29
|
+
eruby
|
30
|
+
end
|
27
31
|
end
|
28
32
|
end
|
29
33
|
end
|
@@ -10,41 +10,30 @@ module Ramaze
|
|
10
10
|
|
11
11
|
class Ezamar < Template
|
12
12
|
|
13
|
-
|
13
|
+
ENGINES[self] = %w[ xhtml zmr ]
|
14
14
|
|
15
|
-
|
16
|
-
::Ezamar::Element, ::Ezamar::Template
|
17
|
-
]
|
18
|
-
|
19
|
-
trait :actionless => true
|
15
|
+
TRANSFORM_PIPELINE = [ ::Ezamar::Element ]
|
20
16
|
|
21
17
|
class << self
|
22
18
|
|
23
|
-
#
|
24
|
-
#
|
25
|
-
# Uses Ezamar::Template to compile the template.
|
26
|
-
|
19
|
+
# Transforms an action into the XHTML code for parsing and returns
|
20
|
+
# the result
|
27
21
|
def transform action
|
28
|
-
|
29
|
-
|
30
|
-
pipeline(template.to_s, action.binding, file)
|
22
|
+
ezamar = wrap_compile(action)
|
23
|
+
ezamar.result(action.binding)
|
31
24
|
end
|
32
25
|
|
33
|
-
#
|
34
|
-
#
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
def pipeline(template, binding, file)
|
43
|
-
class_trait[:transform_pipeline].each do |klass|
|
44
|
-
template = klass.transform(template, binding, file)
|
26
|
+
# Compile a template, applying all transformations from the pipeline
|
27
|
+
# and returning an instance of ::Ezamar::Template
|
28
|
+
|
29
|
+
def compile(action, template)
|
30
|
+
file = (action.template || __FILE__)
|
31
|
+
|
32
|
+
TRANSFORM_PIPELINE.each do |tp|
|
33
|
+
template = tp.transform(template)
|
45
34
|
end
|
46
35
|
|
47
|
-
template
|
36
|
+
::Ezamar::Template.new(template, :file => file)
|
48
37
|
end
|
49
38
|
end
|
50
39
|
end
|
@@ -83,7 +83,7 @@ class Ezamar::Element
|
|
83
83
|
# a binding to be compatible to the transform-pipeline, won't have
|
84
84
|
# any use for it though.
|
85
85
|
|
86
|
-
def transform template
|
86
|
+
def transform template
|
87
87
|
matches = template.scan(/<([A-Z][a-zA-Z0-9]*)(.*?)?>/)
|
88
88
|
|
89
89
|
matches.each do |(klass, params)|
|
@@ -17,47 +17,56 @@ module Ezamar
|
|
17
17
|
# This class is responsible for initializing and compiling the template.
|
18
18
|
|
19
19
|
class Template
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
20
|
+
def initialize(template, options = {})
|
21
|
+
@template, @options = template, options
|
22
|
+
compile
|
23
|
+
end
|
24
|
+
|
25
|
+
# All ye who seek magic, look elsewhere, this method is ASAP (as simple as possible)
|
26
|
+
#
|
27
|
+
# There are some simple gsubs that build a final template which is evaluated
|
28
|
+
#
|
29
|
+
# The rules are following:
|
30
|
+
# <?r rubycode ?>
|
31
|
+
# evaluate the code inside the tag, this is considered XHTML-valid and so is the
|
32
|
+
# preferred method for executing code inside your templates.
|
33
|
+
# The return-value is ignored
|
34
|
+
# <% rubycode %>
|
35
|
+
# The same as <?r ?>, ERB-style and not valid XHTML, but should give someone who
|
36
|
+
# is already familiar with ERB some common ground
|
37
|
+
# #{ rubycode }
|
38
|
+
# You know this from normal ruby already and it's actually nothing else.
|
39
|
+
# Interpolation at the position in the template, isn't any special taggy format
|
40
|
+
# and therefor safe to use.
|
41
|
+
# <%= rubycode %>
|
42
|
+
# The result of this will be interpolated at the position in the template.
|
43
|
+
# Not valid XHTML either.
|
44
|
+
#
|
45
|
+
# TODO
|
46
|
+
# - provide C version or maybe use erbuis
|
47
|
+
|
48
|
+
def compile
|
49
|
+
temp = @template.dup
|
50
|
+
start_heredoc = "T" << Digest::SHA1.hexdigest(temp)
|
51
|
+
start_heredoc, end_heredoc = "\n<<#{start_heredoc}\n", "\n#{start_heredoc}\n"
|
52
|
+
bufadd = "_out_ << "
|
53
|
+
|
54
|
+
temp.gsub!(/<%\s+(.*?)\s+%>/m,
|
51
55
|
"#{end_heredoc} \\1; #{bufadd} #{start_heredoc}")
|
52
|
-
|
56
|
+
temp.gsub!(/<\?r\s+(.*?)\s+\?>/m,
|
53
57
|
"#{end_heredoc} \\1; #{bufadd} #{start_heredoc}")
|
54
|
-
|
58
|
+
temp.gsub!(/<%=\s+(.*?)\s+%>/m,
|
55
59
|
"#{end_heredoc} #{bufadd} (\\1); #{bufadd} #{start_heredoc}")
|
56
60
|
|
57
|
-
|
61
|
+
@compiled = "_out_ = ''
|
62
|
+
#{bufadd} #{start_heredoc} #{temp} #{end_heredoc}
|
63
|
+
_out_"
|
64
|
+
end
|
65
|
+
|
66
|
+
# Takes a binding and evals it with the previously set options.
|
58
67
|
|
59
|
-
|
60
|
-
|
68
|
+
def result(binding)
|
69
|
+
eval(@compiled, binding, @options[:file]).strip
|
61
70
|
end
|
62
71
|
end
|
63
72
|
end
|
@@ -18,7 +18,7 @@ require 'ramaze/template/ezamar/engine'
|
|
18
18
|
#
|
19
19
|
# If you want to turn this functionality off, either remove Morpher
|
20
20
|
# from:
|
21
|
-
# Ramaze::Template::Ezamar
|
21
|
+
# Ramaze::Template::Ezamar::TRANSFORM_PIPELINE
|
22
22
|
# or do:
|
23
23
|
# Ramaze::Morpher.trait[:morphs] = {}
|
24
24
|
#
|
@@ -106,7 +106,7 @@ class Ezamar::Morpher
|
|
106
106
|
# TODO:
|
107
107
|
# - Add pure Ruby implementation as a fall-back.
|
108
108
|
|
109
|
-
def self.transform
|
109
|
+
def self.transform(template)
|
110
110
|
morphs =
|
111
111
|
trait[:morphs].map{|k,v| [k.to_s, v.to_s]}.select do |(k,v)|
|
112
112
|
template.to_s.include?("#{k}=")
|
@@ -145,7 +145,7 @@ class Ezamar::Morpher
|
|
145
145
|
# replace this method with a stub that only returns the template.
|
146
146
|
|
147
147
|
self.class_eval do
|
148
|
-
def self.transform(template
|
148
|
+
def self.transform(template)
|
149
149
|
template
|
150
150
|
end
|
151
151
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
3
|
+
|
4
|
+
require 'ramaze/template/ezamar/engine'
|
5
|
+
|
6
|
+
module Ezamar
|
7
|
+
class RenderPartial
|
8
|
+
|
9
|
+
# Renders <render src="/path" [optional="option", ...]> in place.
|
10
|
+
#
|
11
|
+
# Other options than `src` will be transformed to session parameters for the
|
12
|
+
# rendered action to use.
|
13
|
+
|
14
|
+
def self.transform(template, action, file = __FILE__)
|
15
|
+
template.gsub!(/<render (.*?) \/>/) do |m|
|
16
|
+
args = Hash[*$1.scan(/(\S+)=["'](.*?)["']/).flatten]
|
17
|
+
if src = args.delete('src')
|
18
|
+
PartialHelper.render_partial(src, args)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
template
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/lib/ramaze/template/haml.rb
CHANGED
@@ -3,32 +3,37 @@
|
|
3
3
|
|
4
4
|
require 'haml/engine'
|
5
5
|
|
6
|
-
module Ramaze
|
7
|
-
|
6
|
+
module Ramaze
|
7
|
+
module Template
|
8
|
+
class Haml < Template
|
8
9
|
|
9
|
-
|
10
|
+
# Custom HAML-options for your controller to be merged.
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
trait :haml_options => {
|
13
|
+
:locals => {}
|
14
|
+
}
|
14
15
|
|
15
|
-
|
16
|
+
ENGINES[self] = %w[ haml ]
|
16
17
|
|
17
|
-
|
18
|
+
class << self
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
# Transform any String via Haml, takes optionally an hash with the
|
21
|
+
# haml_options that you can set also by
|
22
|
+
# trait :haml_options => {}
|
23
|
+
# if you pass the options it will merge the trait with them. (your
|
24
|
+
# options override the defaults from trait[:haml_options]
|
24
25
|
|
25
|
-
|
26
|
-
|
26
|
+
def transform action
|
27
|
+
haml = wrap_compile(action)
|
28
|
+
haml.to_html(action.instance)
|
29
|
+
end
|
27
30
|
|
28
|
-
|
31
|
+
# Instantiates Haml::Engine with the template and haml_options from
|
32
|
+
# the trait.
|
29
33
|
|
30
|
-
|
31
|
-
|
34
|
+
def compile(action, template)
|
35
|
+
::Haml::Engine.new(template, ancestral_trait[:haml_options])
|
36
|
+
end
|
32
37
|
end
|
33
38
|
end
|
34
39
|
end
|
@@ -6,7 +6,8 @@ require 'liquid'
|
|
6
6
|
module Ramaze
|
7
7
|
module Template
|
8
8
|
class Liquid < Template
|
9
|
-
|
9
|
+
|
10
|
+
ENGINES[self] = %w[ liquid ]
|
10
11
|
|
11
12
|
class << self
|
12
13
|
|
@@ -18,9 +19,10 @@ module Ramaze
|
|
18
19
|
def transform action
|
19
20
|
template = reaction_or_file(action)
|
20
21
|
|
21
|
-
|
22
|
+
instance = action.instance
|
23
|
+
hash = instance.instance_variable_get("@hash") || {}
|
22
24
|
template = ::Liquid::Template.parse(template)
|
23
|
-
options =
|
25
|
+
options = instance.ancestral_trait[:liquid_options]
|
24
26
|
|
25
27
|
template.render(hash, options)
|
26
28
|
end
|
@@ -6,31 +6,34 @@ require 'markaby'
|
|
6
6
|
module Ramaze
|
7
7
|
module Template
|
8
8
|
class Markaby < Template
|
9
|
-
|
9
|
+
ENGINES[self] = %w[ mab ]
|
10
10
|
|
11
11
|
class << self
|
12
12
|
|
13
|
-
#
|
14
|
-
# Creates a new instances of itself and sends the action and params.
|
15
|
-
# Also tries to render the template.
|
16
|
-
# In Theory you can use this standalone, this has not been tested though.
|
13
|
+
# Entry point for Action#render
|
17
14
|
|
18
15
|
def transform action
|
19
16
|
result, file = result_and_file(action)
|
20
17
|
|
21
|
-
result =
|
18
|
+
result = transform_string(file, action) if file
|
22
19
|
result.to_s
|
23
20
|
end
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
# Takes a string and action, instance_evals the string inside a mab
|
23
|
+
# block that gets the instance_variables of the original
|
24
|
+
# action.instance passed.
|
28
25
|
|
29
|
-
|
30
|
-
|
26
|
+
def transform_string string, action
|
27
|
+
instance = action.instance
|
28
|
+
ivs = extract_ivs(instance)
|
29
|
+
|
30
|
+
instance.send(:mab, ivs) do
|
31
|
+
instance_eval(string)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
35
|
+
# Generate a hash from instance-variables
|
36
|
+
|
34
37
|
def extract_ivs(controller)
|
35
38
|
controller.instance_variables.inject({}) do |hash, iv|
|
36
39
|
sym = iv.gsub('@', '').to_sym
|
@@ -6,20 +6,26 @@ require 'remarkably/engines/html'
|
|
6
6
|
module Ramaze
|
7
7
|
module Template
|
8
8
|
class Remarkably < Template
|
9
|
-
|
9
|
+
ENGINES[self] = %w[ rem ]
|
10
10
|
|
11
11
|
class << self
|
12
|
+
|
13
|
+
# Entry point for Action#render
|
14
|
+
|
12
15
|
def transform action
|
13
16
|
result, file = result_and_file(action)
|
14
17
|
|
15
|
-
result =
|
18
|
+
result = transform_string(file, action) if file
|
16
19
|
result.to_s
|
17
20
|
end
|
18
21
|
|
19
|
-
|
20
|
-
|
22
|
+
# Takes a string and action, sets args to action.args and then proceeds
|
23
|
+
# to instance_eval the string inside the action.instance
|
24
|
+
|
25
|
+
def transform_string(string, action)
|
26
|
+
action.instance.instance_eval do
|
21
27
|
args = action.params
|
22
|
-
instance_eval(
|
28
|
+
instance_eval(string)
|
23
29
|
end
|
24
30
|
end
|
25
31
|
end
|
data/lib/ramaze/tool/localize.rb
CHANGED
@@ -27,6 +27,11 @@ class Ramaze::Tool::Localize
|
|
27
27
|
# do some coercion between what you use as keys and what the browser sends.
|
28
28
|
trait :mapping => { 'en-us' => 'en', 'ja' => 'jp'}
|
29
29
|
|
30
|
+
# When this is set to false, it will not save newly collected translatable
|
31
|
+
# strings to disk. Disable this for production use, as it slows the
|
32
|
+
# application down.
|
33
|
+
trait :collect => true
|
34
|
+
|
30
35
|
class << self
|
31
36
|
|
32
37
|
include Ramaze::Trinity
|
@@ -46,7 +51,7 @@ class Ramaze::Tool::Localize
|
|
46
51
|
localize($1, locale)
|
47
52
|
end
|
48
53
|
|
49
|
-
store(locale, trait[:default_language])
|
54
|
+
store(locale, trait[:default_language]) if trait[:collect]
|
50
55
|
|
51
56
|
body
|
52
57
|
end
|
@@ -60,9 +65,12 @@ class Ramaze::Tool::Localize
|
|
60
65
|
|
61
66
|
if dict[locale] && trans = dict[locale][str]
|
62
67
|
#
|
63
|
-
elsif trans = dict[default_language][str]
|
68
|
+
elsif dict[default_language] && trans = dict[default_language][str]
|
69
|
+
dict[locale] ||= {}
|
64
70
|
dict[locale][str] = str
|
65
71
|
else
|
72
|
+
dict[locale] ||= {}
|
73
|
+
dict[default_language] ||= {}
|
66
74
|
dict[locale][str] = str
|
67
75
|
dict[default_language][str] = str
|
68
76
|
end
|
@@ -121,8 +129,8 @@ class Ramaze::Tool::Localize
|
|
121
129
|
fd.write data
|
122
130
|
end
|
123
131
|
end
|
124
|
-
rescue Errno::ENOENT
|
125
|
-
|
132
|
+
rescue Errno::ENOENT => e
|
133
|
+
Ramaze::Inform.error e
|
126
134
|
end
|
127
135
|
end
|
128
136
|
end
|