manveru-ramaze 2009.04 → 2009.04.01

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/CHANGELOG +0 -405
  2. data/MANIFEST +16 -16
  3. data/Rakefile +4 -24
  4. data/bin/ramaze +52 -275
  5. data/doc/tutorial/todolist.html +5 -83
  6. data/doc/tutorial/todolist.txt +33 -85
  7. data/examples/app/auth/layout/{auth.xhtml → auth.nag} +0 -0
  8. data/examples/app/auth/view/{index.xhtml → index.nag} +0 -0
  9. data/examples/app/auth/view/{login.xhtml → login.nag} +0 -0
  10. data/examples/app/auth/view/{secret.xhtml → secret.nag} +0 -0
  11. data/examples/app/blog/app.rb +1 -1
  12. data/examples/app/blog/controller/comment.rb +1 -1
  13. data/examples/app/blog/controller/entry.rb +3 -12
  14. data/examples/app/blog/model/init.rb +0 -5
  15. data/examples/app/blog/model/tag.rb +2 -2
  16. data/examples/app/blog/start.rb +1 -1
  17. data/examples/app/blog/view/entry/index.nag +3 -3
  18. data/examples/app/blog/view/feed.atom.nag +1 -1
  19. data/examples/app/blog/view/feed.rss.nag +1 -1
  20. data/examples/app/blog/view/index.nag +1 -1
  21. data/examples/app/blog/view/tag/index.nag +1 -1
  22. data/examples/app/todolist/model/init.rb +0 -3
  23. data/examples/app/wikore/spec/wikore.rb +6 -4
  24. data/examples/app/wikore/src/controller.rb +11 -9
  25. data/examples/app/wikore/src/model.rb +10 -7
  26. data/examples/app/wikore/start.rb +1 -1
  27. data/examples/app/wikore/{view → template}/index.xhtml +0 -0
  28. data/examples/helpers/provide.rb +23 -0
  29. data/examples/misc/rapp.rb +17 -28
  30. data/examples/templates/template_redcloth.rb +2 -2
  31. data/examples/templates/template_xslt.rb +48 -0
  32. data/examples/templates/view/external.xsl +57 -0
  33. data/lib/proto/config.ru +5 -4
  34. data/lib/proto/controller/init.rb +2 -2
  35. data/lib/proto/layout/{default.xhtml → default.nag} +0 -0
  36. data/lib/proto/spec/main.rb +8 -7
  37. data/lib/proto/start.rb +10 -6
  38. data/lib/proto/view/{index.xhtml → index.nag} +0 -0
  39. data/lib/proto/view/page.nag +27 -0
  40. data/lib/ramaze/app.rb +5 -5
  41. data/lib/ramaze/cache.rb +2 -3
  42. data/lib/ramaze/contrib/email.rb +0 -2
  43. data/lib/ramaze/contrib/sequel/create_join.rb +0 -1
  44. data/lib/ramaze/contrib/sequel/fill.rb +12 -0
  45. data/lib/ramaze/contrib/sequel/form_field.rb +4 -4
  46. data/lib/ramaze/contrib/sequel/image.rb +11 -9
  47. data/lib/ramaze/contrib/sequel/relation.rb +3 -17
  48. data/lib/ramaze/controller/default.rb +0 -5
  49. data/lib/ramaze/helper/cache.rb +8 -22
  50. data/lib/ramaze/helper/formatting.rb +0 -2
  51. data/lib/ramaze/helper/httpdigest.rb +1 -1
  52. data/lib/ramaze/helper/link.rb +5 -2
  53. data/lib/ramaze/helper/localize.rb +3 -13
  54. data/lib/ramaze/helper/paginate.rb +0 -1
  55. data/lib/ramaze/helper/partial.rb +10 -85
  56. data/lib/ramaze/helper.rb +16 -6
  57. data/lib/ramaze/request.rb +1 -22
  58. data/lib/ramaze/snippets/ramaze/deprecated.rb +1 -0
  59. data/lib/ramaze/snippets/string/each.rb +19 -0
  60. data/lib/ramaze/spec.rb +2 -9
  61. data/lib/ramaze/version.rb +1 -1
  62. data/lib/ramaze/view/haml.rb +0 -1
  63. data/lib/ramaze/view/liquid.rb +11 -45
  64. data/lib/ramaze/view/nagoro/render_partial.rb +9 -9
  65. data/lib/ramaze/view.rb +0 -4
  66. data/lib/ramaze.rb +0 -2
  67. data/ramaze.gemspec +12 -12
  68. data/spec/contrib/sequel/fill.rb +47 -0
  69. data/spec/examples/helpers/httpdigest.rb +67 -42
  70. data/spec/examples/templates/template_markaby.rb +1 -1
  71. data/spec/examples/templates/template_xslt.rb +10 -0
  72. data/spec/ramaze/dispatcher/file.rb +20 -22
  73. data/spec/ramaze/error.rb +1 -1
  74. data/spec/ramaze/helper/auth.rb +40 -29
  75. data/spec/ramaze/helper/cache.rb +3 -43
  76. data/spec/ramaze/helper/flash.rb +14 -10
  77. data/spec/ramaze/helper/httpdigest.rb +65 -47
  78. data/spec/ramaze/helper/localize.rb +9 -9
  79. data/spec/ramaze/helper/partial.rb +40 -0
  80. data/spec/ramaze/helper/sequel_form.rb +1 -1
  81. data/spec/ramaze/helper/simple_captcha.rb +13 -9
  82. data/spec/ramaze/helper/stack.rb +39 -31
  83. data/spec/ramaze/helper/user.rb +13 -15
  84. data/spec/ramaze/request.rb +0 -12
  85. data/tasks/bacon.rake +21 -38
  86. data/tasks/release.rake +22 -4
  87. metadata +24 -22
  88. data/lib/proto/app.rb +0 -15
  89. data/lib/ramaze/cache/localmemcache.rb +0 -56
  90. data/lib/ramaze/contrib/app_graph.rb +0 -64
  91. data/lib/ramaze/tool/create.rb +0 -48
  92. data/lib/ramaze/tool/project_creator.rb +0 -111
  93. data/spec/ramaze/cache/localmemcache.rb +0 -49
  94. data/tasks/setup.rake +0 -24
