lolita 3.4.3 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +37 -36
  3. data/Gemfile +31 -29
  4. data/README.md +147 -147
  5. data/Rakefile +17 -7
  6. data/app/assets/javascripts/lolita/application.js +5 -6
  7. data/app/assets/javascripts/lolita/tab.js +98 -100
  8. data/app/assets/stylesheets/lolita/PIE-custom.htc +87 -87
  9. data/app/assets/stylesheets/lolita/PIE.htc +81 -81
  10. data/app/assets/stylesheets/lolita/application.css +7 -6
  11. data/app/assets/stylesheets/lolita/default.css.erb +169 -169
  12. data/app/assets/stylesheets/lolita/jquery-ui-1.8.16.lolita.css.erb +567 -567
  13. data/app/assets/stylesheets/lolita/style.css.erb +554 -553
  14. data/app/assets/stylesheets/tinymce/skins/lolita/content.inline.min.css +1 -0
  15. data/app/assets/stylesheets/tinymce/skins/lolita/content.min.css +1 -0
  16. data/app/assets/stylesheets/tinymce/skins/lolita/fonts/readme.md +1 -0
  17. data/app/assets/stylesheets/tinymce/skins/lolita/fonts/tinymce-small.eot +0 -0
  18. data/app/assets/stylesheets/tinymce/skins/lolita/fonts/tinymce-small.svg +175 -0
  19. data/app/assets/stylesheets/tinymce/skins/lolita/fonts/tinymce-small.ttf +0 -0
  20. data/app/assets/stylesheets/tinymce/skins/lolita/fonts/tinymce-small.woff +0 -0
  21. data/app/assets/stylesheets/tinymce/skins/lolita/fonts/tinymce.eot +0 -0
  22. data/app/assets/stylesheets/tinymce/skins/lolita/fonts/tinymce.svg +153 -0
  23. data/app/assets/stylesheets/tinymce/skins/lolita/fonts/tinymce.ttf +0 -0
  24. data/app/assets/stylesheets/tinymce/skins/lolita/fonts/tinymce.woff +0 -0
  25. data/app/assets/stylesheets/tinymce/skins/lolita/img/anchor.gif +0 -0
  26. data/app/assets/stylesheets/tinymce/skins/lolita/img/loader.gif +0 -0
  27. data/app/assets/stylesheets/tinymce/skins/lolita/img/object.gif +0 -0
  28. data/app/assets/stylesheets/tinymce/skins/lolita/img/trans.gif +0 -0
  29. data/app/assets/stylesheets/tinymce/skins/lolita/img/wline.gif +0 -0
  30. data/app/assets/stylesheets/tinymce/skins/lolita/skin.ie7.min.css +1 -0
  31. data/app/assets/stylesheets/tinymce/skins/lolita/skin.min.css +2 -0
  32. data/app/helpers/components/lolita/configuration/list_component.rb +10 -10
  33. data/app/helpers/components/lolita/configuration_component.rb +21 -21
  34. data/app/views/components/lolita/configuration/column/_first.html.haml +1 -1
  35. data/app/views/components/lolita/configuration/column/header/_first.html.haml +1 -1
  36. data/app/views/components/lolita/configuration/column/header/_sort.html.haml +6 -6
  37. data/app/views/components/lolita/configuration/columns/body/_display.html.haml +1 -1
  38. data/app/views/components/lolita/configuration/columns/header/_display.html.haml +5 -5
  39. data/app/views/components/lolita/configuration/field/array/checkbox/_display.html.haml +7 -7
  40. data/app/views/components/lolita/configuration/field/string/text/_display.html.haml +4 -7
  41. data/app/views/components/lolita/configuration/search/_display.html.haml +2 -2
  42. data/app/views/components/lolita/configuration/tab/_display.html.haml +4 -4
  43. data/app/views/components/lolita/configuration/tabs/_form.html.haml +7 -6
  44. data/app/views/components/lolita/configuration/tabs/yo.html +1 -0
  45. data/app/views/kaminari/lolita/_first_page.html.erb +11 -11
  46. data/app/views/kaminari/lolita/_gap.html.erb +8 -8
  47. data/app/views/kaminari/lolita/_last_page.html.erb +11 -11
  48. data/app/views/kaminari/lolita/_next_page.html.erb +11 -11
  49. data/app/views/kaminari/lolita/_page.html.erb +12 -12
  50. data/app/views/kaminari/lolita/_paginator.html.erb +23 -23
  51. data/app/views/kaminari/lolita/_prev_page.html.erb +11 -11
  52. data/app/views/lolita/info/index.html.erb +232 -232
  53. data/author +1 -1
  54. data/config/locales/sv_SE.yml +37 -0
  55. data/config/routes.rb +6 -6
  56. data/lib/generators/lolita/install_generator.rb +22 -19
  57. data/lib/generators/lolita/uninstall_generator.rb +76 -71
  58. data/lib/generators/templates/lolita.rb +17 -14
  59. data/lib/generators/templates/tinymce.yml +22 -0
  60. data/lib/lolita.rb +142 -141
  61. data/lib/lolita/adapter/abstract_adapter.rb +17 -16
  62. data/lib/lolita/adapter/active_record.rb +229 -227
  63. data/lib/lolita/adapter/common_helper.rb +220 -221
  64. data/lib/lolita/adapter/field_helper.rb +18 -18
  65. data/lib/lolita/adapter/mongoid.rb +244 -241
  66. data/lib/lolita/components/base.rb +10 -12
  67. data/lib/lolita/configuration.rb +61 -61
  68. data/lib/lolita/configuration/column.rb +170 -181
  69. data/lib/lolita/configuration/field/big_decimal.rb +12 -12
  70. data/lib/lolita/configuration/field/boolean.rb +12 -12
  71. data/lib/lolita/configuration/field/date.rb +12 -12
  72. data/lib/lolita/configuration/field/hidden.rb +12 -12
  73. data/lib/lolita/configuration/field/integer.rb +11 -11
  74. data/lib/lolita/configuration/field/string.rb +16 -16
  75. data/lib/lolita/configuration/field/time.rb +13 -13
  76. data/lib/lolita/configuration/field_set.rb +25 -25
  77. data/lib/lolita/configuration/filter.rb +130 -116
  78. data/lib/lolita/configuration/list.rb +201 -201
  79. data/lib/lolita/configuration/search.rb +105 -105
  80. data/lib/lolita/controllers/component_helpers.rb +156 -156
  81. data/lib/lolita/controllers/internal_helpers.rb +74 -71
  82. data/lib/lolita/dbi/base.rb +56 -56
  83. data/lib/lolita/hooks/named_hook.rb +125 -125
  84. data/lib/lolita/lazy_loader.rb +54 -54
  85. data/lib/lolita/navigation/tree.rb +132 -132
  86. data/lib/lolita/rails/engine.rb +29 -24
  87. data/lib/lolita/rails/routes.rb +133 -129
  88. data/lib/lolita/ruby_ext/accessors.rb +26 -26
  89. data/lib/lolita/search/simple.rb +75 -75
  90. data/lib/lolita/support/formatter.rb +62 -62
  91. data/lib/lolita/support/formatter/rails.rb +56 -56
  92. data/lib/lolita/system_configuration/base.rb +182 -178
  93. data/lib/lolita/test/matchers.rb +77 -77
  94. data/lib/lolita/version.rb +30 -30
  95. data/lolita.gemspec +35 -34
  96. data/spec/adapter/common_helper_spec.rb +96 -96
  97. data/spec/builder_spec.rb +120 -120
  98. data/spec/configuration/base_spec.rb +23 -23
  99. data/spec/configuration/field_spec.rb +117 -118
  100. data/spec/configuration/filter_spec.rb +145 -131
  101. data/spec/configuration/tab_spec.rb +184 -187
  102. data/spec/configuration/tabs_spec.rb +116 -120
  103. data/spec/generators/lolita/install_generator_spec.rb +70 -55
  104. data/spec/generators/lolita/uninstall_generator_spec.rb +65 -49
  105. data/spec/helpers/url_for_spec.rb +8 -0
  106. data/spec/orm/active_record.rb +53 -0
  107. data/spec/orm/mongoid.rb +2 -13
  108. data/spec/orm/mongoid.yml +6 -0
  109. data/spec/rails_app/app/controllers/application_controller.rb +3 -3
  110. data/spec/rails_app/app/helpers/application_helper.rb +3 -3
  111. data/spec/rails_app/app/orm/active_record/address.rb +3 -0
  112. data/spec/rails_app/app/orm/active_record/category.rb +16 -0
  113. data/spec/rails_app/app/orm/active_record/comment.rb +4 -0
  114. data/spec/rails_app/app/orm/active_record/post.rb +24 -0
  115. data/spec/rails_app/app/orm/active_record/preference.rb +4 -0
  116. data/spec/rails_app/app/orm/active_record/profile.rb +9 -0
  117. data/spec/rails_app/app/orm/active_record/tag.rb +2 -0
  118. data/spec/rails_app/app/{mongoid → orm/mongoid}/address.rb +7 -7
  119. data/spec/rails_app/app/{mongoid → orm/mongoid}/category.rb +18 -19
  120. data/spec/rails_app/app/{mongoid → orm/mongoid}/comment.rb +5 -5
  121. data/spec/rails_app/app/{mongoid → orm/mongoid}/post.rb +30 -30
  122. data/spec/rails_app/app/{mongoid → orm/mongoid}/preference.rb +5 -5
  123. data/spec/rails_app/app/{mongoid → orm/mongoid}/profile.rb +13 -14
  124. data/spec/rails_app/app/{mongoid → orm/mongoid}/tag.rb +3 -3
  125. data/spec/rails_app/app/views/components/lolita/configuration/list/_body_cell.html.erb +1 -1
  126. data/spec/rails_app/config/application.rb +34 -33
  127. data/spec/rails_app/config/boot.rb +7 -8
  128. data/spec/rails_app/config/environment.rb +5 -5
  129. data/spec/rails_app/config/environments/development.rb +22 -23
  130. data/spec/rails_app/config/environments/production.rb +37 -37
  131. data/spec/rails_app/config/environments/test.rb +36 -37
  132. data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -7
  133. data/spec/rails_app/config/initializers/inflections.rb +2 -2
  134. data/spec/rails_app/config/initializers/secret_token.rb +1 -1
  135. data/spec/rails_app/config/routes.rb +4 -3
  136. data/spec/rails_app/lib/lolita/configuration/field/my_custom_collection.rb +13 -13
  137. data/spec/rails_app/public/javascripts/jquery-1.5.1.min.js +15 -15
  138. data/spec/rails_app/public/javascripts/lolita/main.js +6 -6
  139. data/spec/rails_app/public/javascripts/modernizr-1.7.min.js +1 -1
  140. data/spec/rails_app/public/javascripts/rails.js +137 -137
  141. data/spec/rails_app/public/javascripts/tinymce/langs/en.js +221 -221
  142. data/spec/rails_app/public/javascripts/tinymce/license.txt +504 -504
  143. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/about.htm +52 -52
  144. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/anchor.htm +26 -26
  145. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/charmap.htm +51 -51
  146. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/color_picker.htm +74 -74
  147. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/editor_template_src.js +1328 -1328
  148. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/image.htm +80 -80
  149. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/about.js +73 -73
  150. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/anchor.js +42 -42
  151. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/charmap.js +354 -354
  152. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/color_picker.js +329 -329
  153. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/image.js +247 -247
  154. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/link.js +153 -153
  155. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/source_editor.js +56 -56
  156. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/langs/en.js +68 -68
  157. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/langs/en_dlg.js +53 -53
  158. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/link.htm +57 -57
  159. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/shortcuts.htm +47 -47
  160. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/skins/cirkuit/content.css +66 -66
  161. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/skins/cirkuit/dialog.css +117 -117
  162. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/skins/cirkuit/ui.css +988 -988
  163. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/source_editor.htm +25 -25
  164. data/spec/rails_app/public/javascripts/tinymce/tiny_mce_popup.js +4 -4
  165. data/spec/rails_app/public/stylesheets/lolita/default.css +169 -169
  166. data/spec/rails_app/public/stylesheets/lolita/style.css +214 -214
  167. data/spec/spec_helper.rb +44 -51
  168. data/spec/support/cleaner.rb +12 -0
  169. data/vendor/assets/javascripts/application_vendor_lolita.js +5 -4
  170. data/vendor/assets/javascripts/jquery-numeric.js +279 -279
  171. data/vendor/assets/javascripts/modernizr_1_7_min.js +1 -1
  172. data/vendor/assets/stylesheets/jquery-ui-1.8.16.custom.css +567 -567
  173. metadata +105 -72
  174. data/lib/tasks/tinymce-assets.rake +0 -7
  175. data/spec/adapter_helper.rb +0 -43
  176. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/content.css +0 -66
  177. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/dialog.css +0 -117
  178. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/img/butt2.png +0 -0
  179. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/img/button-bg.png +0 -0
  180. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/img/buttons.png +0 -0
  181. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/img/down_arrow.gif +0 -0
  182. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/img/fade-butt.png +0 -0
  183. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/img/icons.png +0 -0
  184. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/img/items.gif +0 -0
  185. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/img/menu-arrow.png +0 -0
  186. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/img/menu-check.png +0 -0
  187. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/img/progress.gif +0 -0
  188. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/img/tabs.gif +0 -0
  189. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/img/toolbarbg.png +0 -0
  190. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/ui.css +0 -988
