ramaze 0.0.6
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 +360 -0
- data/bin/ramaze +152 -0
- data/doc/CHANGELOG +2021 -0
- data/doc/COPYING +56 -0
- data/doc/COPYING.ja +51 -0
- data/doc/README +275 -0
- data/doc/TODO +33 -0
- data/doc/allison/LICENSE +184 -0
- data/doc/allison/README +37 -0
- data/doc/allison/allison.css +300 -0
- data/doc/allison/allison.gif +0 -0
- data/doc/allison/allison.js +307 -0
- data/doc/allison/allison.rb +287 -0
- data/doc/allison/cache/BODY +588 -0
- data/doc/allison/cache/CLASS_INDEX +4 -0
- data/doc/allison/cache/CLASS_PAGE +1 -0
- data/doc/allison/cache/FILE_INDEX +4 -0
- data/doc/allison/cache/FILE_PAGE +1 -0
- data/doc/allison/cache/FONTS +1 -0
- data/doc/allison/cache/FR_INDEX_BODY +1 -0
- data/doc/allison/cache/IMGPATH +1 -0
- data/doc/allison/cache/INDEX +1 -0
- data/doc/allison/cache/JAVASCRIPT +307 -0
- data/doc/allison/cache/METHOD_INDEX +4 -0
- data/doc/allison/cache/METHOD_LIST +1 -0
- data/doc/allison/cache/SRC_PAGE +1 -0
- data/doc/allison/cache/STYLE +322 -0
- data/doc/allison/cache/URL +1 -0
- data/examples/blog/main.rb +16 -0
- data/examples/blog/public/screen.css +106 -0
- data/examples/blog/src/controller.rb +50 -0
- data/examples/blog/src/element.rb +53 -0
- data/examples/blog/src/model.rb +29 -0
- data/examples/blog/template/edit.xhtml +6 -0
- data/examples/blog/template/index.xhtml +24 -0
- data/examples/blog/template/new.xhtml +5 -0
- data/examples/blog/template/view.xhtml +15 -0
- data/examples/blog/test/tc_entry.rb +18 -0
- data/examples/caching.rb +23 -0
- data/examples/element.rb +40 -0
- data/examples/hello.rb +23 -0
- data/examples/simple.rb +60 -0
- data/examples/templates/template/external.haml +21 -0
- data/examples/templates/template/external.liquid +28 -0
- data/examples/templates/template/external.mab +27 -0
- data/examples/templates/template/external.rhtml +29 -0
- data/examples/templates/template/external.rmze +24 -0
- data/examples/templates/template_erubis.rb +50 -0
- data/examples/templates/template_haml.rb +48 -0
- data/examples/templates/template_liquid.rb +64 -0
- data/examples/templates/template_markaby.rb +52 -0
- data/examples/templates/template_ramaze.rb +49 -0
- data/examples/whywiki/main.rb +56 -0
- data/examples/whywiki/template/edit.xhtml +14 -0
- data/examples/whywiki/template/show.xhtml +17 -0
- data/lib/proto/conf/benchmark.yaml +35 -0
- data/lib/proto/conf/debug.yaml +34 -0
- data/lib/proto/conf/live.yaml +33 -0
- data/lib/proto/conf/silent.yaml +31 -0
- data/lib/proto/conf/stage.yaml +33 -0
- data/lib/proto/main.rb +18 -0
- data/lib/proto/public/404.jpg +0 -0
- data/lib/proto/public/css/coderay.css +105 -0
- data/lib/proto/public/css/ramaze_error.css +42 -0
- data/lib/proto/public/error.xhtml +74 -0
- data/lib/proto/public/favicon.ico +0 -0
- data/lib/proto/public/js/jquery.js +1923 -0
- data/lib/proto/public/ramaze.png +0 -0
- data/lib/proto/src/controller/main.rb +7 -0
- data/lib/proto/src/element/page.rb +16 -0
- data/lib/proto/src/model.rb +5 -0
- data/lib/proto/template/index.xhtml +6 -0
- data/lib/ramaze.rb +317 -0
- data/lib/ramaze/adapter/mongrel.rb +111 -0
- data/lib/ramaze/adapter/webrick.rb +161 -0
- data/lib/ramaze/cache.rb +11 -0
- data/lib/ramaze/cache/memcached.rb +52 -0
- data/lib/ramaze/cache/memory.rb +6 -0
- data/lib/ramaze/cache/yaml_store.rb +37 -0
- data/lib/ramaze/controller.rb +10 -0
- data/lib/ramaze/dispatcher.rb +315 -0
- data/lib/ramaze/error.rb +11 -0
- data/lib/ramaze/gestalt.rb +108 -0
- data/lib/ramaze/global.rb +120 -0
- data/lib/ramaze/helper.rb +32 -0
- data/lib/ramaze/helper/aspect.rb +189 -0
- data/lib/ramaze/helper/auth.rb +120 -0
- data/lib/ramaze/helper/cache.rb +52 -0
- data/lib/ramaze/helper/feed.rb +135 -0
- data/lib/ramaze/helper/form.rb +204 -0
- data/lib/ramaze/helper/link.rb +80 -0
- data/lib/ramaze/helper/redirect.rb +48 -0
- data/lib/ramaze/helper/stack.rb +67 -0
- data/lib/ramaze/http_status.rb +66 -0
- data/lib/ramaze/inform.rb +166 -0
- data/lib/ramaze/snippets.rb +5 -0
- data/lib/ramaze/snippets/hash/keys_to_sym.rb +19 -0
- data/lib/ramaze/snippets/kernel/aquire.rb +22 -0
- data/lib/ramaze/snippets/kernel/autoreload.rb +79 -0
- data/lib/ramaze/snippets/kernel/caller_lines.rb +58 -0
- data/lib/ramaze/snippets/kernel/constant.rb +24 -0
- data/lib/ramaze/snippets/kernel/rescue_require.rb +12 -0
- data/lib/ramaze/snippets/kernel/self_method.rb +41 -0
- data/lib/ramaze/snippets/kernel/silently.rb +13 -0
- data/lib/ramaze/snippets/object/traits.rb +60 -0
- data/lib/ramaze/snippets/openstruct/temp.rb +10 -0
- data/lib/ramaze/snippets/string/DIVIDE.rb +16 -0
- data/lib/ramaze/snippets/string/camel_case.rb +14 -0
- data/lib/ramaze/snippets/string/snake_case.rb +12 -0
- data/lib/ramaze/snippets/symbol/to_proc.rb +14 -0
- data/lib/ramaze/snippets/thread/deadQUESTIONMARK.rb +11 -0
- data/lib/ramaze/store/default.rb +48 -0
- data/lib/ramaze/template.rb +102 -0
- data/lib/ramaze/template/amrita2.rb +40 -0
- data/lib/ramaze/template/erubis.rb +58 -0
- data/lib/ramaze/template/haml.rb +65 -0
- data/lib/ramaze/template/haml/actionview_stub.rb +20 -0
- data/lib/ramaze/template/liquid.rb +74 -0
- data/lib/ramaze/template/markaby.rb +68 -0
- data/lib/ramaze/template/ramaze.rb +177 -0
- data/lib/ramaze/template/ramaze/element.rb +166 -0
- data/lib/ramaze/template/ramaze/morpher.rb +156 -0
- data/lib/ramaze/tool/create.rb +70 -0
- data/lib/ramaze/tool/tidy.rb +71 -0
- data/lib/ramaze/trinity.rb +38 -0
- data/lib/ramaze/trinity/request.rb +244 -0
- data/lib/ramaze/trinity/response.rb +41 -0
- data/lib/ramaze/trinity/session.rb +129 -0
- data/lib/ramaze/version.rb +14 -0
- data/spec/spec_all.rb +73 -0
- data/spec/spec_helper.rb +215 -0
- data/spec/tc_adapter_mongrel.rb +24 -0
- data/spec/tc_adapter_webrick.rb +22 -0
- data/spec/tc_cache.rb +79 -0
- data/spec/tc_controller.rb +39 -0
- data/spec/tc_element.rb +100 -0
- data/spec/tc_error.rb +23 -0
- data/spec/tc_gestalt.rb +90 -0
- data/spec/tc_global.rb +46 -0
- data/spec/tc_helper_aspect.rb +65 -0
- data/spec/tc_helper_auth.rb +61 -0
- data/spec/tc_helper_cache.rb +81 -0
- data/spec/tc_helper_feed.rb +129 -0
- data/spec/tc_helper_form.rb +146 -0
- data/spec/tc_helper_link.rb +58 -0
- data/spec/tc_helper_redirect.rb +51 -0
- data/spec/tc_helper_stack.rb +55 -0
- data/spec/tc_morpher.rb +90 -0
- data/spec/tc_params.rb +84 -0
- data/spec/tc_request.rb +111 -0
- data/spec/tc_session.rb +56 -0
- data/spec/tc_store.rb +25 -0
- data/spec/tc_template_amrita2.rb +34 -0
- data/spec/tc_template_erubis.rb +41 -0
- data/spec/tc_template_haml.rb +44 -0
- data/spec/tc_template_liquid.rb +98 -0
- data/spec/tc_template_markaby.rb +74 -0
- data/spec/tc_template_ramaze.rb +54 -0
- data/spec/tc_tidy.rb +14 -0
- data/spec/template/amrita2/data.html +6 -0
- data/spec/template/amrita2/index.html +1 -0
- data/spec/template/amrita2/sum.html +1 -0
- data/spec/template/erubis/sum.rhtml +1 -0
- data/spec/template/haml/index.haml +5 -0
- data/spec/template/haml/with_vars.haml +4 -0
- data/spec/template/liquid/index.liquid +1 -0
- data/spec/template/liquid/products.liquid +45 -0
- data/spec/template/markaby/external.mab +8 -0
- data/spec/template/markaby/sum.mab +1 -0
- data/spec/template/ramaze/file_only.rmze +1 -0
- data/spec/template/ramaze/index.rmze +1 -0
- data/spec/template/ramaze/nested.rmze +1 -0
- data/spec/template/ramaze/sum.rmze +1 -0
- metadata +317 -0
|
@@ -0,0 +1,166 @@
|
|
|
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
|
+
module Ramaze
|
|
5
|
+
|
|
6
|
+
# an Element is almost like an Controller, however, instead
|
|
7
|
+
# of connecting actions to templates it is only used in
|
|
8
|
+
# Ramaze::Template::Ramaze and can be used inside the
|
|
9
|
+
# templates of the Controller as a simple wrapper.
|
|
10
|
+
#
|
|
11
|
+
# Example:
|
|
12
|
+
#
|
|
13
|
+
# Your Element called Page:
|
|
14
|
+
#
|
|
15
|
+
# class Page < Element
|
|
16
|
+
# def render
|
|
17
|
+
# %{
|
|
18
|
+
# <html>
|
|
19
|
+
# <h1>
|
|
20
|
+
# #{@hash['title']}
|
|
21
|
+
# </h1>
|
|
22
|
+
# #{content}
|
|
23
|
+
# </html>
|
|
24
|
+
# }
|
|
25
|
+
# end
|
|
26
|
+
# end
|
|
27
|
+
#
|
|
28
|
+
# and one called SideBar
|
|
29
|
+
#
|
|
30
|
+
# class SideBar < Element
|
|
31
|
+
# def render
|
|
32
|
+
# %{
|
|
33
|
+
# <a href="http://something.com">something</a>
|
|
34
|
+
# }
|
|
35
|
+
# end
|
|
36
|
+
# end
|
|
37
|
+
#
|
|
38
|
+
# and your template (any template for any action):
|
|
39
|
+
#
|
|
40
|
+
# <Page title="Test">
|
|
41
|
+
# <SideBar />
|
|
42
|
+
# <p>
|
|
43
|
+
# Hello, World!
|
|
44
|
+
# </p>
|
|
45
|
+
# </Page>
|
|
46
|
+
#
|
|
47
|
+
# would result in:
|
|
48
|
+
#
|
|
49
|
+
# <html>
|
|
50
|
+
# <h1>
|
|
51
|
+
# Test
|
|
52
|
+
# </h1>
|
|
53
|
+
# <p>
|
|
54
|
+
# Hello, World!
|
|
55
|
+
# </p>
|
|
56
|
+
# </html>
|
|
57
|
+
|
|
58
|
+
class Element
|
|
59
|
+
extend Ramaze::Helper
|
|
60
|
+
|
|
61
|
+
helper :link, :redirect
|
|
62
|
+
|
|
63
|
+
attr_accessor :content
|
|
64
|
+
|
|
65
|
+
# this will be called by #transform, passes along the
|
|
66
|
+
# stuff inside the tags for the element
|
|
67
|
+
|
|
68
|
+
def initialize(content)
|
|
69
|
+
@content = content
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# The method that will be called upon to render the things
|
|
73
|
+
# inside the element, you can access #content from here, which
|
|
74
|
+
# contains the contents between the tags.
|
|
75
|
+
#
|
|
76
|
+
# It should answer with a String.
|
|
77
|
+
|
|
78
|
+
def render *args
|
|
79
|
+
@content
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
class << self
|
|
83
|
+
# transforms all <Element> tags within the string, takes also
|
|
84
|
+
# a binding to be compatible to the transform-pipeline, won't have
|
|
85
|
+
# any use for it though.
|
|
86
|
+
#
|
|
87
|
+
# It also sets a instance-variable for you called @hash, which
|
|
88
|
+
# contains the parameters you gave the <Element> tag.
|
|
89
|
+
# See above for an example of writing and using them.
|
|
90
|
+
|
|
91
|
+
def transform string = '', binding = nil
|
|
92
|
+
string = string.to_s
|
|
93
|
+
matches = string.scan(/<([A-Z][a-zA-Z0-9]*)(.*?)?>/)
|
|
94
|
+
|
|
95
|
+
matches.each do |(klass, params)|
|
|
96
|
+
transformer = (params[-1,1] == '/' ? :without : :with)
|
|
97
|
+
string = send("transform_#{transformer}_content", string, klass)
|
|
98
|
+
end
|
|
99
|
+
string
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# transforms elements like:
|
|
103
|
+
# <Page> some content </Page>
|
|
104
|
+
|
|
105
|
+
def transform_with_content(string, klass)
|
|
106
|
+
string.gsub(/<#{klass}( .*?)?>(.*?)<\/#{klass}>/m) do |m|
|
|
107
|
+
params, content = $1.to_s, $2.to_s
|
|
108
|
+
finish_transform(klass, params, content)
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# transforms elements like:
|
|
113
|
+
# <Page />
|
|
114
|
+
|
|
115
|
+
def transform_without_content(string, klass)
|
|
116
|
+
string.gsub(/<#{klass}( .*?)?\/>/) do |m|
|
|
117
|
+
params = $1.to_s
|
|
118
|
+
finish_transform(klass, params, content = '')
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# find the element, create an instance, pass it the content
|
|
123
|
+
# check if it responds to :render and set an instance-variable
|
|
124
|
+
# called @hash to hold the parameters passed to the element.
|
|
125
|
+
#
|
|
126
|
+
# Parameters look like:
|
|
127
|
+
# <Page foo="true"> bar </Page>
|
|
128
|
+
# <Page foo="true" />
|
|
129
|
+
|
|
130
|
+
def finish_transform(klass, params, content)
|
|
131
|
+
instance = constant(klass).new(content) rescue nil
|
|
132
|
+
|
|
133
|
+
return unless instance and instance.respond_to?(:render)
|
|
134
|
+
|
|
135
|
+
hash = demunge_passed_variables(params)
|
|
136
|
+
instance.instance_variable_set("@hash", hash)
|
|
137
|
+
|
|
138
|
+
instance.render
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# basically processes stuff like
|
|
142
|
+
# 'foo="bar" foobar="baz"'
|
|
143
|
+
# do NOT pass actual objects that cannot be simply read as a string
|
|
144
|
+
# here, the information will be lost.
|
|
145
|
+
#
|
|
146
|
+
# Exceptions are true, false, Integers and Floats. They will appear
|
|
147
|
+
# in their real form (this again is also valid for strings that contain
|
|
148
|
+
# these values in a way that makes Integer/Float possible to parse them)
|
|
149
|
+
#
|
|
150
|
+
# Just remember, walk like a duck, talk like a duck.
|
|
151
|
+
|
|
152
|
+
def demunge_passed_variables(string)
|
|
153
|
+
string.scan(/\s?(.*?)="(.*?)"/).inject({}) do |hash, (key, value)|
|
|
154
|
+
value =
|
|
155
|
+
case value
|
|
156
|
+
when 'true' : true
|
|
157
|
+
when 'false' : false
|
|
158
|
+
else
|
|
159
|
+
Integer(value) rescue Float(value) rescue value
|
|
160
|
+
end
|
|
161
|
+
hash.merge key => value
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
@@ -0,0 +1,156 @@
|
|
|
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
|
+
module Ramaze
|
|
5
|
+
|
|
6
|
+
# This applies a morphing-replace for the template.
|
|
7
|
+
#
|
|
8
|
+
# To use the functionality of Morpher you will need to have hpricot
|
|
9
|
+
# installed, you will get one error in case you don't and the method
|
|
10
|
+
# will be replaced by a stub that simply returns the template.
|
|
11
|
+
#
|
|
12
|
+
# The method first checks if you use any morphers and just skips
|
|
13
|
+
# the step if you don't, this should give quite some speedup for
|
|
14
|
+
# smaller templates that don't use this functionality at all.
|
|
15
|
+
# the check works by searching the morphs with appended '='
|
|
16
|
+
# in the template. There may be a few cases where this won't work
|
|
17
|
+
# since we cannot make any assumptions on the format.
|
|
18
|
+
#
|
|
19
|
+
# If you want to turn this functionality off, either remove Morpher
|
|
20
|
+
# from:
|
|
21
|
+
# Ramaze::Template::Ramaze.trait[:transform_pipeline]
|
|
22
|
+
# or do:
|
|
23
|
+
# Ramaze::Morpher.trait[:morphs] = {}
|
|
24
|
+
#
|
|
25
|
+
# The latter is a tad slower, but i mention the possibility in case you
|
|
26
|
+
# find good use for it.
|
|
27
|
+
#
|
|
28
|
+
# You can add your own morphers in Ramaze::Morpher.trait[:morphs]
|
|
29
|
+
#
|
|
30
|
+
# For Example:
|
|
31
|
+
#
|
|
32
|
+
# Morpher.trait[:morphs]['if'] = '<?r %morph %expression ?>%content<?r end ?>'
|
|
33
|
+
#
|
|
34
|
+
# Now, assuming that some tag in your template is '<a if="@foo">x</a>'
|
|
35
|
+
#
|
|
36
|
+
# %morph stands for the name of your morph: 'if'
|
|
37
|
+
# %expression is the stuff you write in the attribute: '@foo'
|
|
38
|
+
# %content is the tag without the attribute (and all inside): '<a>x</a>'
|
|
39
|
+
|
|
40
|
+
class Morpher
|
|
41
|
+
|
|
42
|
+
# Use this trait to define your custom morphs.
|
|
43
|
+
trait :morphs => {
|
|
44
|
+
'if' => '<?r %morph %expression ?>%content<?r end ?>',
|
|
45
|
+
'unless' => '<?r %morph %expression ?>%content<?r end ?>',
|
|
46
|
+
'for' => '<?r %morph %expression ?>%content<?r end ?>',
|
|
47
|
+
'each' => '<?r %expression.%morph do |_e| ?>%content<?r end ?>',
|
|
48
|
+
'times' => '<?r %expression.%morph do |_t| ?>%content<?r end ?>',
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
# Since the functionality is best explained by examples, here they come.
|
|
52
|
+
#
|
|
53
|
+
# Example:
|
|
54
|
+
#
|
|
55
|
+
# if:
|
|
56
|
+
# <div if="@name">#@name</div>
|
|
57
|
+
# morphs to:
|
|
58
|
+
# <?r if @name ?>
|
|
59
|
+
# <div>#@name</div>
|
|
60
|
+
# <?r end ?>
|
|
61
|
+
#
|
|
62
|
+
# unless:
|
|
63
|
+
# <div unless="@name">No Name</div>
|
|
64
|
+
# morphs to:
|
|
65
|
+
# <?r unless @name ?>
|
|
66
|
+
# <div>No Name</div>
|
|
67
|
+
# <?r end ?>
|
|
68
|
+
#
|
|
69
|
+
# for:
|
|
70
|
+
# <div for="name in @names">#{name}</div>
|
|
71
|
+
# morphs to:
|
|
72
|
+
# <?r for name in @names ?>
|
|
73
|
+
# <div>#{name}</div>
|
|
74
|
+
# <?r end ?>
|
|
75
|
+
#
|
|
76
|
+
# times:
|
|
77
|
+
# <div times="3">#{_t}<div>
|
|
78
|
+
# morphs to:
|
|
79
|
+
# <?r 3.times do |_t| ?>
|
|
80
|
+
# <div>#{_t}</div>
|
|
81
|
+
# <?r end ?>
|
|
82
|
+
#
|
|
83
|
+
# each:
|
|
84
|
+
# <div each="[1,2,3]">#{_e}</div>
|
|
85
|
+
# morphs to:
|
|
86
|
+
# <?r [1,2,3].each do |_e| ?>
|
|
87
|
+
# <div>#{_e}</div>
|
|
88
|
+
# <?r end ?>
|
|
89
|
+
#
|
|
90
|
+
# The latter two examples show you also one standard introduced by a
|
|
91
|
+
# limitation of the replacement-system.
|
|
92
|
+
#
|
|
93
|
+
# When you yield a value, please name it by the first character(s) of
|
|
94
|
+
# the morphs name, with an underscore prefixed.
|
|
95
|
+
#
|
|
96
|
+
# for each an _e, for times a _t.
|
|
97
|
+
#
|
|
98
|
+
# This is by far not the best way to handle it and might lead to problems
|
|
99
|
+
# due to the lack of proper scoping in ruby (if you define an _e or _t
|
|
100
|
+
# before the block it will be overwritten).
|
|
101
|
+
#
|
|
102
|
+
# So please be careful, I tried to come up with something that is both easy
|
|
103
|
+
# to write and doesn't look outright awful while keeping an easy to remember
|
|
104
|
+
# mnemonic.
|
|
105
|
+
#
|
|
106
|
+
# TODO:
|
|
107
|
+
# - Add pure Ruby implementation as a fall-back.
|
|
108
|
+
|
|
109
|
+
def self.transform template, bound = nil
|
|
110
|
+
morphs =
|
|
111
|
+
trait[:morphs].map{|k,v| [k.to_s, v.to_s]}.select do |(k,v)|
|
|
112
|
+
template.to_s.include?("#{k}=")
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
morphs = Hash[*morphs.flatten]
|
|
116
|
+
|
|
117
|
+
return template if morphs.empty?
|
|
118
|
+
|
|
119
|
+
require 'hpricot'
|
|
120
|
+
|
|
121
|
+
hp = Hpricot(template)
|
|
122
|
+
hp.each_child do |child|
|
|
123
|
+
if child.elem?
|
|
124
|
+
morphs.each_pair do |morph, replacement|
|
|
125
|
+
if expression = child[morph]
|
|
126
|
+
old = child.to_html
|
|
127
|
+
child.remove_attribute(morph)
|
|
128
|
+
|
|
129
|
+
replacement = replacement.dup.
|
|
130
|
+
gsub('%morph', morph).
|
|
131
|
+
gsub('%expression', expression).
|
|
132
|
+
gsub('%content', child.to_html)
|
|
133
|
+
|
|
134
|
+
template.gsub!(old, replacement)
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
template
|
|
141
|
+
|
|
142
|
+
rescue LoadError => ex
|
|
143
|
+
error "Please install hpricot (for example via `gem install hpricot`) to get morphing"
|
|
144
|
+
|
|
145
|
+
# replace this method with a stub that only returns the template.
|
|
146
|
+
|
|
147
|
+
self.class_eval do
|
|
148
|
+
def self.transform(template, bound = nil)
|
|
149
|
+
template
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
template
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
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 'fileutils'
|
|
5
|
+
require 'yaml'
|
|
6
|
+
|
|
7
|
+
module Ramaze
|
|
8
|
+
module Tool
|
|
9
|
+
|
|
10
|
+
# Create is a simple class used to create new projects based on the proto
|
|
11
|
+
# directory.
|
|
12
|
+
#
|
|
13
|
+
# It is primarly used for this command:
|
|
14
|
+
#
|
|
15
|
+
# ramaze --create project
|
|
16
|
+
#
|
|
17
|
+
# where project is the directory you want the content put into.
|
|
18
|
+
|
|
19
|
+
class Create
|
|
20
|
+
class << self
|
|
21
|
+
|
|
22
|
+
# a method to create a new project by copying the contents of lib/proto
|
|
23
|
+
# to the position you specify (project)
|
|
24
|
+
#
|
|
25
|
+
# It is just a nice wrapper showing you what files/directories are put
|
|
26
|
+
# in place.
|
|
27
|
+
|
|
28
|
+
def create project
|
|
29
|
+
@basedir = ::Ramaze::BASEDIR / 'proto'
|
|
30
|
+
@destdir = Dir.pwd / project
|
|
31
|
+
|
|
32
|
+
puts "creating project: #{project}"
|
|
33
|
+
|
|
34
|
+
FileUtils.mkdir_p(project)
|
|
35
|
+
|
|
36
|
+
puts "copy proto to new project (#@destdir)..."
|
|
37
|
+
|
|
38
|
+
directories, files =
|
|
39
|
+
Dir[@basedir / '**' / '*'].partition{|f| File.directory?(f) }
|
|
40
|
+
|
|
41
|
+
create_dirs(*directories)
|
|
42
|
+
copy_files(*files)
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# create the directories recursivly
|
|
47
|
+
|
|
48
|
+
def create_dirs(*dirs)
|
|
49
|
+
dirs.each do |dir|
|
|
50
|
+
dest = dir.gsub(@basedir, @destdir)
|
|
51
|
+
|
|
52
|
+
puts "create directory: '#{dest}'"
|
|
53
|
+
FileUtils.mkdir_p(dest)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# copy the files over
|
|
58
|
+
|
|
59
|
+
def copy_files(*files)
|
|
60
|
+
files.each do |file|
|
|
61
|
+
dest = file.gsub(@basedir, @destdir)
|
|
62
|
+
|
|
63
|
+
puts "copy file: '#{dest}'"
|
|
64
|
+
FileUtils.cp(file, dest)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
module Ramaze
|
|
5
|
+
module Tool
|
|
6
|
+
|
|
7
|
+
# This is a simple tool to tidy up your html-output
|
|
8
|
+
# in general this is just used by setting Global.tidy = true
|
|
9
|
+
|
|
10
|
+
module Tidy
|
|
11
|
+
|
|
12
|
+
# set this to define a custom path to your tidy.so
|
|
13
|
+
trait[:path] ||= `locate libtidy.so`.strip
|
|
14
|
+
|
|
15
|
+
# dirty html in, tidy html out
|
|
16
|
+
# To activate Tidy for everything outgoing (given that it is of
|
|
17
|
+
# Content-Type text/html) set
|
|
18
|
+
# Global.tidy = true
|
|
19
|
+
# there is almost no speed-tradeoff but makes debugging a much
|
|
20
|
+
# nicer experience ;)
|
|
21
|
+
#
|
|
22
|
+
# Example:
|
|
23
|
+
#
|
|
24
|
+
# include Ramaze::Tool::Tidy
|
|
25
|
+
# puts tidy('<html></html>')
|
|
26
|
+
#
|
|
27
|
+
# # results in something like:
|
|
28
|
+
#
|
|
29
|
+
# <html>
|
|
30
|
+
# <head>
|
|
31
|
+
# <meta name="generator" content="HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org" />
|
|
32
|
+
# <title></title>
|
|
33
|
+
# </head>
|
|
34
|
+
# <body></body>
|
|
35
|
+
# </html>
|
|
36
|
+
|
|
37
|
+
def self.tidy html, options = {}
|
|
38
|
+
require 'tidy'
|
|
39
|
+
|
|
40
|
+
::Tidy.path = trait[:path]
|
|
41
|
+
|
|
42
|
+
defaults = {
|
|
43
|
+
:output_xml => true,
|
|
44
|
+
:input_encoding => :utf8,
|
|
45
|
+
:output_encoding => :utf8,
|
|
46
|
+
:indent_spaces => 2,
|
|
47
|
+
:indent => :auto,
|
|
48
|
+
:markup => :yes,
|
|
49
|
+
:wrap => 500
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
::Tidy.open(:show_warnings => true) do |tidy|
|
|
53
|
+
defaults.merge(options).each do |key, value|
|
|
54
|
+
tidy.options.send("#{key}=", value.to_s)
|
|
55
|
+
end
|
|
56
|
+
tidy.clean(html)
|
|
57
|
+
end
|
|
58
|
+
rescue LoadError => ex
|
|
59
|
+
puts ex
|
|
60
|
+
puts "cannot load 'tidy', please `gem install tidy`"
|
|
61
|
+
puts "you can find it at http://tidy.rubyforge.org/"
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# calls self#tidy
|
|
65
|
+
|
|
66
|
+
def tidy html, options = {}
|
|
67
|
+
Ramaze::Tool::Tidy.tidy(html, options)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|