amrita2 2.0.0 → 2.0.1

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.
Files changed (53) hide show
  1. data/README +1 -1
  2. data/init.rb +1 -0
  3. data/lib/amrita2/rails_bridge.rb +92 -7
  4. data/lib/amrita2/template.rb +12 -127
  5. data/lib/amrita2/testsupport.rb +0 -25
  6. data/lib/amrita2/version.rb +1 -1
  7. data/sample/depot/app/controllers/admin_controller.rb +3 -1
  8. data/sample/depot/app/helpers/cart_helper.rb +8 -0
  9. data/sample/depot/app/helpers/price_helper.rb +7 -0
  10. data/sample/depot/config/environment.rb +0 -14
  11. data/sample/depot/config/environments/development.rb +2 -2
  12. data/sample/depot/db/schema.rb +27 -20
  13. data/sample/depot/test/functional/admin_controller_test.rb +63 -22
  14. data/sample/depot/test/functional/store_controller_test.rb +30 -18
  15. data/sample/depot/vendor/plugins/will_paginate/init.rb +4 -0
  16. data/sample/depot/vendor/plugins/will_paginate/lib/will_paginate.rb +61 -0
  17. data/sample/depot/vendor/plugins/will_paginate/lib/will_paginate/collection.rb +132 -0
  18. data/sample/depot/vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb +80 -0
  19. data/sample/depot/vendor/plugins/will_paginate/lib/will_paginate/finder.rb +181 -0
  20. data/sample/depot/vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb +206 -0
  21. data/sample/depot/vendor/plugins/will_paginate/test/array_pagination_test.rb +131 -0
  22. data/sample/depot/vendor/plugins/will_paginate/test/boot.rb +23 -0
  23. data/sample/depot/vendor/plugins/will_paginate/test/finder_test.rb +290 -0
  24. data/sample/depot/vendor/plugins/will_paginate/test/fixtures/admin.rb +3 -0
  25. data/sample/depot/vendor/plugins/will_paginate/test/fixtures/company.rb +9 -0
  26. data/sample/depot/vendor/plugins/will_paginate/test/fixtures/developer.rb +11 -0
  27. data/sample/depot/vendor/plugins/will_paginate/test/fixtures/project.rb +15 -0
  28. data/sample/depot/vendor/plugins/will_paginate/test/fixtures/reply.rb +5 -0
  29. data/sample/depot/vendor/plugins/will_paginate/test/fixtures/schema.rb +38 -0
  30. data/sample/depot/vendor/plugins/will_paginate/test/fixtures/topic.rb +4 -0
  31. data/sample/depot/vendor/plugins/will_paginate/test/fixtures/user.rb +2 -0
  32. data/sample/depot/vendor/plugins/will_paginate/test/helper.rb +25 -0
  33. data/sample/depot/vendor/plugins/will_paginate/test/lib/activerecord_test_case.rb +23 -0
  34. data/sample/depot/vendor/plugins/will_paginate/test/lib/activerecord_test_connector.rb +67 -0
  35. data/sample/depot/vendor/plugins/will_paginate/test/lib/load_fixtures.rb +13 -0
  36. data/sample/depot/vendor/plugins/will_paginate/test/pagination_test.rb +240 -0
  37. data/sample/hello/test1.rb +23 -0
  38. data/sample/login_engine/config/environment.rb +18 -20
  39. data/sample/login_engine/config/environments/development.rb +2 -2
  40. data/sample/login_engine/db/schema.rb +24 -17
  41. data/sample/login_engine/lib/login_engine/authenticated_system.rb +18 -18
  42. data/sample/login_engine/test/functional/user_controller_test.rb +1 -0
  43. data/sample/ramaze/ramaise_amrita2.rb +156 -0
  44. data/specs/attribute.rb +11 -0
  45. data/specs/datatypes.rb +13 -0
  46. data/specs/sample.rb +1 -2
  47. data/specs/sanitize.rb +14 -0
  48. metadata +28 -7
  49. data/sample/depot/app/helpers/ar_form.rb +0 -169
  50. data/sample/depot/app/helpers/form_tag.rb +0 -24
  51. data/sample/depot/app/helpers/standard_form.rb +0 -73
  52. data/sample/depot/test/integration/dsl_user_stories_test.rb +0 -126
  53. data/sample/depot/test/integration/user_stories_test.rb +0 -70
