lolita 3.0.7 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. data/GUIDELINE +4 -0
  2. data/README.rdoc +50 -0
  3. data/VERSION +1 -1
  4. data/app/controllers/lolita/rest_controller.rb +27 -11
  5. data/app/helpers/components/lolita/configuration/list_component.rb +11 -0
  6. data/app/helpers/lolita_helper.rb +1 -1
  7. data/app/views/components/lolita/configuration/field/_display.html.erb +9 -0
  8. data/app/views/components/lolita/configuration/field/_label.html.erb +1 -0
  9. data/app/views/components/lolita/{field → configuration/field}/_object.html.erb +0 -0
  10. data/app/views/components/lolita/configuration/field/array/_display.html.erb +5 -0
  11. data/app/views/components/lolita/configuration/field/array/habtm/_display.html.erb +26 -0
  12. data/app/views/components/lolita/configuration/field/array/select/_display.html.erb +5 -0
  13. data/app/views/components/lolita/configuration/field/big_decimal/_display.html.erb +1 -0
  14. data/app/views/components/lolita/{field/_boolean.html.erb → configuration/field/boolean/_display.html.erb} +0 -0
  15. data/app/views/components/lolita/configuration/field/date/_display.html.erb +1 -0
  16. data/app/views/components/lolita/{field/_string.html.erb → configuration/field/float/_display.html.erb} +0 -0
  17. data/app/views/components/lolita/configuration/field/integer/_display.html.erb +1 -0
  18. data/app/views/components/lolita/configuration/field/string/_display.html.erb +5 -0
  19. data/app/views/components/lolita/{field/_disabled.html.erb → configuration/field/string/disabled/_display.html.erb} +0 -0
  20. data/app/views/components/lolita/{field/_password.html.erb → configuration/field/string/password/_display.html.erb} +0 -0
  21. data/app/views/components/lolita/configuration/field/string/text/_display.html.erb +34 -0
  22. data/app/views/components/lolita/configuration/field/time/_display.html.erb +1 -0
  23. data/app/views/components/lolita/{field_set → configuration/field_set}/_display.html.erb +1 -1
  24. data/app/views/components/lolita/configuration/list/_body.html.erb +5 -0
  25. data/app/views/components/lolita/{list → configuration/list}/_body_cell.html.erb +0 -0
  26. data/app/views/components/lolita/{list → configuration/list}/_checkbox_cell.html.erb +0 -0
  27. data/app/views/components/lolita/{list → configuration/list}/_checkbox_header.html.erb +0 -0
  28. data/app/views/components/lolita/configuration/list/_display.html.erb +12 -0
  29. data/app/views/components/lolita/configuration/list/_filter.html.erb +8 -0
  30. data/app/views/components/lolita/configuration/list/_header.html.erb +9 -0
  31. data/app/views/components/lolita/{list → configuration/list}/_header_cell.html.erb +0 -0
  32. data/app/views/components/lolita/{list → configuration/list}/_new_resource.html.erb +0 -0
  33. data/app/views/components/lolita/configuration/list/_paginator.html.erb +3 -0
  34. data/app/views/components/lolita/configuration/list/_row.html.erb +7 -0
  35. data/app/views/components/lolita/{list → configuration/list}/_title.html.erb +0 -0
  36. data/app/views/components/lolita/{list → configuration/list}/_tool_cell.html.erb +0 -0
  37. data/app/views/components/lolita/{list → configuration/list}/_tool_header.html.erb +0 -0
  38. data/app/views/components/lolita/configuration/tab/_display.html.erb +17 -0
  39. data/app/views/components/lolita/configuration/tab/_fields.html.erb +7 -0
  40. data/app/views/components/lolita/configuration/tab/content/_display.html.erb +1 -0
  41. data/app/views/components/lolita/configuration/tab/default/_display.html.erb +9 -0
  42. data/app/views/components/lolita/{tabs → configuration/tabs}/_display.html.erb +4 -3
  43. data/app/views/{lolita/layouts → layouts/lolita}/application.html.erb +0 -0
  44. data/app/views/{lolita/layouts → layouts/lolita}/application.html.erb_spec.rb +0 -0
  45. data/author +1 -1
  46. data/lib/lolita.rb +31 -12
  47. data/lib/lolita/adapter/active_record.rb +16 -5
  48. data/lib/lolita/adapter/mongoid.rb +2 -2
  49. data/lib/lolita/base_configuration.rb +44 -2
  50. data/lib/lolita/builder.rb +31 -14
  51. data/lib/lolita/configuration/column.rb +92 -86
  52. data/lib/lolita/configuration/columns.rb +65 -65
  53. data/lib/lolita/configuration/factory.rb +8 -8
  54. data/lib/lolita/configuration/field.rb +156 -100
  55. data/lib/lolita/configuration/field/array.rb +74 -0
  56. data/lib/lolita/configuration/field/big_decimal.rb +12 -0
  57. data/lib/lolita/configuration/field/boolean.rb +7 -5
  58. data/lib/lolita/configuration/field/date.rb +13 -0
  59. data/lib/lolita/configuration/field/integer.rb +7 -5
  60. data/lib/lolita/configuration/field/string.rb +8 -6
  61. data/lib/lolita/configuration/field/time.rb +13 -0
  62. data/lib/lolita/configuration/fields.rb +36 -0
  63. data/lib/lolita/configuration/filter.rb +63 -0
  64. data/lib/lolita/configuration/list.rb +101 -91
  65. data/lib/lolita/configuration/page.rb +1 -0
  66. data/lib/lolita/configuration/tab.rb +137 -131
  67. data/lib/lolita/configuration/tab/content.rb +14 -12
  68. data/lib/lolita/configuration/tab/default.rb +15 -13
  69. data/lib/lolita/configuration/tabs.rb +2 -2
  70. data/lib/lolita/controllers/component_helpers.rb +26 -14
  71. data/lib/lolita/controllers/internal_helpers.rb +14 -0
  72. data/lib/lolita/controllers/url_helpers.rb +47 -10
  73. data/lib/lolita/dbi/base.rb +50 -50
  74. data/lib/lolita/errors.rb +2 -2
  75. data/lib/lolita/hooks.rb +298 -0
  76. data/lib/lolita/hooks/named_hook.rb +122 -0
  77. data/lib/lolita/lazy_loader.rb +46 -46
  78. data/lib/lolita/mapping.rb +3 -2
  79. data/lib/lolita/navigation.rb +48 -0
  80. data/lib/lolita/observed_array.rb +7 -0
  81. data/lib/lolita/rails/routes.rb +29 -3
  82. data/lolita.gemspec +65 -48
  83. data/public/javascripts/lolita/tab.js +5 -0
  84. data/public/javascripts/rails.js +137 -137
  85. data/public/stylesheets/lolita/style.css +3 -1
  86. data/spec/builder_spec.rb +42 -0
  87. data/spec/configuration/field_spec.rb +29 -18
  88. data/spec/configuration/filter_spec.rb +60 -0
  89. data/spec/configuration/tab_spec.rb +28 -20
  90. data/spec/configuration/tabs_spec.rb +8 -4
  91. data/spec/controllers/lolita_rest_spec.rb +15 -0
  92. data/spec/hooks_spec.rb +191 -0
  93. data/spec/lolita_spec.rb +6 -4
  94. data/spec/navigation/tree_spec.rb +59 -0
  95. data/spec/rails_app/app/mongoid/post.rb +2 -0
  96. data/spec/rails_app/app/views/components/lolita/{list → configuration/list}/_body_cell.html.erb +0 -0
  97. data/spec/rails_app/config/application.rb +1 -0
  98. data/spec/rails_app/lib/lolita/configuration/field/my_custom_collection.rb +14 -0
  99. data/spec/simple_spec_helper.rb +1 -0
  100. data/spec/spec_helper.rb +1 -2
  101. metadata +66 -49
  102. data/README.md +0 -5
  103. data/app/helpers/components/lolita/list_component.rb +0 -9
  104. data/app/views/components/lolita/field/_collection.html.erb +0 -5
  105. data/app/views/components/lolita/field/_date.html.erb +0 -1
  106. data/app/views/components/lolita/field/_datetime.html.erb +0 -1
  107. data/app/views/components/lolita/field/_display.html.erb +0 -6
  108. data/app/views/components/lolita/field/_integer.html.erb +0 -1
  109. data/app/views/components/lolita/field/_label.html.erb +0 -1
  110. data/app/views/components/lolita/field/_select.html.erb +0 -1
  111. data/app/views/components/lolita/field/_text.html.erb +0 -27
  112. data/app/views/components/lolita/list/_body.html.erb +0 -5
  113. data/app/views/components/lolita/list/_display.html.erb +0 -11
  114. data/app/views/components/lolita/list/_header.html.erb +0 -9
  115. data/app/views/components/lolita/list/_paginator.html.erb +0 -4
  116. data/app/views/components/lolita/list/_row.html.erb +0 -7
  117. data/app/views/components/lolita/tab/_content.html.erb +0 -1
  118. data/app/views/components/lolita/tab/_default.html.erb +0 -11
  119. data/app/views/components/lolita/tab/_display.html.erb +0 -7
  120. data/app/views/components/lolita/tab/_fields.html.erb +0 -7
  121. data/lib/lolita/configuration/field/collection.rb +0 -71
  122. data/lib/lolita/configuration/field/datetime.rb +0 -10
  123. data/lib/lolita/configuration/field/disabled.rb +0 -10
  124. data/lib/lolita/configuration/field/password.rb +0 -10
  125. data/lib/lolita/configuration/field/text.rb +0 -10
  126. data/lib/lolita/hooks/base.rb +0 -58
  127. data/lib/lolita/hooks/component.rb +0 -15
  128. data/lib/lolita/hooks/hooks.rb +0 -15
