ramaze 2011.01.30 → 2011.07.25
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/.gitignore +2 -1
- data/.mailmap +2 -0
- data/.rvmrc +1 -0
- data/README.md +119 -197
- data/Rakefile +14 -97
- data/bin/ramaze +6 -14
- data/doc/AUTHORS +8 -4
- data/doc/CHANGELOG +3784 -3339
- data/examples/app/chat/start.rb +2 -2
- data/lib/proto/app.rb +2 -3
- data/lib/proto/config.ru +4 -5
- data/lib/proto/controller/init.rb +11 -4
- data/lib/proto/controller/main.rb +12 -7
- data/lib/proto/layout/default.xhtml +56 -23
- data/lib/proto/model/init.rb +3 -1
- data/lib/proto/public/css/grid.css +107 -0
- data/lib/proto/public/css/layout.css +81 -0
- data/lib/proto/public/css/reset.css +123 -0
- data/lib/proto/public/css/text.css +109 -0
- data/lib/proto/public/images/bg.png +0 -0
- data/lib/proto/spec/main.rb +2 -2
- data/lib/proto/start.rb +11 -1
- data/lib/proto/view/index.xhtml +27 -23
- data/lib/ramaze.rb +0 -1
- data/lib/ramaze/app.rb +85 -12
- data/lib/ramaze/app_graph.rb +107 -0
- data/lib/ramaze/bin/console.rb +87 -0
- data/lib/ramaze/bin/create.rb +94 -0
- data/lib/ramaze/bin/helper.rb +107 -0
- data/lib/ramaze/bin/restart.rb +95 -0
- data/lib/ramaze/bin/runner.rb +141 -0
- data/lib/ramaze/bin/start.rb +206 -0
- data/lib/ramaze/bin/status.rb +152 -0
- data/lib/ramaze/bin/stop.rb +112 -0
- data/lib/ramaze/cache.rb +9 -4
- data/lib/ramaze/cache/localmemcache.rb +10 -13
- data/lib/ramaze/cache/lru.rb +49 -7
- data/lib/ramaze/cache/memcache.rb +170 -92
- data/lib/ramaze/cache/sequel.rb +301 -118
- data/lib/ramaze/controller.rb +108 -9
- data/lib/ramaze/controller/default.rb +15 -2
- data/lib/ramaze/current.rb +14 -2
- data/lib/ramaze/dependencies.rb +46 -0
- data/lib/ramaze/files.rb +38 -3
- data/lib/ramaze/gestalt.rb +12 -12
- data/lib/ramaze/helper.rb +0 -2
- data/lib/ramaze/helper/auth.rb +30 -23
- data/lib/ramaze/helper/blue_form.rb +175 -126
- data/lib/ramaze/helper/csrf.rb +76 -91
- data/lib/ramaze/helper/email.rb +105 -0
- data/lib/ramaze/helper/erector.rb +16 -15
- data/lib/ramaze/helper/gestalt.rb +2 -2
- data/lib/ramaze/helper/layout.rb +89 -73
- data/lib/ramaze/helper/link.rb +7 -6
- data/lib/ramaze/helper/localize.rb +6 -5
- data/lib/ramaze/helper/markaby.rb +25 -23
- data/lib/ramaze/helper/maruku.rb +3 -3
- data/lib/ramaze/helper/paginate.rb +19 -27
- data/lib/ramaze/helper/remarkably.rb +3 -3
- data/lib/ramaze/helper/request_accessor.rb +3 -3
- data/lib/ramaze/helper/send_file.rb +12 -8
- data/lib/ramaze/helper/simple_captcha.rb +5 -6
- data/lib/ramaze/helper/stack.rb +7 -4
- data/lib/ramaze/helper/tagz.rb +10 -11
- data/lib/ramaze/helper/thread.rb +19 -16
- data/lib/ramaze/helper/ultraviolet.rb +7 -4
- data/lib/ramaze/helper/user.rb +40 -21
- data/lib/ramaze/helper/xhtml.rb +29 -20
- data/lib/ramaze/log.rb +3 -11
- data/lib/ramaze/log/analogger.rb +5 -4
- data/lib/ramaze/log/growl.rb +9 -7
- data/lib/ramaze/log/hub.rb +3 -5
- data/lib/ramaze/log/informer.rb +15 -12
- data/lib/ramaze/log/knotify.rb +3 -5
- data/lib/ramaze/log/logger.rb +3 -5
- data/lib/ramaze/log/logging.rb +6 -8
- data/lib/ramaze/log/rotatinginformer.rb +27 -17
- data/lib/ramaze/log/syslog.rb +7 -7
- data/lib/ramaze/log/xosd.rb +3 -5
- data/lib/ramaze/middleware_compiler.rb +27 -4
- data/lib/ramaze/reloader.rb +50 -12
- data/lib/ramaze/reloader/watch_inotify.rb +4 -5
- data/lib/ramaze/reloader/watch_stat.rb +3 -3
- data/lib/ramaze/request.rb +18 -8
- data/lib/ramaze/response.rb +38 -7
- data/lib/ramaze/rest.rb +36 -0
- data/lib/ramaze/setup.rb +101 -31
- data/lib/ramaze/spec.rb +1 -1
- data/lib/ramaze/spec/bacon.rb +6 -3
- data/lib/ramaze/spec/helper/bacon.rb +0 -1
- data/lib/ramaze/version.rb +1 -1
- data/lib/ramaze/view.rb +2 -11
- data/lib/ramaze/view/erector.rb +46 -31
- data/lib/ramaze/view/erubis.rb +7 -3
- data/lib/ramaze/view/ezamar.rb +7 -3
- data/lib/ramaze/view/gestalt.rb +9 -3
- data/lib/ramaze/view/haml.rb +7 -3
- data/lib/ramaze/view/liquid.rb +3 -3
- data/lib/ramaze/view/lokar.rb +7 -3
- data/lib/ramaze/view/mustache.rb +11 -5
- data/lib/ramaze/view/nagoro.rb +3 -3
- data/lib/ramaze/view/sass.rb +1 -1
- data/lib/ramaze/view/slippers.rb +40 -13
- data/lib/ramaze/view/tagz.rb +9 -5
- data/ramaze.gemspec +23 -128
- data/spec/helper.rb +5 -0
- data/spec/ramaze/bin/app/config.ru +11 -0
- data/spec/ramaze/bin/create.rb +28 -0
- data/spec/ramaze/bin/runner.rb +30 -0
- data/spec/ramaze/bin/start.rb +38 -0
- data/spec/ramaze/cache/memcache.rb +10 -3
- data/spec/ramaze/cache/sequel.rb +7 -0
- data/spec/ramaze/controller/provide_inheritance.rb +0 -10
- data/spec/ramaze/dispatcher/file.rb +19 -15
- data/spec/ramaze/helper/auth.rb +10 -9
- data/spec/ramaze/helper/blue_form.rb +121 -68
- data/spec/ramaze/helper/email.rb +69 -0
- data/spec/ramaze/helper/layout.rb +12 -15
- data/spec/ramaze/helper/layout/alternative.xhtml +5 -0
- data/spec/ramaze/helper/user.rb +2 -0
- data/spec/ramaze/log/growl.rb +14 -1
- data/spec/{contrib → ramaze}/rest.rb +1 -1
- data/spec/ramaze/session/memcache.rb +2 -2
- data/spec/ramaze/view/sass.rb +1 -1
- data/tasks/bacon.rake +3 -3
- data/tasks/gem.rake +17 -18
- data/tasks/rcov.rake +2 -3
- data/tasks/release.rake +8 -65
- data/tasks/setup.rake +10 -8
- data/tasks/todo.rake +9 -5
- data/tasks/yard.rake +3 -2
- metadata +105 -397
- data/MANIFEST +0 -532
- data/TODO.md +0 -19
- data/benchmark/bench_templates/bench.rb +0 -67
- data/benchmark/bench_templates/view/large.erb +0 -79
- data/benchmark/bench_templates/view/large.haml +0 -41
- data/benchmark/bench_templates/view/large.lok +0 -79
- data/benchmark/bench_templates/view/large.xhtml +0 -79
- data/benchmark/bench_templates/view/small.erb +0 -21
- data/benchmark/bench_templates/view/small.haml +0 -12
- data/benchmark/bench_templates/view/small.lok +0 -21
- data/benchmark/bench_templates/view/small.xhtml +0 -21
- data/benchmark/results.txt +0 -131
- data/benchmark/run.rb +0 -355
- data/benchmark/suite/minimal.rb +0 -11
- data/benchmark/suite/no_informer.rb +0 -7
- data/benchmark/suite/no_sessions.rb +0 -9
- data/benchmark/suite/no_template.rb +0 -7
- data/benchmark/suite/simple.rb +0 -5
- data/benchmark/suite/template_erubis.rb +0 -8
- data/benchmark/suite/template_etanni.rb +0 -8
- data/benchmark/suite/template_ezamar.rb +0 -8
- data/benchmark/suite/template_haml.rb +0 -13
- data/benchmark/suite/template_liquid.rb +0 -11
- data/benchmark/suite/template_markaby.rb +0 -9
- data/benchmark/suite/template_nagoro.rb +0 -8
- data/benchmark/suite/template_redcloth.rb +0 -13
- data/benchmark/suite/template_tenjin.rb +0 -8
- data/benchmark/test.rb +0 -35
- data/doc/FAQ +0 -92
- data/doc/INSTALL +0 -92
- data/doc/TODO +0 -29
- data/doc/meta/announcement.txt +0 -119
- data/doc/meta/configuration.txt +0 -163
- data/doc/meta/internals.txt +0 -278
- data/doc/meta/users.kml +0 -64
- data/doc/tutorial/todolist.html +0 -1512
- data/doc/tutorial/todolist.txt +0 -920
- data/examples/app/sourceview/public/coderay.css +0 -104
- data/examples/app/sourceview/public/images/file.gif +0 -0
- data/examples/app/sourceview/public/images/folder.gif +0 -0
- data/examples/app/sourceview/public/images/tv-collapsable-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-collapsable.gif +0 -0
- data/examples/app/sourceview/public/images/tv-expandable-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-expandable.gif +0 -0
- data/examples/app/sourceview/public/images/tv-item-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-item.gif +0 -0
- data/examples/app/sourceview/public/jquery.js +0 -11
- data/examples/app/sourceview/public/jquery.treeview.css +0 -48
- data/examples/app/sourceview/public/jquery.treeview.js +0 -223
- data/examples/app/sourceview/public/sourceview.js +0 -52
- data/examples/app/sourceview/start.rb +0 -79
- data/examples/app/sourceview/view/index.haml +0 -59
- data/examples/helpers/httpdigest.rb +0 -107
- data/lib/proto/public/css/screen.css +0 -30
- data/lib/proto/public/js/jquery.js +0 -7179
- data/lib/ramaze/contrib/addressable_route.rb +0 -56
- data/lib/ramaze/contrib/app_graph.rb +0 -64
- data/lib/ramaze/contrib/email.rb +0 -88
- data/lib/ramaze/contrib/facebook.rb +0 -23
- data/lib/ramaze/contrib/facebook/facebook.rb +0 -171
- data/lib/ramaze/contrib/gettext.rb +0 -113
- data/lib/ramaze/contrib/gettext/mo.rb +0 -155
- data/lib/ramaze/contrib/gettext/parser.rb +0 -46
- data/lib/ramaze/contrib/gettext/po.rb +0 -109
- data/lib/ramaze/contrib/gzip_filter.rb +0 -1
- data/lib/ramaze/contrib/maruku_uv.rb +0 -59
- data/lib/ramaze/contrib/profiling.rb +0 -36
- data/lib/ramaze/contrib/rest.rb +0 -23
- data/lib/ramaze/contrib/sequel/create_join.rb +0 -26
- data/lib/ramaze/contrib/sequel/form_field.rb +0 -129
- data/lib/ramaze/contrib/sequel/image.rb +0 -196
- data/lib/ramaze/contrib/sequel/relation.rb +0 -98
- data/lib/ramaze/helper/httpdigest.rb +0 -96
- data/lib/ramaze/tool/bin.rb +0 -340
- data/lib/ramaze/tool/create.rb +0 -48
- data/lib/ramaze/tool/project_creator.rb +0 -120
- data/lib/ramaze/view/less.rb +0 -12
- data/lib/ramaze/view/maruku.rb +0 -15
- data/lib/ramaze/view/redcloth.rb +0 -21
- data/spec/contrib/addressable_route.rb +0 -30
- data/spec/examples/helpers/httpdigest.rb +0 -64
- data/spec/examples/templates/template_redcloth.rb +0 -13
- data/spec/ramaze/bin/ramaze.rb +0 -96
- data/spec/ramaze/helper/httpdigest.rb +0 -176
- data/spec/ramaze/view/less.rb +0 -60
- data/spec/ramaze/view/less/file.css.less +0 -8
- data/spec/ramaze/view/redcloth.rb +0 -66
- data/spec/ramaze/view/redcloth/external.redcloth +0 -8
- data/tasks/copyright.rake +0 -21
- data/tasks/gem_setup.rake +0 -112
- data/tasks/git.rake +0 -46
- data/tasks/grancher.rake +0 -12
- data/tasks/jquery.rake +0 -15
- data/tasks/manifest.rake +0 -4
- data/tasks/metric_changes.rake +0 -24
- data/tasks/reversion.rake +0 -8
- data/tasks/traits.rake +0 -21
data/lib/ramaze/helper/layout.rb
CHANGED
|
@@ -1,97 +1,113 @@
|
|
|
1
1
|
module Ramaze
|
|
2
2
|
module Helper
|
|
3
|
-
|
|
3
|
+
##
|
|
4
4
|
# Provides wrapper methods for a higher-level approach than the core layout
|
|
5
|
-
# method.
|
|
5
|
+
# method. The layout() method that comes with Innate/Ramaze is fairly basic
|
|
6
|
+
# as it only allows you to specify a single layout to always use or a block
|
|
7
|
+
# giving you some extra flexibility. The latter however is still a bit of a
|
|
8
|
+
# pain when dealing with many custom layouts in a single controller. Meet
|
|
9
|
+
# the Layout helper. This helper provides a single method (since April 2011,
|
|
10
|
+
# it used to provide more) called "set_layout". This method allows you to
|
|
11
|
+
# specify a number of layouts and the methods for which these layouts should
|
|
12
|
+
# be used.
|
|
13
|
+
#
|
|
14
|
+
# == Examples
|
|
15
|
+
#
|
|
16
|
+
# The most basic example is simply setting a layout as you would do with the
|
|
17
|
+
# layout() method:
|
|
18
|
+
#
|
|
19
|
+
# set_layout 'default'
|
|
6
20
|
#
|
|
7
|
-
#
|
|
8
|
-
# * layout a whitelist of actions
|
|
9
|
-
# * layout all but a blacklist of actions
|
|
21
|
+
# This of course is very boring, time to add some more spices to our code:
|
|
10
22
|
#
|
|
11
|
-
#
|
|
12
|
-
# controller on which they are applied. Furthermore, multiple layout
|
|
13
|
-
# definitions are not combined; only the last definition will be used.
|
|
23
|
+
# set_layout 'default' => [:index]
|
|
14
24
|
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
25
|
+
# Woah! What just happened? It's quite easy actually, we merely defined that
|
|
26
|
+
# the layout called "default" should be used for the index method *only*.
|
|
27
|
+
# Pretty sweet huh? It gets even better:
|
|
17
28
|
#
|
|
18
|
-
#
|
|
29
|
+
# set_layout 'default' => [:index, :edit], 'alternative' => [:add, :process]
|
|
19
30
|
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
# def action2; end
|
|
26
|
-
# def action3; end
|
|
27
|
-
# end
|
|
31
|
+
# A few things changed. First of all there are now two key/value groups.
|
|
32
|
+
# Each group defines a layout (the key) and a set of methods (the value) for
|
|
33
|
+
# which each layout should be used. In this case the layout "default" will
|
|
34
|
+
# be used for index() and edit() but the layout "alternative" will be used
|
|
35
|
+
# for add() and process().
|
|
28
36
|
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
#
|
|
33
|
-
# set_layout_except 'default' => [:not_laid_out1, :not_laid_out2]
|
|
37
|
+
# Last but not least, multiple calls to set_layout will no longer override
|
|
38
|
+
# any existing settings *unless* you actually specify the same method with a
|
|
39
|
+
# different layout. This is possible because the set_layout method stores
|
|
40
|
+
# all these details in an instance variable called "_ramaze_layouts".
|
|
34
41
|
#
|
|
35
|
-
#
|
|
36
|
-
#
|
|
42
|
+
# @author Yorick Peterse
|
|
43
|
+
# @author Michael Fellinger
|
|
44
|
+
# @author Pistos
|
|
37
45
|
#
|
|
38
|
-
# def not_laid_out1; end
|
|
39
|
-
# def not_laid_out2; end
|
|
40
|
-
# end
|
|
41
46
|
module Layout
|
|
47
|
+
|
|
48
|
+
##
|
|
49
|
+
# Extends the class that included this module so that the methods that
|
|
50
|
+
# this helper provides can be called outside of instance of class methods.
|
|
51
|
+
#
|
|
52
|
+
# @param [Object] into The class that included this module.
|
|
53
|
+
# @author Michael Fellinger
|
|
54
|
+
# @author Pistos
|
|
55
|
+
#
|
|
42
56
|
def self.included(into)
|
|
43
57
|
into.extend SingletonMethods
|
|
44
58
|
end
|
|
45
59
|
|
|
46
60
|
module SingletonMethods
|
|
47
|
-
|
|
48
|
-
#
|
|
49
|
-
#
|
|
50
|
-
#
|
|
51
|
-
#
|
|
52
|
-
# @example
|
|
53
|
-
#
|
|
54
|
-
#
|
|
55
|
-
#
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
##
|
|
62
|
+
# The set_layout method allows you to specify a number of methods and
|
|
63
|
+
# their layout. This allows you to use layout A for methods 1, 2 and 3
|
|
64
|
+
# but layout B for method 4.
|
|
65
|
+
#
|
|
66
|
+
# @example
|
|
67
|
+
# # The key is the layout, the value an array of methods
|
|
68
|
+
# set_layout 'default' => [:method_1], 'alternative' => [:method_2]
|
|
69
|
+
#
|
|
70
|
+
# # We can combine this method with layout()
|
|
71
|
+
# layout 'default'
|
|
72
|
+
# set_layout 'alternative' => [:method_1]
|
|
73
|
+
#
|
|
74
|
+
# # This is also perfectly fine
|
|
75
|
+
# set_layout 'default'
|
|
76
|
+
#
|
|
77
|
+
# @param [String, Symbol, #to_hash] hash_or_layout
|
|
78
|
+
# In case it's a String or Symbol it will directly be used as the
|
|
79
|
+
# layout.
|
|
80
|
+
# When setting a Hash this hash should have it's keys set to the
|
|
81
|
+
# layouts and it's values to an array of methods that use the
|
|
82
|
+
# specific layout. For more information see the examples.
|
|
83
|
+
#
|
|
84
|
+
# @author Yorick Peterse
|
|
85
|
+
# @author Michael Fellinger
|
|
86
|
+
# @author Pistos
|
|
87
|
+
# @since 2011-04-07
|
|
88
|
+
def set_layout(hash_or_layout)
|
|
89
|
+
@_ramaze_layouts ||= {}
|
|
64
90
|
|
|
65
|
-
layout
|
|
66
|
-
|
|
67
|
-
|
|
91
|
+
# Extract the layout to use
|
|
92
|
+
if hash_or_layout.respond_to?(:to_hash)
|
|
93
|
+
# Invert the method/layout hash and save them so they don't get lost
|
|
94
|
+
hash_or_layout.to_hash.each do |layout, layout_methods|
|
|
95
|
+
layout_methods.each do |layout_method|
|
|
96
|
+
@_ramaze_layouts[layout_method.to_s] = layout.to_s
|
|
97
|
+
end
|
|
68
98
|
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
99
|
|
|
72
|
-
|
|
73
|
-
# which maps a layout name to an Array containing a blacklist of
|
|
74
|
-
# action names
|
|
75
|
-
# @see set_layout Innate::Node::layout
|
|
76
|
-
# @author Pistos, manveru
|
|
77
|
-
# @example Use a layout named 'default' on all actions except the user_data action:
|
|
78
|
-
# set_layout_except 'default' => [ :user_data ]
|
|
79
|
-
def set_layout_except(hash_or_the_layout)
|
|
80
|
-
if hash_or_the_layout.respond_to?(:to_hash)
|
|
81
|
-
f = hash_or_the_layout.to_hash.find{|k,v| k && v }
|
|
82
|
-
the_layout = f[0]
|
|
83
|
-
blacklist = f[1].map{|action| action.to_s }
|
|
100
|
+
layout{|path| @_ramaze_layouts[path.to_s] }
|
|
84
101
|
else
|
|
85
|
-
|
|
102
|
+
layout{|path| hash_or_layout }
|
|
86
103
|
end
|
|
104
|
+
end
|
|
87
105
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
end
|
|
92
|
-
end
|
|
106
|
+
# @deprecated because it's not longer useful
|
|
107
|
+
def set_layout_except(hash_or_layout)
|
|
108
|
+
Ramaze.deprecated('set_layout_except', 'set_layout')
|
|
93
109
|
end
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
end
|
|
110
|
+
end # SingletonMethods
|
|
111
|
+
end # Layout
|
|
112
|
+
end # Helper
|
|
113
|
+
end # Ramaze
|
data/lib/ramaze/helper/link.rb
CHANGED
|
@@ -16,9 +16,10 @@ module Ramaze
|
|
|
16
16
|
[prefix, location].join('/')
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
#
|
|
21
|
-
#
|
|
19
|
+
##
|
|
20
|
+
# Give it a path with character to split at and one to join the crumbs
|
|
21
|
+
# with. It will generate a list of links that act as pointers to previous
|
|
22
|
+
# pages on this path.
|
|
22
23
|
#
|
|
23
24
|
# @example usage
|
|
24
25
|
# breadcrumbs('/path/to/somewhere')
|
|
@@ -51,6 +52,6 @@ module Ramaze
|
|
|
51
52
|
end
|
|
52
53
|
bread.join(join)
|
|
53
54
|
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
55
|
+
end # Link
|
|
56
|
+
end # Helper
|
|
57
|
+
end # Ramaze
|
|
@@ -4,8 +4,9 @@ require 'locale'
|
|
|
4
4
|
module Ramaze
|
|
5
5
|
module Helper
|
|
6
6
|
##
|
|
7
|
-
# The localization helper can be used to output translated strings.
|
|
8
|
-
#
|
|
7
|
+
# The localization helper can be used to output translated strings. This
|
|
8
|
+
# enables your application to use multiple language files for English, Dutch
|
|
9
|
+
# and so on.
|
|
9
10
|
#
|
|
10
11
|
module Localize
|
|
11
12
|
include Traited
|
|
@@ -137,6 +138,6 @@ module Ramaze
|
|
|
137
138
|
::Locale::Tag.parse(lang) }
|
|
138
139
|
end
|
|
139
140
|
end
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
end
|
|
141
|
+
end # Localize
|
|
142
|
+
end # Helper
|
|
143
|
+
end # Ramaze
|
|
@@ -2,30 +2,32 @@
|
|
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
3
|
|
|
4
4
|
module Ramaze
|
|
5
|
+
module Helper
|
|
6
|
+
# Allows you to use some shortcuts for markaby in your Controller.
|
|
7
|
+
module Markaby
|
|
8
|
+
##
|
|
9
|
+
# use this inside your controller to directly build Markaby
|
|
10
|
+
# Refer to the Markaby-documentation and testsuite for more examples.
|
|
11
|
+
#
|
|
12
|
+
# @example
|
|
13
|
+
# mab { h1 "Apples & Oranges"} #=> "<h1>Apples & Oranges</h1>"
|
|
14
|
+
# mab { h1 'Apples', :class => 'fruits&floots' }
|
|
15
|
+
#
|
|
16
|
+
def markaby(ivs = {}, helpers = nil, &block)
|
|
17
|
+
builder = ::Markaby::Builder
|
|
18
|
+
builder.extend(Ramaze::Helper::Methods)
|
|
19
|
+
builder.send(:helper, :link)
|
|
5
20
|
|
|
6
|
-
|
|
21
|
+
iv_hash = {}
|
|
22
|
+
instance_variables.each do |iv|
|
|
23
|
+
key, value = iv.gsub('@', '').to_sym, instance_variable_get(iv)
|
|
24
|
+
iv_hash[key] = value
|
|
25
|
+
end
|
|
7
26
|
|
|
8
|
-
|
|
9
|
-
# use this inside your controller to directly build Markaby
|
|
10
|
-
# Refer to the Markaby-documentation and testsuite for more examples.
|
|
11
|
-
# Usage:
|
|
12
|
-
# mab { h1 "Apples & Oranges"} #=> "<h1>Apples & Oranges</h1>"
|
|
13
|
-
# mab { h1 'Apples', :class => 'fruits&floots' } #=> "<h1 class=\"fruits&floots\">Apples</h1>"
|
|
14
|
-
|
|
15
|
-
def markaby(ivs = {}, helpers = nil, &block)
|
|
16
|
-
builder = ::Markaby::Builder
|
|
17
|
-
builder.extend(Ramaze::Helper::Methods)
|
|
18
|
-
builder.send(:helper, :link)
|
|
19
|
-
|
|
20
|
-
iv_hash = {}
|
|
21
|
-
instance_variables.each do |iv|
|
|
22
|
-
key, value = iv.gsub('@', '').to_sym, instance_variable_get(iv)
|
|
23
|
-
iv_hash[key] = value
|
|
27
|
+
builder.new(iv_hash.merge(ivs), helpers, &block).to_s
|
|
24
28
|
end
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
end
|
|
31
|
-
end
|
|
30
|
+
alias mab markaby
|
|
31
|
+
end # Markaby
|
|
32
|
+
end # Helper
|
|
33
|
+
end # Ramaze
|
data/lib/ramaze/helper/maruku.rb
CHANGED
|
@@ -2,23 +2,21 @@ require 'ramaze/gestalt'
|
|
|
2
2
|
|
|
3
3
|
module Ramaze
|
|
4
4
|
module Helper
|
|
5
|
-
|
|
6
5
|
# Helper for pagination and pagination-navigation.
|
|
7
6
|
#
|
|
8
7
|
# See detailed API docs for Paginator below.
|
|
9
8
|
# Also have a look at the examples/helpers/paginate.rb
|
|
10
|
-
|
|
11
9
|
module Paginate
|
|
12
10
|
include Traited
|
|
13
11
|
|
|
14
12
|
# Define default options in your Controller, they are being retrieved by
|
|
15
13
|
# ancestral_trait, so you can also put it into a common superclass
|
|
16
|
-
|
|
17
14
|
trait :paginate => {
|
|
18
15
|
:limit => 10,
|
|
19
16
|
:var => 'pager',
|
|
20
17
|
}
|
|
21
18
|
|
|
19
|
+
##
|
|
22
20
|
# Returns a new Paginator instance.
|
|
23
21
|
#
|
|
24
22
|
# Note that the pagination relies on being inside a Ramaze request to
|
|
@@ -53,18 +51,17 @@ module Ramaze
|
|
|
53
51
|
# :page The page you are currently on, if not given it will be
|
|
54
52
|
# retrieved from current request variables. Defaults to 1 if
|
|
55
53
|
# neither exists.
|
|
56
|
-
|
|
54
|
+
#
|
|
57
55
|
def paginate(dataset, options = {})
|
|
58
56
|
options = ancestral_trait[:paginate].merge(options)
|
|
59
57
|
limit = options[:limit]
|
|
60
58
|
var = options[:var]
|
|
61
59
|
page = options[:page] || (request[var] || 1).to_i
|
|
62
|
-
|
|
60
|
+
|
|
63
61
|
Paginator.new(dataset, page, limit, var)
|
|
64
62
|
end
|
|
65
63
|
|
|
66
64
|
# Provides easy pagination and navigation
|
|
67
|
-
|
|
68
65
|
class Paginator
|
|
69
66
|
include Ramaze::Helper
|
|
70
67
|
helper :link, :cgi
|
|
@@ -76,6 +73,7 @@ module Ramaze
|
|
|
76
73
|
@pager = pager_for(data)
|
|
77
74
|
end
|
|
78
75
|
|
|
76
|
+
##
|
|
79
77
|
# Returns String with navigation div.
|
|
80
78
|
#
|
|
81
79
|
# This cannot be customized very nicely, but you can style it easily
|
|
@@ -100,8 +98,7 @@ module Ramaze
|
|
|
100
98
|
# <span class="next grey">></span>
|
|
101
99
|
# <span class="last grey">>></span>
|
|
102
100
|
# </div>
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
#
|
|
105
102
|
def navigation(limit = 8)
|
|
106
103
|
g = Ramaze::Gestalt.new
|
|
107
104
|
g.div :class => :pager do
|
|
@@ -140,24 +137,22 @@ module Ramaze
|
|
|
140
137
|
end
|
|
141
138
|
|
|
142
139
|
# Useful to omit pager if it's of no use.
|
|
143
|
-
|
|
144
140
|
def needed?
|
|
145
141
|
@pager.page_count > 1
|
|
146
142
|
end
|
|
147
143
|
|
|
148
144
|
# these methods are actually on the pager, but we def them here for
|
|
149
145
|
# convenience (method_missing in helper is evil and even slower)
|
|
150
|
-
|
|
151
|
-
def
|
|
152
|
-
def
|
|
153
|
-
def
|
|
154
|
-
def prev_page; @pager.prev_page; end
|
|
146
|
+
def page_count ; @pager.page_count ; end
|
|
147
|
+
def each(&block); @pager.each(&block); end
|
|
148
|
+
def first_page? ; @pager.first_page? ; end
|
|
149
|
+
def prev_page ; @pager.prev_page ; end
|
|
155
150
|
def current_page; @pager.current_page; end
|
|
156
|
-
def last_page; @pager.last_page; end
|
|
157
|
-
def last_page
|
|
158
|
-
def next_page; @pager.next_page; end
|
|
159
|
-
def empty
|
|
160
|
-
def count; @pager.count; end
|
|
151
|
+
def last_page ; @pager.last_page ; end
|
|
152
|
+
def last_page? ; @pager.last_page? ; end
|
|
153
|
+
def next_page ; @pager.next_page ; end
|
|
154
|
+
def empty? ; @pager.empty? ; end
|
|
155
|
+
def count ; @pager.count ; end
|
|
161
156
|
|
|
162
157
|
private
|
|
163
158
|
|
|
@@ -185,7 +180,6 @@ module Ramaze
|
|
|
185
180
|
end
|
|
186
181
|
|
|
187
182
|
# Wrapper for Array to behave like the Sequel pagination
|
|
188
|
-
|
|
189
183
|
class ArrayPager
|
|
190
184
|
def initialize(array, page, limit)
|
|
191
185
|
@array, @page, @limit = array, page, limit
|
|
@@ -257,10 +251,8 @@ module Ramaze
|
|
|
257
251
|
def empty?
|
|
258
252
|
size == 0
|
|
259
253
|
end
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
end
|
|
266
|
-
end
|
|
254
|
+
end # DataMapperPager
|
|
255
|
+
end # Paginator
|
|
256
|
+
end # Paginate
|
|
257
|
+
end # Helper
|
|
258
|
+
end # Ramaze
|
|
@@ -2,16 +2,20 @@ module Ramaze
|
|
|
2
2
|
module Helper
|
|
3
3
|
##
|
|
4
4
|
# The SendFile module can be used to stream a file to the user's computer.
|
|
5
|
-
# While the performance of the module isn't optimal it's convenient and
|
|
5
|
+
# While the performance of the module isn't optimal it's convenient and
|
|
6
|
+
# relatively easy to use.
|
|
6
7
|
#
|
|
7
8
|
module SendFile
|
|
8
9
|
##
|
|
9
10
|
# The send_file method streams the specified file to the user's browser.
|
|
10
11
|
#
|
|
11
|
-
# @param [String] filename The name or path to the file which will be
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
12
|
+
# @param [String] filename The name or path to the file which will be
|
|
13
|
+
# streamed to the user.
|
|
14
|
+
# @param [String] content_type The type of file we're dealing with. For
|
|
15
|
+
# example, if we want to stream a JPG image we'd set this variable to
|
|
16
|
+
# 'image/jpg'.
|
|
17
|
+
# @param [String] content_disposition Value for the Content-Disposition
|
|
18
|
+
# header.
|
|
15
19
|
#
|
|
16
20
|
def send_file(filename, content_type = nil, content_disposition = nil)
|
|
17
21
|
content_type ||= Rack::Mime.mime_type(::File.extname(filename))
|
|
@@ -25,6 +29,6 @@ module Ramaze
|
|
|
25
29
|
|
|
26
30
|
throw(:respond, response)
|
|
27
31
|
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
32
|
+
end # SendFile
|
|
33
|
+
end # Helper
|
|
34
|
+
end # Ramaze
|