data/README CHANGED
@@ -77,7 +77,7 @@ matching the +id+ attribute of XML element to model data.
77
77
 
78
78
  === Current version and roadmap
79
79
 
80
- Current version is 2.0.0 .
80
+ Current version is 2.0.1 .
81
81
 
82
82
  === Setup
83
83
 
data/init.rb CHANGED
@@ -3,4 +3,5 @@
3
3
  require 'amrita2/rails_bridge'
4
4
 
5
5
  ActionView::Base.register_template_handler "a2html", Amrita2View::Base
6
+ ActionView::Base.register_template_handler "a2", Amrita2View::Base
6
7
 
@@ -2,9 +2,99 @@ require 'amrita2/template'
2
2
 
3
3
  require 'action_view'
4
4
 
5
+ module Amrita2
6
+ module Core
7
+ class Hook
8
+ include ActionView::Helpers::FormHelper
9
+ include ActionView::Helpers::FormHelper
10
+ end
11
+ end
12
+
13
+ end
14
+
15
+ module Amrita2View # :nodoc: all
16
+ module FormHelper
17
+ class FormFieldHelper
18
+ include Amrita2::DictionaryData
19
+ attr_reader :form, :data
20
+
21
+ def initialize(record, form, &block)
22
+ @record = record
23
+ @form = form
24
+ @data = {}
25
+ block.call(self)
26
+ end
27
+
28
+ def add_field(name, value)
29
+ @data[name] = value
30
+ end
31
+
32
+ def add_field_element(name, element)
33
+ add_field(name, Amrita2::SanitizedString[element])
34
+ end
35
+
36
+ def method_missing(meth, name, *args, &block)
37
+ value = @form.send(meth, name, *args, &block)
38
+ add_field_element(name, value)
39
+ end
40
+
41
+ def as_hash
42
+ @data
43
+ end
44
+
45
+ def as_label_field_hash
46
+ @data.inject(Hash.new) do |h, data|
47
+ k, v = *data
48
+ h.merge ({
49
+ k => {
50
+ :label => {
51
+ :for=>"#{@record}_#{k}",
52
+ :text=>k.to_s
53
+ },
54
+ :field => v
55
+ }
56
+ })
57
+ end
58
+ end
59
+ end
60
+
61
+ def amrita_define_form(*args, &block)
62
+ record = args.first
63
+ method = :form_for
64
+ format = :as_hash
65
+ case h = args.last
66
+ when Hash
67
+ method = h.delete(:form_method) || method
68
+ format = h.delete(:amrita_format) || format
69
+ end
70
+
71
+ amrita_form_hook(method, *args) do |f|
72
+ FormFieldHelper.new(record, f) do |ff|
73
+ block.call(ff)
74
+ end.send(format)
75
+ end
76
+ end
77
+
78
+ def amrita_form_hook(meth, *args, &block)
79
+ view = self
80
+ hook = Amrita2::Core::Hook.new do
81
+ _erbout = stream
82
+ view.instance_eval do
83
+ self.send(meth, *args) do |f|
84
+ data = block.call(f)
85
+ hook.render_me_with(data)
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ FormFieldHelper = FormHelper::FormFieldHelper
92
+ end
93
+
5
94
  module ActionView # :nodoc: all
6
95
  class Base #:nodoc:
7
96
  include Amrita2::Runtime
97
+ include Amrita2View::FormHelper
8
98
  end
9
99
  end
10
100
 