@@ -1,157 +1,157 @@
1
- module Lolita
2
- module Controllers
3
- # Helper that add #render_component method. That is shortstand for render :partial for lolita
4
- # partial files. Also it provide view hooks for Lolita.
5
- # For any component there may be helper module. Modules are include in current view or
6
- # controller instance when component is rendered.
7
- # All components ar placed in "app/helpers/components/[your component path]".
8
- # Component should have fallowing module structure Components::[NameSpace]::[Component name]Component
9
- # Components::Lolita::ListComponent
10
- # ====Example
11
- # render_component :"lolita/configuration/list", :dispaly
12
- # # try to find /helpers/components/lolita/list_component.rb in every directory in $: that
13
- # # ends with /helpers
14
- # # require this file if found and extend self with Components::Lolita::ListComponent.
15
- # Component helpers is loaded in same order as views or controller.
16
- module ComponentHelpers
17
- # Render partial template.
18
- # Accept:
19
- # <tt>name</tt> - name for component in '/components' directory,
20
- # can be full name too.
21
- # Example 'lolita/list'
22
- # <tt>state</tt> - name for partial. Example 'row'.
23
- # <tt>options</tt> - any options to pass as <code>:locals</code> to partial,
24
- # also available through <code>@opts</code> variable.
25
- # =====Example
26
- # render_component "lolita/list", :display
27
- # render_component "lolita/list/display"
28
- def render_component *args
29
- @rendering_components ||= []
30
- name,state,options=get_render_options(*args)
31
- format=options.delete(:format)
32
- raise "Can't render component without name!" unless name
33
- will_use_component name
34
- component_name=File.join(name.to_s,state ? "#{!Lolita.rails? && "_" || ""}#{state}" : "")
35
- partial_name=File.join("/components",component_name)
36
-
37
- @rendering_components.push(component_name)
38
- @current_component_name = component_name
39
- output = output_component(partial_name,component_name,:format=>format ,:locals=>options)
40
- @rendering_components.pop
41
- @current_component_name = @rendering_components.last
42
- self.respond_to?(:raw) ? raw(output) : output
43
- end
44
-
45
- def get_render_options *args
46
- options=args.extract_options!
47
- if args.first.respond_to?(:build)
48
- name,state,options=args[0].build("",args[1],options)
49
- elsif args.first.class.ancestors.include?(Lolita::Configuration)
50
- raise ArgumentError, "Include Lolita::Builder in #{args.first.class}"
51
- else
52
- name,state=args
53
- name = "/#{name}" unless name.to_s.match(/^\//)
54
- end
55
- return name,state,options
56
- end
57
-
58
- def output_component(partial_name,name,options={})
59
- output=""
60
- if options[:format]
61
- with_format(options[:format]) do
62
- output << output_with_callbacks(partial_name,name,options[:locals])
63
- end
64
- else
65
- output << output_with_callbacks(partial_name,name,options[:locals])
66
- end
67
- output
68
- end
69
-
70
- def output_with_callbacks(partial_name,name,locals)
71
- @component_locals ||={}
72
- @component_locals[name] = locals
73
- output = Lolita::Hooks.component(name).run(:before,:run_scope => self).to_s
74
- block_output = Lolita::Hooks.component(name).run(:around, :run_scope => self) do
75
- if Lolita.rails?
76
- render(:partial => partial_name, :locals => locals)
77
- else
78
- haml :"#{partial_name}.html", :locals => locals
79
- end
80
- end
81
- #FIXME does block_output raises error?
82
- output << block_output.to_s
83
- output << Lolita::Hooks.component(name).run(:after,:run_scope => self).to_s
84
- @component_locals[name] = nil
85
- output
86
- end
87
-
88
- def with_format(format, &block)
89
- old_formats = formats
90
- self.formats = [format]
91
- result=block.call
92
- self.formats = old_formats
93
- result
94
- end
95
-
96
- # Require component helper file and extend current instance with component helper module.
97
- # ====Example
98
- # will_use_component :"lolita/configuration/list"
99
- def will_use_component component_name
100
- helpers_for_component(component_name) do |possible_component_name|
101
- @used_component_helpers||={}
102
- unless @used_component_helpers.include?(possible_component_name)
103
- if path=component_helper_path(possible_component_name)
104
- self.class.class_eval do
105
- require path
106
- end
107
- class_name=possible_component_name.to_s.camelize
108
- helper_module = "Components::#{class_name}Component".constantize rescue nil
109
- if helper_module
110
- self.extend(helper_module)
111
- end
112
- end
113
- @used_component_helpers[possible_component_name] = helper_module
114
- else
115
- if helper_module = @used_component_helpers[possible_component_name]
116
- self.extend(helper_module)
117
- end
118
- end
119
- end
120
- end
121
-
122
- def helpers_for_component component_name
123
- names=component_name.to_s.gsub(/^\//,"").split("/")
124
- start_index=1 # first is lolita
125
- start_index.upto(names.size) do |index|
126
- yield names.slice(0..index).join("/")
127
- end
128
- end
129
-
130
- # Find path for given component.
131
- #
132
- # component_helper_path :"lolita/list" #=> [path_to_lolita]/app/helpers/components/lolita/list_component.rb
133
- def component_helper_path component_name
134
- @helper_paths||=$:.reject{|p| !p.match(/\/helpers$/) rescue nil}
135
- get_path=lambda{|paths|
136
- extra_path=component_name.to_s.split("/")
137
- component=extra_path.pop
138
- paths.each do |path|
139
- new_path=File.join(path,"components",*extra_path,"#{component}_component.rb")
140
- if File.exist?(new_path)
141
- return new_path
142
- end
143
- end
144
- nil
145
- }
146
- path=get_path.call(@helper_paths)
147
- path
148
- end
149
-
150
- # Return locals for component that will be rendered next. Very useful in hook views, where is no locals.
151
- def component_locals
152
- @component_locals[@current_component_name]
153
- end
154
-
155
- end
156
- end
1
+ module Lolita
2
+ module Controllers
3
+ # Helper that add #render_component method. That is shortstand for render :partial for lolita
4
+ # partial files. Also it provide view hooks for Lolita.
5
+ # For any component there may be helper module. Modules are include in current view or
6
+ # controller instance when component is rendered.
7
+ # All components ar placed in "app/helpers/components/[your component path]".
8
+ # Component should have fallowing module structure Components::[NameSpace]::[Component name]Component
9
+ # Components::Lolita::ListComponent
10
+ # ====Example
11
+ # render_component :"lolita/configuration/list", :dispaly
12
+ # # try to find /helpers/components/lolita/list_component.rb in every directory in $: that
13
+ # # ends with /helpers
14
+ # # require this file if found and extend self with Components::Lolita::ListComponent.
15
+ # Component helpers is loaded in same order as views or controller.
16
+ module ComponentHelpers
17
+ # Render partial template.
18
+ # Accept:
19
+ # <tt>name</tt> - name for component in '/components' directory,
20
+ # can be full name too.
21
+ # Example 'lolita/list'
22
+ # <tt>state</tt> - name for partial. Example 'row'.
23
+ # <tt>options</tt> - any options to pass as <code>:locals</code> to partial,
24
+ # also available through <code>@opts</code> variable.
25
+ # =====Example
26
+ # render_component "lolita/list", :display
27
+ # render_component "lolita/list/display"
28
+ def render_component *args
29
+ @rendering_components ||= []
30
+ name,state,options=get_render_options(*args)
31
+ format=options.delete(:format)
32
+ raise "Can't render component without name!" unless name
33
+ will_use_component name
34
+ component_name=File.join(name.to_s,state ? "#{!Lolita.rails? && "_" || ""}#{state}" : "")
35
+ partial_name=File.join("/components",component_name)
36
+
37
+ @rendering_components.push(component_name)
38
+ @current_component_name = component_name
39
+ output = output_component(partial_name,component_name,:format=>format ,:locals=>options)
40
+ @rendering_components.pop
41
+ @current_component_name = @rendering_components.last
42
+ self.respond_to?(:raw) ? raw(output) : output
43
+ end
44
+
45
+ def get_render_options *args
46
+ options=args.extract_options!
47
+ if args.first.respond_to?(:build)
48
+ name,state,options=args[0].build("",args[1],options)
49
+ elsif args.first.class.ancestors.include?(Lolita::Configuration)
50
+ raise ArgumentError, "Include Lolita::Builder in #{args.first.class}"
51
+ else
52
+ name,state=args
53
+ name = "/#{name}" unless name.to_s.match(/^\//)
54
+ end
55
+ return name,state,options
56
+ end
57
+
58
+ def output_component(partial_name,name,options={})
59
+ output=""
60
+ if options[:format]
61
+ with_format(options[:format]) do
62
+ output << output_with_callbacks(partial_name,name,options[:locals])
63
+ end
64
+ else
65
+ output << output_with_callbacks(partial_name,name,options[:locals])
66
+ end
67
+ output
68
+ end
69
+
70
+ def output_with_callbacks(partial_name,name,locals)
71
+ @component_locals ||={}
72
+ @component_locals[name] = locals
73
+ output = Lolita::Hooks.component(name).run(:before,:run_scope => self).to_s
74
+ block_output = Lolita::Hooks.component(name).run(:around, :run_scope => self) do
75
+ if Lolita.rails?
76
+ render(:partial => partial_name, :locals => locals)
77
+ else
78
+ haml :"#{partial_name}.html", :locals => locals
79
+ end
80
+ end
81
+ #FIXME does block_output raises error?
82
+ output << block_output.to_s
83
+ output << Lolita::Hooks.component(name).run(:after,:run_scope => self).to_s
84
+ @component_locals[name] = nil
85
+ output
86
+ end
87
+
88
+ def with_format(format, &block)
89
+ old_formats = formats
90
+ self.formats = [format]
91
+ result=block.call
92
+ self.formats = old_formats
93
+ result
94
+ end
95
+
96
+ # Require component helper file and extend current instance with component helper module.
97
+ # ====Example
98
+ # will_use_component :"lolita/configuration/list"
99
+ def will_use_component component_name
100
+ helpers_for_component(component_name) do |possible_component_name|
101
+ @used_component_helpers||={}
102
+ unless @used_component_helpers.include?(possible_component_name)
103
+ if path=component_helper_path(possible_component_name)
104
+ self.class.class_eval do
105
+ require path
106
+ end
107
+ class_name=possible_component_name.to_s.camelize
108
+ helper_module = "Components::#{class_name}Component".constantize rescue nil
109
+ if helper_module
110
+ self.extend(helper_module)
111
+ end
112
+ end
113
+ @used_component_helpers[possible_component_name] = helper_module
114
+ else
115
+ if helper_module = @used_component_helpers[possible_component_name]
116
+ self.extend(helper_module)
117
+ end
118
+ end
119
+ end
120
+ end
121
+
122
+ def helpers_for_component component_name
123
+ names=component_name.to_s.gsub(/^\//,"").split("/")
124
+ start_index=1 # first is lolita
125
+ start_index.upto(names.size) do |index|
126
+ yield names.slice(0..index).join("/")
127
+ end
128
+ end
129
+
130
+ # Find path for given component.
131
+ #
132
+ # component_helper_path :"lolita/list" #=> [path_to_lolita]/app/helpers/components/lolita/list_component.rb
133
+ def component_helper_path component_name
134
+ @helper_paths||=$:.reject{|p| !p.match(/\/helpers$/) rescue nil}
135
+ get_path=lambda{|paths|
136
+ extra_path=component_name.to_s.split("/")
137
+ component=extra_path.pop
138
+ paths.each do |path|
139
+ new_path=File.join(path,"components",*extra_path,"#{component}_component.rb")
140
+ if File.exist?(new_path)
141
+ return new_path
142
+ end
143
+ end
144
+ nil
145
+ }
146
+ path=get_path.call(@helper_paths)
147
+ path
148
+ end
149
+
150
+ # Return locals for component that will be rendered next. Very useful in hook views, where is no locals.
151
+ def component_locals
152
+ @component_locals[@current_component_name]
153
+ end
154
+
155
+ end
156
+ end
157
157
  end
@@ -1,71 +1,74 @@
1
- module Lolita
2
- module Controllers
3
- module InternalHelpers
4
- def include_application_assets
5
- result = ''
6
- Lolita.application.assets.each do |asset_name|
7
- if asset_name.match(/\.js(\.|$)/)
8
- result << javascript_include_tag(asset_name)
9
- elsif asset_name.match(/\.css(\.|$)/)
10
- result << stylesheet_link_tag(asset_name)
11
- end
12
- end
13
- raw(result)
14
- end
15
-
16
- def resource
17
- instance_variable_get(:"@#{resource_name}")
18
- end
19
-
20
- def resource_name
21
- lolita_mapping.class_name.gsub(/::/, '_').underscore.to_sym
22
- end
23
-
24
- def resource_class
25
- lolita_mapping.to
26
- end
27
-
28
- def lolita_mapping(new_mapping = nil)
29
- @lolita_mapping ||= request.env['lolita.mapping']
30
- end
31
-
32
- def current_form=(form)
33
- @current_form = form
34
- end
35
-
36
- def current_form(temp_form = nil)
37
- if block_given?
38
- old_form = @current_form
39
- @current_form = temp_form
40
- content = yield
41
- @current_form = old_form
42
- end
43
- @current_form
44
- end
45
-
46
- def use_mapping(new_mapping)
47
- if block_given?
48
- begin
49
- @old_mapping = lolita_mapping
50
- @lolita_mapping = new_mapping
51
- yield
52
- ensure
53
- @lolita_mapping = @old_mapping
54
- @old_mapping = nil
55
- end
56
- end
57
- end
58
-
59
- def is_lolita_resource?
60
- fail ActionController::UnknownAction unless lolita_mapping
61
- true
62
- end
63
-
64
- protected
65
-
66
- def resource=(new_resource)
67
- instance_variable_set(:"@#{resource_name}", new_resource)
68
- end
69
- end
70
- end
71
- end
1
+ module Lolita
2
+ module Controllers
3
+ module InternalHelpers
4
+ def include_application_assets
5
+ result = ''
6
+ Lolita.application.assets.each do |asset_name|
7
+ if asset_name.match(/\.js(\.|$)/)
8
+ result << javascript_include_tag(asset_name)
9
+ elsif asset_name.match(/\.css(\.|$)/)
10
+ result << stylesheet_link_tag(asset_name)
11
+ end
12
+ end
13
+ raw(result)
14
+ end
15
+
16
+ def resource
17
+ instance_variable_get(:"@#{resource_name}")
18
+ end
19
+
20
+ def resource_name
21
+ lolita_mapping.class_name.underscore.to_sym
22
+ end
23
+
24
+ def resource_class
25
+ lolita_mapping.to
26
+ end
27
+
28
+ def lolita_mapping(new_mapping = nil)
29
+ @lolita_mapping ||= request.env["lolita.mapping"]
30
+ end
31
+
32
+ def current_form=(form)
33
+ @current_form = form
34
+ end
35
+
36
+ def current_form(temp_form = nil)
37
+ if block_given?
38
+ old_form = @current_form
39
+ @current_form = temp_form
40
+ content = yield
41
+ @current_form = old_form
42
+ end
43
+ @current_form
44
+ end
45
+
46
+ def use_mapping(new_mapping)
47
+ if block_given?
48
+ begin
49
+ @old_mapping = lolita_mapping
50
+ @lolita_mapping = new_mapping
51
+ yield
52
+ ensure
53
+ @lolita_mapping = @old_mapping
54
+ @old_mapping = nil
55
+ end
56
+ end
57
+ end
58
+
59
+ def is_lolita_resource?
60
+ fail ActionController::UnknownAction unless lolita_mapping
61
+ true
62
+ end
63
+
64
+ protected
65
+
66
+
67
+ def resource=(new_resource)
68
+ instance_variable_set(:"@#{resource_name}",new_resource)
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+ end