@@ -0,0 +1,12 @@
1
+ # Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ module Sequel
5
+ class Model
6
+ class << self
7
+ def fill request_object = Ramaze::Request.current
8
+ create(request_object.params)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -94,14 +94,14 @@ class FormField
94
94
  select(gestalt)
95
95
  else
96
96
  case db_type
97
- when /varchar|integer/
97
+ when 'varchar', 'integer'
98
98
  input(gestalt)
99
- when /boolean/
99
+ when 'boolean'
100
100
  checkbox(gestalt)
101
- when /string/
101
+ when 'string'
102
102
  textarea(gestalt)
103
103
  else
104
- raise("Unsupported type: (%p : %p)" % [db_type || hint, field])
104
+ raise "Unsupported type: (#{db_type || hint} : #{field})"
105
105
  end
106
106
  end
107
107
  end
@@ -7,7 +7,7 @@
7
7
  # Usage:
8
8
  # class Avatar < Sequel::Model
9
9
  # IMAGE = {
10
- # # specifies many_to_one, will create relation and foreign key
10
+ # # specifies belongs_to, will create relation and foreign key
11
11
  #
12
12
  # :owner => :User,
13
13
  #
@@ -51,8 +51,8 @@
51
51
  module SequelImage
52
52
  def self.included(model)
53
53
  args = model::IMAGE
54
- set_foreign_key = args[:foreign_key] || "#{args[:owner]}_id".downcase.to_sym
55
- set_many_to_one = args[:many_to_one] || args[:owner].to_s.downcase.to_sym
54
+ set_foreign_key = args[:foreign_key] || "#{args[:owner]}_id".downcase.to_sym
55
+ set_belongs_to = args[:belongs_to] || args[:owner].to_s.downcase.to_sym
56
56
 
57
57
  # Define schema
58
58
  model.set_schema do
@@ -68,19 +68,21 @@ module SequelImage
68
68
  end
69
69
 
70
70
  # Define Relations
71
- model.many_to_one set_many_to_one
71
+ model.belongs_to set_belongs_to
72
72
 
73
73
  # Define Hooks
74
- model.before_create :generate_thumbnails do
74
+ model.send(:hooks).clear
75
+
76
+ model.before_create do
75
77
  generate_thumbnails
76
78
  self.created_at = Time.now