@@ -18,13 +108,6 @@ module ActiveRecord # :nodoc: all
18
108
  end
19
109
  end
20
110
 
21
- module ActionController # :nodoc: all
22
- class Pagination::Paginator
23
- include Amrita2::DictionaryData
24
- end
25
- end
26
-
27
-
28
111
  module Amrita2View # :nodoc: all
29
112
  class Base
30
113
  include Amrita2
@@ -91,6 +174,8 @@ module Amrita2View # :nodoc: all
91
174
  end
92
175
  end
93
176
  end
177
+
178
+
94
179
  module Helper
95
180
  include ActionView::Helpers::UrlHelper
96
181
 
@@ -1,10 +1,7 @@
1
- require 'rubygems'
2
1
  require 'hpricot'
3
2
  require 'erb'
4
- #require 'rexml/document'
5
3
  require 'enumerator'
6
4
 
7
-
8
5
  module Amrita2
9
6
  module ScalarData
10
7
  def amrita_value
@@ -73,18 +70,6 @@ class Time
73
70
  include Amrita2::ScalarData
74
71
  end
75
72
 
76
- # class REXML::Element
77
- # include Amrita2::ScalarData
78
- # def amrita_value
79
- # Amrita2::SanitizedString[to_s]
80
- # end
81
-
82
- # def as_amrita_dictionary(*args)
83
- # Amrita2::Util::REXMLConverter.new(*args).convert(self)
84
- # end
85
- # end
86
-
87
-
88
73
  class Array
89
74
  include Amrita2::Enum
90
75
  end
@@ -96,7 +81,7 @@ end
96
81
  class Hash
97
82
  include Amrita2::DictionaryData
98
83
  def amrita_value(name)
99
- self[name]
84
+ self[name.to_sym]
100
85
  end
101
86
  end
102
87
 
@@ -313,109 +298,9 @@ module Amrita2
313
298
  self.new(args)
314
299
  end
315
300
  end
316
-
317
- class REXMLConverter # :nodoc: all
318
- include Amrita2
319
- include Util::OptionSupport
320
-
321
- def initialize(*args)
322
- parse_opt(*args)
323
- end
324
-
325
- def convert(e)
326
- @noattrs = select_elements(e, :noattrs)
327
- @use_child_contents = select_elements(e, :use_child_contents)
328
- @use_child = select_elements(e, :use_child)
329
- convert1(e)
330
- end
331
-
332
- def convert1(e)
333
- h = {}
334
- if use_attr?(e)
335
- e.attributes.each do |key, value|
336
- h[key.intern] = value
337
- end
338
- end
339
-
340
- ctag = get_contents_tag(e)
341
- if ctag
342
- if e.elements.size > 0
343
- s = e.collect { |cc| cc.to_s }
344
- h[ctag] = SanitizedString[s]
345
- else
346
- h[ctag] = e.text
347
- end
348
- end
349
-
350
- e.each_element do |c|
351
- if use_child_contents?(c)
352
- if c.elements.size > 0
353
- s = c.collect { |cc| cc.to_s }
354
- h[c.name.intern] = SanitizedString[s]
355
- else
356
- h[c.name.intern] = c.text
357
- end
358
- end
359
-
360
- if use_child?(c)
361
- ch = convert1(c)
362
- case h[c.name.intern]
363
- when nil
364
- h.merge!(ch)
365
- when Array
366
- h[c.name.intern] << ch[c.name.intern]
367
- else
368
- h[c.name.intern] = [h[c.name.intern], ch[c.name.intern]]
369
- end
370
- end
371
- end
372
- if @opt[:use_tag]
373
- { e.name.intern => h }
374
- else
375
- h
376
- end
377
- end
378
-
379
- private
380
-
381
- def select_elements(e, key)
382
- case xpath = opt[key]
383
- when String
384
- REXML::XPath.match(e, xpath)
385
- when nil,false
386
- return []
387
- else
388
- REXML::XPath.match(e, "//*")
389
- end
390
- end
391
-
392
- def get_contents_tag(e)
393
- case o = opt[:use_contents]
394
- when true, :use_contents
395
- :contents
396
- when Symbol
397
- o
398
- when nil
399
- nil
400
- else
401
- raise "not implemented"
402
- end
403
- end
404
-
405
- def use_attr?(e)
406
- not @noattrs.include?(e)
407
- end
408
-
409
- def use_child_contents?(e)
410
- @use_child_contents.include?(e)
411
- end
412
-
413
- def use_child?(e)
414
- @use_child.include?(e)
415
- end
416
- end
417
301
  end