@@ -1,5 +0,0 @@
1
- <tbody>
2
- <% page.each_with_index do |record,index| %>
3
- <%= render_component :"lolita/list", :row, :columns=>columns,:record=>record,:index=>index %>
4
- <% end %>
5
- </tbody>
@@ -1,11 +0,0 @@
1
- <div class="box">
2
- <%= render_component :"lolita/list", :title %>
3
- <%= render_component :"lolita/list", :new_resource%>
4
- <div class="list">
5
- <table>
6
- <%= render_component :"lolita/list", :header, :columns=>list.columns %>
7
- <%= render_component :"lolita/list", :body, :page=>page,:columns=>list.columns %>
8
- </table>
9
- </div>
10
- <%= render_component :"lolita/list", :paginator,:page=>page, :columns=>list.columns %>
11
- </div>
@@ -1,9 +0,0 @@
1
- <thead>
2
- <tr>
3
- <%= render_component :"lolita/list",:checkbox_header %>
4
- <% columns.each do |column| %>
5
- <%= render_component :"lolita/list", :header_cell, :column=>column %>
6
- <% end %>
7
- <%= render_component :"lolita/list",:tool_header %>
8
- </tr>
9
- </thead>
@@ -1,4 +0,0 @@
1
- <div class="paginator">
2
- <%= will_paginate page %>
3
- </div>
4
-
@@ -1,7 +0,0 @@
1
- <tr class="<%= @class_name %>">
2
- <%= render_component :"lolita/list", :checkbox_cell, :record=>record %>
3
- <% columns.each do |column| %>
4
- <%= render_component :"lolita/list",:body_cell, :value=>column.with_format(record.send(column.name.to_sym)) %>
5
- <% end %>
6
- <%= render_component :"lolita/list", :tool_cell,:record=>record %>
7
- </tr>
@@ -1 +0,0 @@
1
- <%= render_component :"lolita/tab", :default, :tab=>tab %>
@@ -1,11 +0,0 @@
1
- <% #
2
- # PĀRNEST ĀRĀ, LAI IR ATSEVIŠĶA VIETA, KUR DAŽĀDA TIPA TABI GLABĀJAS
3
- # piemēram, /tab_types/
4
- #
5
- %>
6
- <%= form_tag "#", :id=>"tab-form-#{tab.__id__}" do |form| %>
7
- <div class="tab-content">
8
- <%#= error_messages_for resource #TODO removed in Rails 3, now available as plugin .. %>
9
- <%= render_component :"lolita/tab", :fields, :tab=>tab %>
10
- </div>
11
- <% end %>
@@ -1,7 +0,0 @@
1
- <div class="tab box" id="tab_<%=tab.__id__%>">
2
- <div class="tab-title boxtitle black" data-closed="false">
3
- <h1><%= tab.title %></h1>
4
- <div class="arrow"></div> <%# FIXME more DRY solution is needed for .arrow within .boxtitle, maybe box helper %>
5
- </div>
6
- <%= render_component :"lolita/tab", tab.type, :tab=>tab %>
7
- </div>
@@ -1,7 +0,0 @@
1
- <% tab.fields_with_field_set do |fields_or_field,field_set| %>
2
- <% if field_set %>
3
- <%= render_component :"lolita/field_set", :display, :fields=>fields_or_field,:field_set=>field_set %>
4
- <% else %>
5
- <%= render_component :"lolita/field", :display,:field=>fields_or_field %>
6
- <% end %>
7
- <% end %>
@@ -1,71 +0,0 @@
1
- module Lolita
2
- module Configuration
3
- class CollectionField < Lolita::Configuration::Field
4
- lolita_accessor :conditions,:text_method,:value_method,:find_options,:association_type,:include_blank
5
-
6
-
7
- def initialize *args,&block
8
- @type="collection"
9
- @association_type=:one
10
- @include_blank=true
11
- super
12
- set_association_type
13
- end
14
-
15
- def options_for_select=(value=nil)
16
- @options_for_select=value
17
- end
18
-
19
- def options_for_select value=nil, &block
20
- @options_for_select=value || block if value || block_given?
21
- @options_for_select
22
- end
23
-
24
- # Collect values for collection type field.
25
- # Uses <code>text_method</code> for content. By default it search for
26
- # first _String_ type field in DB. Uses <code>value_method</code> for value,
27
- # by default it it is <code>id</code>. Use <code>conditions</code> or
28
- # <code>find_options</code> for advanced search. When <code>find_options</code>
29
- # is used, than <code>conditions</code> is ignored.
30
- def association_values() #TODO test
31
- @association_values||=if options_for_select
32
- options_for_select
33
- elsif @association
34
- klass=@dbi.association_class_name(@association).camelize.constantize
35
- current_text_method=@text_method || default_text_method(klass)
36
- current_value_method=@value_method || :id
37
- options=@find_options || {}
38
- options[:conditions]||=@conditions
39
-
40
- klass.find(:all,options).map{|r|
41
- [r.send(current_text_method),r.send(current_value_method)]
42
- }
43
- else
44
- []
45
- end
46
- @association_values
47
- end
48
-
49
- private
50
-
51
- def set_association_type #TODO test
52
- if @association
53
- @association_type||=@dbi.association_macro(@association)
54
- end
55
- end
56
-
57
- def default_text_method(klass)
58
- assoc_dbi=Lolita::DBI::Base.new(klass)
59
- field=assoc_dbi.fields.detect{|f| f[:type].downcase=="string"}
60
- if field
61
- field[:name]
62
- else
63
- raise Lolita::FieldTypeError, %^
64
- Can't find any content field in #{assoc_dbi.klass}.
65
- Use text_method in #{klass} to set one.
66
- ^
67
- end
68
- end
69
- end
70
- end
71
- end
@@ -1,10 +0,0 @@
1
- module Lolita
2
- module Configuration
3
- class DatetimeField < Lolita::Configuration::Field
4
- def initialize *args
5
- @type="datetime"
6
- super
7
- end
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- module Lolita
2
- module Configuration
3
- class DisabledField < Lolita::Configuration::Field
4
- def initialize *args
5
- @type="disabled"
6
- super
7
- end
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- module Lolita
2
- module Configuration
3
- class PasswordField < Lolita::Configuration::Field
4
- def initialize *args
5
- @type="password"
6
- super
7
- end
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- module Lolita
2
- module Configuration
3
- class TextField < Lolita::Configuration::Field
4
- def initialize *args
5
- @type="text"
6
- super
7
- end
8
- end
9
- end
10
- end
@@ -1,58 +0,0 @@
1
- module Lolita
2
- module Hooks
3
- class Base
4
-
5
- class << self
6
- def get(name)
7
- @collection||={}
8
- @collection[name]||=self.new(name)
9
- @collection[name]
10
- end
11
-
12
- def define_callback *names
13
- names.each do |name|
14
- self.class_eval <<-CALLBACK,__FILE__,__LINE__+1
15
- def #{name}(*args,&block)
16
- @callbacks||={}
17
- @callbacs[:#{name}]||={}
18
- @callbacks[:#{name}][:methods]=args || []
19
- @callbacks[:#{name}][:block]=block if block_given?
20
- end
21
-
22
- def run_#{name} scope, &block
23
- self.run(scope,:"#{name}",&block)
24
- end
25
- CALLBACK
26
- end
27
- end
28
- end
29
-
30
- # To wrap around some content, for example, html code,
31
- # call run with block.
32
- # ====Example
33
- # # in other view
34
- # Lolita::Hooks.component(:"lolita/list").replace_with do
35
- # # my new html code
36
- # end
37
- # # in view
38
- # Lolita::Hooks.component(:"lolita/list").run(self,:replace_with) do
39
- # # your old html here
40
- # end
41
- # # After this old code will be replaced with new one
42
- def run scope,name, &block
43
- @callbacks[name][:methods].each do |m|
44
- scope.send(m)
45
- end
46
- if @callbacks[name][:block]
47
- if block_given?
48
- callback[name][:block].call()
49
- else
50
- scope.instance_eval(&callbacks[name][:block])
51
- end
52
- end
53
- @callbacks[name]={}
54
- end
55
-
56
- end
57
- end
58
- end
@@ -1,15 +0,0 @@
1
- module Lolita
2
- module Hooks
3
- # Lolita::Hooks.component("lolita/list").before
4
-
5
- class Component < Lolita::Hooks::Base
6
-
7
- define_callback :before,:after,:replace_with
8
-
9
- def initialize(name)
10
-
11
- end
12
-
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- module Lolita
2
- module Hooks
3
- module Hooks
4
- def self.included(base)
5
- base.extend(SingletonMethods)
6
- end
7
-
8
- module SingletonMethods
9
- def component(name)
10
- Lolita::Hooks::Component.get(name)
11
- end
12
- end
13
- end
14
- end
15
- end