77
79
  end
78
80
 
79
- model.before_save :update_time do
81
+ model.before_save do
80
82
  self.updated_at = Time.now
81
83
  end
82
84
 
83
- model.before_destroy :cleanup do
85
+ model.before_destroy do
84
86
  cleanup if conf[:cleanup]
85
87
  end
86
88
 
@@ -108,7 +110,7 @@ module SequelImage
108
110
  tempfile = file[:tempfile]
109
111
  raise ArgumentError, 'Empty tempfile' if tempfile.size == 0
110
112
 
111
- ext = Rack::Mime::MIME_TYPES.invert[type]
113
+ ext = Ramaze::Tool::MIME.ext_for(type)
112
114
  image.mime = type
113
115
  target_name = image.next_name(File.basename(filename, File.extname(filename)), ext)
114
116
  target_path = File.join(image.public_root, image.path, target_name)
@@ -148,7 +150,7 @@ module SequelImage
148
150
  end
149
151
 
150
152
  def public_root
151
- Ramaze.options.roots.first
153
+ Ramaze::Global.public_root
152
154
  end
153
155
 
154
156
  def filename(size)
@@ -65,34 +65,20 @@ module SequelRelation
65
65
  end
66
66
 
67
67
  def belongs_to(model)
68
- todo :many_to_one, singular_sym(model), :class => model
68
+ todo :belongs_to, model.to_s.downcase.to_sym
69
69
  end
70
70
 
71
71
  def has_many(model)
72
72
  todo :create_join, model
73
- todo :many_to_many, plural_sym(model), :class => model
73
+ todo :many_to_many, model.to_s.downcase.pluralize.to_sym
74
74
  end
75
75
 
76
76
  def has_one(model)
77
- todo :many_to_one, singular_sym(model), :class => model
77
+ todo :belongs_to, model.to_s.downcase.to_sym
78
78
  end
79
79
 
80
80
  def todo(method, *args)
81
81
  TODO[@left] << [method, *args]
82
82
  end
83
-
84
- private
85
-
86
- def plural_sym(obj)
87
- basename(obj).pluralize.to_sym
88
- end
89
-
90
- def singular_sym(obj)
91
- basename(obj).to_sym
92
- end
93
-
94
- def basename(obj)
95
- obj.to_s.split('::').last.downcase
96
- end
97
83
  end
98
84
  end
@@ -3,10 +3,5 @@ module Ramaze
3
3
 
4
4
  class DefaultController < Ramaze::Controller
5
5
  map '/'
6
-
7
- def lobster
8
- require 'rack/lobster'
9
- respond Rack::Lobster::LobsterString
10
- end
11
6
  end
12
7
  end
@@ -28,30 +28,17 @@ module Ramaze
28
28
  cache = Innate::Cache.action
29
29
 
30
30
  ancestral_trait[:cache_action].each do |cache_action|
31
- temp = cache_action.dup
32
- block = temp.delete(:key)
33
- ttl = temp.delete(:ttl)
31
+ temp = cache_action.dup
32
+ ttl = temp.delete(:ttl)
34
33
 
35
34
  if temp.all?{|key, value| action[key] == value }
36
- cache_key = action.full_path
37
- cache_key << "_#{action.instance.instance_eval(&block).to_s}" if block
38
-
39
- if cached = cache[cache_key]
40
- action.options[:content_type] = cached[:type]
35
+ if cached = cache[temp]
36
+ return cached
37
+ elsif ttl
38
+ return cache.store(temp, yield, :ttl => ttl)
41
39
  else
42
- cached = {
43
- :body => catch(:respond) { yield },
44
- :type => response['Content-Type']
45
- }
46
-
47
- if ttl
48
- cache.store(cache_key, cached, :ttl => ttl)
49
- else
50
- cache.store(cache_key, cached)
51
- end
40
+ return cache.store(temp, yield)
52
41
  end
53
-
54
- return cached[:body]
55
42
  end
56
43
  end
57
44
 
@@ -80,8 +67,7 @@ module Ramaze
80
67
  cache_action(hash.merge(:method => name))
81
68
  end
82
69
 
83
- def cache_action(hash, &block)
84
- hash[:key] = block if block_given?
70
+ def cache_action(hash)
85
71
  hash[:method] = hash[:method].to_s