418
302
 
303
+
419
304
  module Runtime # :nodoc: all
420
305
  def amrita_set_context_value(v)
421
306
  Thread::current[:amrita_context_value] = v
@@ -951,7 +836,7 @@ module Amrita2
951
836
 
952
837
  def class_name
953
838
  if name
954
- "XX" + name.capitalize
839
+ "XX" + name.capitalize.gsub(/[^\w\d]/, "_")
955
840
  else
956
841
  "XX%d" % [object_id.abs]
957
842
  end
@@ -971,7 +856,7 @@ module Amrita2
971
856
 
972
857
  def render_me(cg, n = name)
973
858
  if (n)
974
- cg.put_string_expression("#{instance_name}.render_with($_.amrita_value(:#{n}), __binding__)")
859
+ cg.put_string_expression("#{instance_name}.render_with($_.amrita_value(#{n.inspect}), __binding__)")
975
860
  else
976
861
  cg.put_string_expression("#{instance_name}.render_with($_, __binding__)")
977
862
  end
@@ -1067,7 +952,6 @@ module Amrita2
1067
952
 
1068
953
  def compile_filters(element, name, *args)
1069
954
  src = args.compact.join('|')
1070
- #filters = src.split('|').collect { |f| parse_filter(f) }
1071
955
  filters = parse_filter(src)
1072
956
  @filter_proc.call(element, name, filters)
1073
957
  filters
@@ -2146,14 +2030,14 @@ module Amrita2
2146
2030
  if use_body
2147
2031
  body_key = @opt[:body]
2148
2032
  body_key = :body unless body_key.kind_of?(Symbol)
2149
- cg.code("body = $_.amrita_value(:#{body_key})")
2033
+ cg.code("body = $_.amrita_value(#{body_key.inspect})")
2150
2034
  end
2151
2035
  if @opt.size > 0
2152
2036
  cg.code("a = {}")
2153
2037
  @opt.each do |key, v|
2154
2038
  next if key == :body
2155
2039
  if element.get_attribute(key)
2156
- cg.case_("v = $_.amrita_value(:#{v})") do
2040
+ cg.case_("v = $_.amrita_value(#{v.inspect})") do
2157
2041
  cg.when_("true") do
2158
2042
  cg.code("a[#{key.inspect}] = #{element.get_attribute(key).inspect}")
2159
2043
  end
@@ -2161,11 +2045,11 @@ module Amrita2
2161
2045
  cg.code("a.delete(#{key.inspect})")
2162
2046
  end
2163
2047
  cg.else_ do
2164
- cg.code("a[#{key.inspect}] = $_.amrita_value(:#{v})")
2048
+ cg.code("a[#{key.inspect}] = $_.amrita_value(#{v.inspect})")
2165
2049
  end
2166
2050
  end
2167
2051
  else
2168
- cg.code("v = $_.amrita_value(:#{v})")
2052
+ cg.code("v = $_.amrita_value(#{v.inspect})")
2169
2053
  cg.code("a[#{key.inspect}] = v if v")
2170
2054
  end
2171
2055
  end
@@ -2414,7 +2298,7 @@ module Amrita2
2414
2298
 
2415
2299
  def make_tupple_code(cg)
2416
2300
  init_code = @names.collect do |n|