86
72
  trait[:cache_action] << hash
87
73
  end
@@ -3,8 +3,6 @@
3
3
 
4
4
  module Ramaze
5
5
  module Helper::Formatting
6
- module_function
7
-
8
6
  FORMATTING_NUMBER_COUNTER = { 0 => 'no', 2 => 'two', 3 => 'three',
9
7
  4 => 'four', 5 => 'five', 6 => 'six', 7 => 'seven', 8 => 'eight',
10
8
  9 => 'nine', 10 => 'ten' }
@@ -83,7 +83,7 @@ module Ramaze
83
83
  httpdigest_failure unless nonce == session_nonce and opaque == session_opaque
84
84
 
85
85
  ha1 = httpdigest_lookup(username, realm, &block)
86
- a2 = [request.request_method,request.request_uri]
86
+ a2 = [request.request_method,request.fullpath]
87
87
  a2 << Digest::MD5.hexdigest(request.body.read) if qop == "auth-int"
88
88
  ha2 = Digest::MD5.hexdigest( a2.join(':') )
89
89
  md5 = Digest::MD5.hexdigest([ha1, nonce, nc, cnonce, qop, ha2].join(':'))
@@ -5,10 +5,13 @@ require 'innate/helper/link'
5
5
 
6
6
  module Ramaze
7
7
  module Helper
8
- # This is a modification of Innate::Helper::Link to respect the routing of
9
- # Ramaze
10
8
  # NOTE: The A/R/Rs methods have been deprecated.
11
9
  module Link
10
+ include Innate::Helper::Link
11
+
12
+ def self.included(into)
13
+ into.extend(self)
14
+ end
12
15
 
13
16
  # @return [String]
14
17
  # @see Innate::Helper#anchor
@@ -19,12 +19,7 @@ module Ramaze
19
19
  end
20
20
 
21
21
  def locales
22
- locales = request.env['localize.locales']
23
- return locales if locales
24
-
25
- fallback = ancestral_trait[:localize_locale]
26
- locales = Parser.new(request).locales(fallback)
27
- request.env['localize.locales'] = locales
22
+ Parser.new(request).locales(ancestral_trait[:localize_locale])
28
23
  end
29
24
 
30
25
  class Dictionary
@@ -110,7 +105,7 @@ module Ramaze
110
105
  end
111
106
 
112
107
  def parse
113
- parse_params || parse_session || parse_cookie || parse_header
108
+ parse_params || parse_cookie || parse_header
114
109
  end
115
110
 
116
111
  def parse_params(key = 'lang')
@@ -118,18 +113,13 @@ module Ramaze
118
113
  ::Locale::Tag.parse(lang)
119
114
  end
120
115
 
121
- def parse_session(key = :lang)
122
- return unless lang = Current.session[key]
123
- ::Locale::Tag.parse(lang)
124
- end
125
-
126
116
  def parse_cookie(key = 'lang')
127
117
  return unless lang = request.cookies[key]
128
118
  ::Locale::Tag.parse(lang)
129
119
  end
130
120
 
131
121
  def parse_header
132
- request.accept_language.map{|lang|
122
+ request.accept_language_with_weight.map{|lang|
133
123
  ::Locale::Tag.parse(lang) }
134
124
  end
135
125
  end
@@ -154,7 +154,6 @@ module Ramaze
154
154
  def last_page; @pager.last_page; end
155
155
  def last_page?; @pager.last_page?; end
156
156
  def next_page; @pager.next_page; end
157
- def empty?; @pager.empty?; end
158
157
 
159
158
  private
160
159
 
@@ -1,99 +1,24 @@
1
- # Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
2
- # All files in this distribution are subject to the terms of the Ruby license.
1
+ require 'innate/helper/partial'
3
2
 
4
3
  module Ramaze
5
4
  module Helper
6
-
7
- # = Helper::Partial
8
- #
9
- # Please note that this helper is deprecated in favor of # Helper::Render,
10
- # it has been removed from Innate and remains in Ramaze until 2009.05.
11
- #
12
- # === Example Usage
13
- #
14
- # class MyController
15
- # def index
16
- # end
17
- #
18
- # def list
19
- # plain = request['plain']
20
- # "Hello World from List! Plain List == #{plain}"
21
- # end
22
- # end
23
- #
24
- #
25
- # <html>
26
- # <head><title>Partial Render Index</title></head>
27
- # <body>
28
- # #{render_partial(Rs(:list), 'plain' => true)}
29
- # </body>
30
- # </html>
31
5
  module Partial
32
- module_function
33
-
34
- # Renders a url 'inline'.
35
- #
36
- # +url+ normal URL, like you'd use for redirecting.
37
- # +options+ optional, will be used as request parameters.
38
- #
39
- # Issues a mock request to the given +url+ with +options+ turned into
40
- # query arguments.
41
- def render_partial(url, options = {})
42
- Ramaze.deprecated('Helper::Partial#render_partial', 'Helper::Render#render_full')
43
-
44
- uri = URI(url)
45
- query = options # Innate::Current.request.params.merge(options)
46
- uri.query = Rack::Utils.build_query(query)
47
-
48
- body = nil
49
-
50
- Innate::Mock.session do |session|
51
- cookie = Innate::Current.session.cookie
52
- session.cookie = cookie
53
- body = session.get(uri.to_s, options).body
54
- end
6
+ include Innate::Helper::Partial
55
7
 
56
- body
8
+ def self.included(into)
9
+ into.extend(self)
10
+ into.extend(Innate::Helper::Partial)
57
11
  end
58
12
 
59
- # Render the template file in view_root of the
60
- # current controller.
61
- #
62
- # TODO:
63
- # * Doesn't work for absolute paths, but there are no specs for that yet.
64
- # * the local variable hack isn't working because innate allocates a new
65
- # binding.
66
- # For now one can simply use instance variables, which I prefer anyway.
67
- #
68
- # the local binding hack:
69
- #
70
- # variables.each do |key, value|
71
- # value = "ObjectSpace._id2ref(#{value.object_id})"
72
- # eval "#{key} = #{value}", action.binding
73
- # end
13
+ def partial_content(name, variables = {})
14
+ action = resolve(name.to_s)
74
15
 
75
- def render_template(path, variables = {})
76
- Ramaze.deprecated('Helper::Partial#render_template')
77
- path = path.to_s
78
-
79
- ext = File.extname(path)
80
- basename = File.basename(path, ext)
81
-
82
- action = Innate::Current.action.dup
83
- action.layout = nil
84
- action.view = action.node.find_view(basename, 'html')
85
- action.method = action.node.find_method(basename, action.params)
16
+ action.layout = nil
86
17
 
18
+ action.instance = action.node.new
87
19
  action.variables = action.variables.merge(variables)
88
- action.sync_variables(action)
89
-
90
- return action.call if action.valid?
91
- raise(ArgumentError, "cannot render %p" % path)
92
- end
93
20
 
94
- def render_action(method, *params)
95
- Ramaze.deprecated('Helper::Partial#render_action', 'Helper::Render#render_full')
96
- render_partial(r(method), *params)
21
+ action.render if action.valid?
97
22
  end
98
23
  end
99
24
  end
data/lib/ramaze/helper.rb CHANGED
@@ -1,12 +1,22 @@
1
1
  # Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
- require 'innate/helper'
5
-
6
4
  module Ramaze
7
- Helper = Innate::Helper
8
- Innate::HelpersHelper.options.paths << File.dirname(__FILE__)
5
+ module Helper
6
+ EXPOSE = LOOKUP = Innate::Helper::EXPOSE
7
+
8
+ def self.included(into)
9
+ into.extend(HelperAccess)
10
+ into.__send__(:include, Trinity)
11
+ end
12
+
13
+ # assign some of the default helpers that have no overrides
14
+ Innate::HelpersHelper.each(:cgi, :aspect, :redirect, :send_file) do |mod|
15
+ Helper.const_set(mod.name.split('::').last, mod)
16
+ end
17
+ end
9
18
 
10
- require 'ramaze/helper/flash'
11
- require 'ramaze/helper/link'
19
+ Innate::HelpersHelper.add_path(File.dirname(__FILE__))
20
+ Innate::HelpersHelper.add_path('')
21
+ Innate::HelpersHelper.add_pool(Ramaze::Helper)
12
22
  end
@@ -27,14 +27,13 @@ module Ramaze
27
27
  # @name # => 'manveru'
28
28
  # @lang # => nil
29
29
 
30
- def to_instance_variables(*args)
30
+ def to_ivs(*args)
31
31
  instance = Action.current.instance
32
32
  args.each do |arg|
33
33
  next unless value = self[arg]
34
34
  instance.instance_variable_set("@#{arg}", value)
35
35
  end
36
36
  end
37
- alias to_ivs to_instance_variables
38
37
 
39
38
  def accept_charset(default = 'UTF-8')
40
39
  return default unless charsets = env['HTTP_ACCEPT_CHARSET']
@@ -94,25 +93,5 @@ module Ramaze
94
93
  env.reject{|key, value| key.to_s !~ INTERESTING_HTTP_VARIABLES }
95
94
  end
96
95
  alias http_vars http_variables
97
-
98
- REQUEST_STRING_FORMAT = "#<%s params=%p cookies=%p env=%p>"
99
-
100
- def to_s
101
- REQUEST_STRING_FORMAT % [self.class, params, cookies, http_variables]
102
- end
103
- alias inspect to_s
104
-
105
- # Pretty prints current action with parameters, cookies and enviroment
106
- # variables.
107
- def pretty_print(pp)
108
- pp.object_group(self){
109
- group = { 'params' => params, 'cookies' => cookies, 'env' => http_variables }
110
- group.each do |name, hash|
111
- pp.breakable
112
- pp.text " @#{name}="
113
- pp.nest(name.size + 3){ pp.pp_hash(hash) }
114
- end
115
- }
116
- end
117
96
  end
118
97
  end
@@ -1,5 +1,6 @@
1
1
  module Ramaze
2
2
  DEPRECATED_CONSTANTS = {
3
+ :ThreadAccessor => :StateAccessor,
3
4
  :BASEDIR => :ROOT,
4
5
  :Template => :View,
5
6
  :Optional => :Optioned,
@@ -0,0 +1,19 @@
1
+ # Copyright (c) 2008 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 CoreExtensions
6
+
7
+ # Extensions for String
8
+
9
+ module String
10
+ # 1.9 Compatibility with 1.8
11
+
12
+ unless ''.respond_to?(:each)
13
+ def each(*args, &block)
14
+ each_line(*args, &block)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
data/lib/ramaze/spec.rb CHANGED
@@ -1,6 +1,6 @@
1
- begin; require 'rubygems'; rescue LoadError; end
1
+ require 'ramaze'
2
+ require 'bacon'
2
3
 
3
- require(File.expand_path("#{__FILE__}/../")) unless defined?(Ramaze)
4
4
  require 'innate/spec'
5
5
 
6
6
  def spec_requires(*libs)
@@ -25,10 +25,3 @@ module Ramaze
25
25
 
26
26
  middleware!(:spec){|m| m.run(AppMap) }
27
27
  end
28
-
29
- shared :mock do
30
- Ramaze.setup_dependencies
31
- extend Rack::Test::Methods
32
-
33
- def app; Ramaze.middleware; end
34
- end
@@ -1,3 +1,3 @@
1
1
  module Ramaze
2
- VERSION = "2009.04"
2
+ VERSION = "2009.04.01"
3
3
  end
@@ -1,4 +1,3 @@
1
- require 'haml/util'
2
1
  require 'haml/engine'
3
2
 
4
3
  module Ramaze
@@ -5,56 +5,22 @@ require 'liquid'
5
5
 
6
6
  module Ramaze
7
7
  module View
8
- # Liquid is a smarty-style templating engine that restricts the usage of
9
- # code inside templates. This is mostly helpful if you want to let users
10
- # submit templates but prevent them from running arbitrary code.
11
- #
12
- # Liquid offers a pipe-like syntax for chaining operations on objects.
13
- # Any instance variable from your Controller is available as a variable
14
- # inside Liquid, so be sensitive about what data you provide.
15
- #
16
- # If you want to allow partials you can provide a kind of virtual
17
- # filesystem that contains partials. These can be rendered using the
18
- # Liquid `{% include 'name' %}` tag. The include tag has no relation to the
19
- # Ramaze::Helper::Render, it simply inlines the file.
20
- #
21
- # To tell Liquid where to find partials, you have to set the file_system.
22
- # The naming-convention for liquid-partials is to use a '_' prefix to the
23
- # filename and the '.liquid' filename extension. The names of partials
24
- # are restricted to ASCII alpha-numeric characters and underscores. You
25
- # can also use '/' to use templates located in deeper directories.
26
- # The partial has access to the same variables as the template including
27
- # it.
28
- #
29
- # @example setting file_system
30
- # template_path = './partials/'
31
- # Liquid::Template.file_system = Liquid::LocalFileSystem.new(template_path)
32
- #
33
- # @example using include
34
- # {% include 'foo' %}
35
- # {% include 'bar/foo' %}
36
- #
37
- # This will include the files located at './partials/_foo.liquid' and
38
- # './partials/bar/_foo.liquid'.
39
- #
40
- # This functionality gets even more interesting if you customize it with
41
- # your own virtual file-system, you can use anything that responds to
42
- # `#read_template_file(path)`.
43
- # That way you can even fetch templates from a database or instruct Liquid
44
- # to allow you access to your own templates in the '/views' directory.
45
8
  module Liquid
46
-
47
- # Liquid requires the variable keys to be strings, most likely for
48
- # security resons (don't allow arbitrary symbols).
49
9
  def self.call(action, string)
50
- action.sync_variables(action)
51
- variables = {}
52
- action.variables.each{|k,v| variables[k.to_s] = v }
10
+ instance_variables = {}
11
+ instance = action.instance
12
+
13
+ instance.instance_variables.each do |iv|
14
+ instance_variables[iv.to_s[1..-1]] = instance.instance_variable_get(iv)
15
+ end
53
16
 
54
- template = ::Liquid::Template.parse(string.to_s)
55
- html = template.render(variables)
17
+ template = ::Liquid::Template.parse(string)
18
+ html = template.render(instance_variables)
56
19
 
57
20
  return html, 'text/html'
21
+
22
+ # data = action.variables[:data] || {}
23
+ # template.render(data, options)
58
24
  end
59
25
 
60
26
  class Tag < ::Liquid::Tag
@@ -1,24 +1,24 @@
1
- require 'innate/helper/render'
1
+ require 'innate/helper/partial'
2
2
 
3
3
  module Nagoro
4
4
  module Pipe
5
5
  # Pipe that transforms <render /> tags.
6
6
  #
7
7
  # the src parameter in the render tag will be used as first parameter to
8
- # render_partial, all other paramters are passed on as +variables+.
8
+ # render_partial, all other paramters are passed on as +options+.
9
9
  #
10
- # Example calling render_partial('hello'):
11
- # <render src="hello" />
10
+ # Example calling render_partial('/hello'):
11
+ # <render src="/hello" />
12
12
  #
13
- # Example calling render_partial('hello', 'tail' => 'foo'):
14
- # <render src="hello" tail="foo" />
13
+ # Example calling render_partial('/hello', 'tail' => 'foo'):
14
+ # <render src="/hello" tail="foo" />
15
15
  #
16
16
  class RenderPartial < Base
17
- include Innate::Helper::Render
17
+ include Innate::Helper::Partial
18
18
 
19
19
  def tag_start(tag, attrs)
20
- if tag == 'render' and action_name = attrs.delete('src')
21
- append(render_partial(action_name, attrs))
20
+ if tag == 'render' and src = attrs.delete('src')
21
+ append(render_partial(src, attrs))
22
22
  else
23
23
  super
24
24
  end
data/lib/ramaze/view.rb CHANGED
@@ -9,10 +9,6 @@ module Ramaze
9
9
  module View
10
10
  extend Innate::View
11
11
 
12
- def self.get(*args)
13
- Innate::View.get(*args)
14
- end
15
-
16
12
  # Combine Kernel#autoload and Innate::View::register
17
13
 
18
14
  def self.auto_register(name, *exts)
data/lib/ramaze.rb CHANGED
@@ -70,7 +70,6 @@ module Ramaze
70
70
  m.use Rack::Head
71
71
  m.use Rack::ETag
72
72
  m.use Rack::ConditionalGet
73
- m.use Rack::ContentLength
74
73
  m.run Ramaze::AppMap
75
74
  end
76
75
 
@@ -82,7 +81,6 @@ module Ramaze
82
81
  m.use Rack::Head
83
82
  m.use Rack::ETag
84
83
  m.use Rack::ConditionalGet
85
- m.use Rack::ContentLength
86
84
  m.run Ramaze::AppMap
87
85
  end
88
86
  end