2417
- "$_.amrita_value(:#{n})"
2301
+ "$_.amrita_value(#{n.inspect})"
2418
2302
  end.join(",")
2419
2303
  cg.code("$_ = Tuple[#{init_code}]")
2420
2304
  end
@@ -2486,7 +2370,7 @@ module Amrita2
2486
2370
  init_code = @names.collect do |n|
2487
2371
  case n
2488
2372
  when Symbol
2489
- "$_.amrita_value(:#{n})"
2373
+ "$_.amrita_value(#{n.inspect})"
2490
2374
  else
2491
2375
  "eval(#{with_context_value_expression(n).inspect},__binding__)"
2492
2376
  end
@@ -2532,7 +2416,7 @@ module Amrita2
2532
2416
  private
2533
2417
  def make_tupple_code(cg)
2534
2418
  init_code = @names.collect do |n|
2535
- "$_.amrita_value(:#{n})"
2419
+ "$_.amrita_value(#{n.inspect})"
2536
2420
  end.join(",")
2537
2421
  cg.code("a = [#{init_code}]")
2538
2422
  end
@@ -2701,4 +2585,5 @@ module Amrita2
2701
2585
 
2702
2586
  SanitizedString = Util::SanitizedString
2703
2587
  Template = Core::Template
2588
+ Hooki = Core::Hook
2704
2589
  end
@@ -144,28 +144,3 @@ end
144
144
  class Object
145
145
  include Amrita2::TestSupport
146
146
  end
147
-
148
- if Object::const_defined?(:ActionView)
149
-
150
- class ActionView::Base # :nodoc: all
151
- def self.unregister_template_handler(extension)
152
- self.cache_template_extensions = false
153
- @@template_handlers.delete(extension)
154
- end
155
- end
156
-
157
- module Amrita2
158
- module RailsTestHelper # :nodoc: all
159
- def compare_result
160
- ActionView::Base.register_template_handler "a2html", Amrita2View::Base
161
- amrita2_result = yield
162
- ActionView::Base.unregister_template_handler "a2html"
163
- erb_result = yield
164
- assert_equal_as_xml(erb_result, amrita2_result)
165
- #assert_dom_equal(amrita2_result, erb_result)
166
- end
167
- end
168
- end
169
-
170
- end
171
-
@@ -2,7 +2,7 @@ module Amrita2
2
2
  module Version
3
3
  MAJOR=2
4
4
  MINOR=0
5
- TINY=0
5
+ TINY=1
6
6
 
7
7
  STRING=[MAJOR,MINOR,TINY].join('.')
8
8
  end
@@ -17,7 +17,9 @@ class AdminController < ApplicationController
17
17
  end
18
18
 
19
19
  def list
20
- @product_pages, @products = paginate :products, :per_page => 10
20
+ #@product_pages, @products = paginate :products, :per_page => 10
21
+
22
+ @products = Product.paginate :page => params[:page]
21
23
  end
22
24
 
23
25
  def show
@@ -0,0 +1,8 @@
1
+ module CartHelper
2
+ include ActionView::Helpers::NumberHelper
3
+ def total_price_currency
4
+ number_to_currency(total_price)
5
+ end
6
+ end
7
+
8
+
@@ -0,0 +1,7 @@
1
+ module PriceHelper
2
+ include ActionView::Helpers::NumberHelper
3
+ def to_currency
4
+ number_to_currency(self)
5
+ end
6
+ end
7
+
@@ -54,20 +54,6 @@ end
54
54
 
55
55
  # Include your application configuration below
56
56
 
57
- module PriceHelper
58
- include ActionView::Helpers::NumberHelper
59
- def to_currency
60
- number_to_currency(self)
61
- end
62
- end
63
-
64
- class BigDecimal
65
- include PriceHelper
66
- end
67
-
68
- class Integer
69
- include PriceHelper
70
- end
71
57
 
72
58
  module StringHelper
73
59
  include ActionView::Helpers::TextHelper