lolita 3.1.16 → 3.1.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/Gemfile +2 -1
  2. data/History.rdoc +10 -0
  3. data/VERSION +1 -1
  4. data/app/views/components/lolita/configuration/field/_display.html.erb +1 -1
  5. data/app/views/components/lolita/configuration/field/_label.html.erb +1 -1
  6. data/app/views/components/lolita/configuration/field/array/habtm/_display.html.haml +1 -1
  7. data/app/views/components/lolita/configuration/field/array/select/_display.html.erb +1 -1
  8. data/app/views/components/lolita/configuration/list/_paginator.html.erb +1 -1
  9. data/app/views/components/lolita/configuration/nested_form/_display.html.erb +3 -3
  10. data/app/views/components/lolita/configuration/nested_form/_fields.html.erb +1 -1
  11. data/app/views/components/lolita/configuration/tab/_display.html.erb +4 -13
  12. data/app/views/components/lolita/configuration/tab/_error_msg.html.erb +14 -0
  13. data/app/views/components/lolita/configuration/tab/_form.html.erb +1 -1
  14. data/app/views/components/lolita/shared/_header.html.erb +1 -1
  15. data/app/views/kaminari/lolita/_first_page.html.erb +11 -0
  16. data/app/views/kaminari/lolita/_gap.html.erb +8 -0
  17. data/app/views/kaminari/lolita/_last_page.html.erb +11 -0
  18. data/app/views/kaminari/lolita/_next_page.html.erb +11 -0
  19. data/app/views/kaminari/lolita/_page.html.erb +12 -0
  20. data/app/views/kaminari/lolita/_paginator.html.erb +23 -0
  21. data/app/views/kaminari/lolita/_prev_page.html.erb +11 -0
  22. data/app/views/layouts/lolita/application.html.erb +5 -3
  23. data/config/locales/en.yml +2 -0
  24. data/config/locales/lv.yml +10 -1
  25. data/lib/lolita/configuration/field/array.rb +10 -0
  26. data/lib/lolita/configuration/helper.rb +1 -1
  27. data/lib/lolita/configuration/nested_form.rb +33 -0
  28. data/lib/lolita/rails.rb +5 -1
  29. data/lib/lolita/system_configuration/application.rb +21 -0
  30. data/lib/lolita/system_configuration/base.rb +161 -0
  31. data/lib/lolita.rb +6 -2
  32. data/lolita.gemspec +15 -3
  33. data/public/javascripts/lolita/tab.js +9 -14
  34. data/public/stylesheets/lolita/style.css +114 -19
  35. data/spec/lolita_spec.rb +1 -1
  36. metadata +52 -32
  37. data/lib/lolita/base_configuration.rb +0 -166
data/Gemfile CHANGED
@@ -5,10 +5,11 @@ gem "rails", "~>3.0.10"
5
5
  gem "kaminari", "~>0.12.4"
6
6
  gem "abstract"
7
7
  gem "builder", "~> 2.1.2" #cucumber asks for builder 3 but rails supports 2.1
8
+ gem "haml", "~> 3.1.2"
8
9
 
9
10
  group :mongoid do
10
11
  gem "mongo", "~> 1.3.0"
11
- gem "mongoid", "~> 2.0.0"
12
+ gem "mongoid", "~> 2.1.7"
12
13
  gem "bson_ext", "~> 1.3.0"
13
14
  end
14
15
 
data/History.rdoc CHANGED
@@ -1,3 +1,13 @@
1
+ === Version 3.1.17 / 2011-09-01
2
+ * Bug fixes
3
+ * Error explanation updated with nested errors
4
+
5
+ * Enhancements
6
+ * Array field have special method for values
7
+ * HAML support added
8
+ * look improved
9
+ * project configuration added
10
+
1
11
  === Version 3.1.16 / 2011-08-30
2
12
  * Bug fixes
3
13
  * Component helper name detection fixed
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.16
1
+ 3.1.17
@@ -1,4 +1,4 @@
1
- <div class="field" id="field_<%=field.__id__%>">
1
+ <div class="field <%= field.type %>" id="field_<%=field.__id__%>">
2
2
  <% unless field.type == "hidden" %>
3
3
  <%= render_component *field.build(:name=>"/lolita/configuration/field", :state => :"label") %>
4
4
  <% end %>
@@ -1 +1 @@
1
- <%= label resource_name, field.name, raw(field.title.to_s.capitalize), :id=>"field_#{field.__id__}_label" %>
1
+ <%= tab_form.label field.name, raw(field.title.to_s.capitalize), :id=>"field_#{field.__id__}_label" %>
@@ -1,5 +1,5 @@
1
1
  = hidden_field_tag "#{resource_name}[#{field.name.to_s.singularize}_ids][]",""
2
- - field.association_values.call.each do |value|
2
+ - field.view_values(self).each do |value|
3
3
  - editors = resource.send(:"#{field.name.to_s.singularize}_ids")
4
4
  .habtm-container
5
5
  = label_tag "#{resource_name}_#{field.name}_#{value.last}",value.first, :class => "habtm-label"
@@ -1,4 +1,4 @@
1
1
  <%= tab_form.select field.name,
2
- (field.association_values.respond_to?(:call) ? field.association_values.call(self) : field.association_values),
2
+ (field.view_values(self)),
3
3
  {:include_blank => field.include_blank},
4
4
  field.html_options || {} %>
@@ -1 +1 @@
1
- <%= paginate(page) %>
1
+ <%= paginate page, :theme => "lolita" %>
@@ -1,13 +1,13 @@
1
1
  <div class="nested_form" id=<%= "nested_form_#{nested_form.__id__}" %>>
2
2
  <% unless nested_form.field_style == :normal %>
3
- <%= label_tag nested_form.name %>
3
+ <%= render_component *nested_form.as_field.build(:name=>"/lolita/configuration/field", :state => :"label") %>
4
4
  <% end %>
5
- <%= tab_form.fields_for nested_form.name do |form| %>
5
+ <%= tab_form.fields_for nested_form.name, resource.send(nested_form.build_method) do |form| %>
6
6
  <% tab_form(form) do %>
7
7
  <%= render_component nested_form, :fields %>
8
8
  <% end %>
9
9
  <% end %>
10
- <% if nested_form.expandable? %>
10
+ <% if nested_form.expandable? && !nested_form.update_only? %>
11
11
  <p><%= link_to_add_fields ::I18n.t("lolita.nested_form.add", :resource_name => nested_form.klass.model_name.human.downcase), tab_form, nested_form %> </p>
12
12
  <% end %>
13
13
  </div>
@@ -6,7 +6,7 @@
6
6
  <%= render_component field %>
7
7
  <% end %>
8
8
  <% end %>
9
- <% if nested_form.expandable? %>
9
+ <% if nested_form.expandable? && nested_form.allow_destroy? %>
10
10
  <%= link_to_remove_fields I18n.t("lolita.shared.delete").downcase, tab_form %>
11
11
  <% end %>
12
12
  </div>
@@ -1,17 +1,8 @@
1
- <div class="tab box" id="tab_<%=tab.__id__%>">
2
- <div class="tab-title boxtitle black" data-closed="false">
1
+ <div class="tab box <%=resource.lolita.tabs.first == tab ? "first-tab" : "default minimized"%>" id="tab_<%=tab.__id__%>">
2
+ <div class="tab-title boxtitle <%= resource.lolita.tabs.first == tab ? "black" : "grey"%>" >
3
3
  <h1><%= tab.title %></h1>
4
- <div class="arrow"></div> <%# FIXME more DRY solution is needed for .arrow within .boxtitle, maybe box helper %>
4
+ <div class="arrow"></div>
5
5
  </div>
6
- <% if resource.errors.any? %>
7
- <p class="errorExplanation" id="errorExplanation">
8
- <%= raw resource.errors.keys.collect{|k|
9
- if error_tab = tab.fields.by_name(k)
10
- "#{error_tab.title.humanize.capitalize}: "+
11
- "#{resource.errors[k].collect{|m| m.capitalize}.join(" and ")}"
12
- end
13
- }.compact.join("<br>") %>
14
- </p>
15
- <% end %>
6
+ <%= render_component "lolita/configuration/tab", :error_msg, :tab => tab %>
16
7
  <%= render_component "lolita/configuration/tab", :form, :tab => tab %>
17
8
  </div>
@@ -0,0 +1,14 @@
1
+ <% if resource.errors.any? %>
2
+ <p class="errorExplanation" id="errorExplanation">
3
+ <%= raw resource.errors.keys.collect{|k|
4
+ title = if k.to_s.match(/\./)
5
+ assoc_name, attr_name = k.to_s.split(".")
6
+ klass = resource.lolita.dbi.reflect_on_association(assoc_name.to_sym).klass
7
+ klass.human_attribute_name(attr_name).downcase
8
+ else
9
+ resource.class.human_attribute_name(k)
10
+ end
11
+ "#{title.to_s.capitalize}: #{resource.errors[k].join(" #{::I18n.t("lolita.shared.and")} ")}"
12
+ }.compact.join("<br>") %>
13
+ </p>
14
+ <% end %>
@@ -1,7 +1,7 @@
1
1
  <%
2
2
  #This partial is useful for hooks. You don't need to hook in each tab, but you can hook here, that is common to all tabs
3
3
  %>
4
- <%= form_for resource, :url => "#",:html => {:multipart=>true, :id=>"tab-form-#{tab.__id__}",:method => resource.new_record? ? :post : :put} do |form| %>
4
+ <%= form_for resource, :url => "#",:html => {:onsubmit => "return false;",:multipart=>true, :id=>"tab-form-#{tab.__id__}",:method => resource.new_record? ? :post : :put} do |form| %>
5
5
  <% self.tab_form = form %>
6
6
  <%= render_component *tab.build %>
7
7
  <% end %>
@@ -1,5 +1,5 @@
1
1
  <header>
2
- <h1>Lolita</h1>
2
+ <h1><%=Lolita.application.name %></h1>
3
3
  <% if lolita_current_user %>
4
4
  <nav>
5
5
  <a href="<%=send(:"edit_#{lolita_current_user.class.to_s.downcase}_password_path")%>" class="username"><%=lolita_current_user.email%></a>
@@ -0,0 +1,11 @@
1
+ <%# Link to the "First" page
2
+ - available local variables
3
+ url: url to the first page
4
+ current_page: a page object for the currently displayed page
5
+ num_pages: total number of pages
6
+ per_page: number of items to fetch per page
7
+ remote: data-remote
8
+ -%>
9
+ <span class="first">
10
+ <%= link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, :remote => remote %>
11
+ </span>
@@ -0,0 +1,8 @@
1
+ <%# Non-link tag that stands for skipped pages...
2
+ - available local variables
3
+ current_page: a page object for the currently displayed page
4
+ num_pages: total number of pages
5
+ per_page: number of items to fetch per page
6
+ remote: data-remote
7
+ -%>
8
+ <span class="page gap"><%= raw(t 'views.pagination.truncate') %></span>
@@ -0,0 +1,11 @@
1
+ <%# Link to the "Last" page
2
+ - available local variables
3
+ url: url to the last page
4
+ current_page: a page object for the currently displayed page
5
+ num_pages: total number of pages
6
+ per_page: number of items to fetch per page
7
+ remote: data-remote
8
+ -%>
9
+ <span class="last">
10
+ <%= link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, {:remote => remote} %>
11
+ </span>
@@ -0,0 +1,11 @@
1
+ <%# Link to the "Next" page
2
+ - available local variables
3
+ url: url to the next page
4
+ current_page: a page object for the currently displayed page
5
+ num_pages: total number of pages
6
+ per_page: number of items to fetch per page
7
+ remote: data-remote
8
+ -%>
9
+ <span class="next">
10
+ <%= link_to_unless current_page.last?, raw(t 'views.pagination.next'), url, :rel => 'next', :remote => remote %>
11
+ </span>
@@ -0,0 +1,12 @@
1
+ <%# Link showing page number
2
+ - available local variables
3
+ page: a page object for "this" page
4
+ url: url to this page
5
+ current_page: a page object for the currently displayed page
6
+ num_pages: total number of pages
7
+ per_page: number of items to fetch per page
8
+ remote: data-remote
9
+ -%>
10
+ <span class="page<%= ' current' if page.current? %>">
11
+ <%= link_to_unless page.current?, page, url, opts = {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil} %>
12
+ </span>
@@ -0,0 +1,23 @@
1
+ <%# The container tag
2
+ - available local variables
3
+ current_page: a page object for the currently displayed page
4
+ num_pages: total number of pages
5
+ per_page: number of items to fetch per page
6
+ remote: data-remote
7
+ paginator: the paginator that renders the pagination tags inside
8
+ -%>
9
+ <%= paginator.render do -%>
10
+ <nav class="pagination">
11
+ <%= first_page_tag unless current_page.first? %>
12
+ <%= prev_page_tag unless current_page.first? %>
13
+ <% each_page do |page| -%>
14
+ <% if page.left_outer? || page.right_outer? || page.inside_window? -%>
15
+ <%= page_tag page %>
16
+ <% elsif !page.was_truncated? -%>
17
+ <%= gap_tag %>
18
+ <% end -%>
19
+ <% end -%>
20
+ <%= next_page_tag unless current_page.last? %>
21
+ <%= last_page_tag unless current_page.last? %>
22
+ </nav>
23
+ <% end -%>
@@ -0,0 +1,11 @@
1
+ <%# Link to the "Previous" page
2
+ - available local variables
3
+ url: url to the previous page
4
+ current_page: a page object for the currently displayed page
5
+ num_pages: total number of pages
6
+ per_page: number of items to fetch per page
7
+ remote: data-remote
8
+ -%>
9
+ <span class="prev">
10
+ <%= link_to_unless current_page.first?, raw(t 'views.pagination.previous'), url, :rel => 'prev', :remote => remote %>
11
+ </span>
@@ -4,7 +4,7 @@
4
4
  <!--[if IE 7 ]> <html class="no-js ie7" lang="en"> <![endif]-->
5
5
  <!--[if IE 8 ]> <html class="no-js ie8" lang="en"> <![endif]-->
6
6
  <!--[if (gte IE 9)|!(IE)]><!-->
7
- <html class="no-js" lang="en">
7
+ <html class="no-js" lang="en" style="height:100%">
8
8
  <!--<![endif]-->
9
9
  <head>
10
10
  <meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
@@ -38,8 +38,10 @@
38
38
  <%= yield %>
39
39
  </div>
40
40
  </div>
41
- <footer>
42
- </footer>
41
+ <div class="push"></div>
43
42
  </div>
43
+ <footer>
44
+ <div id="powered"><%= ::I18n.t("lolita.shared.powered", :year => Date.today.year)%></div>
45
+ </footer>
44
46
  </body>
45
47
  </html>
@@ -6,6 +6,8 @@ en:
6
6
  log_out: Log out
7
7
  edit: Edit
8
8
  delete: Delete
9
+ and: and
10
+ powered: Powered by Lolita (2010-%{year})
9
11
  nested_form:
10
12
  add: "Add %{resource_name}"
11
13
  tabs:
@@ -6,6 +6,8 @@ lv:
6
6
  log_out: Atteikties
7
7
  edit: Labot
8
8
  delete: Dzēst
9
+ and: un
10
+ powered: Darbojas ar Lolita (2010-%{year})
9
11
  nested_form:
10
12
  add: "Pievienot %{resource_name}"
11
13
  tabs:
@@ -20,4 +22,11 @@ lv:
20
22
  confirm: "Vai esat pārliecināts, ka vēlaties dzēst ierakstu?"
21
23
  filter:
22
24
  apply_button: Pielietot
23
- include_blank_by_title: " -- Filtrēt pēc %{title} -- "
25
+ include_blank_by_title: " -- Filtrēt pēc %{title} -- "
26
+ views:
27
+ pagination:
28
+ previous: "&laquo; Atpakaļ"
29
+ next: "Uz priekšu &raquo;"
30
+ last: "Beigas"
31
+ first: "Sākums"
32
+ truncate: "..."
@@ -47,6 +47,16 @@ module Lolita
47
47
  @association_values
48
48
  end
49
49
 
50
+ # used in views for shorter accessing to values
51
+ def view_values(view)
52
+ values = association_values
53
+ if values.respond_to?(:call)
54
+ values.call(view)
55
+ else
56
+ association_values
57
+ end
58
+ end
59
+
50
60
  private
51
61
 
52
62
  def set_association_type #TODO test
@@ -15,7 +15,7 @@ module Lolita
15
15
  key_method = dbi.adapter_name == :active_record ? :association_foreign_key : :key
16
16
  !dbi.associations.values.detect{|assoc| assoc.send(key_method) == name}
17
17
  elsif dbi.klass.respond_to?(:uploaders)
18
- dbi_klass.uploaders.keys.include?(name.to_sym)
18
+ dbi.klass.uploaders.keys.include?(name.to_sym)
19
19
  end
20
20
  end
21
21
  end
@@ -19,31 +19,56 @@ module Lolita
19
19
 
20
20
  attr_reader :parent, :options, :field_style
21
21
  attr_accessor :name, :expandable, :field_rejection_proc
22
+ attr_writer :build_method
22
23
 
23
24
  def initialize parent,name=nil, options ={}
24
25
  @parent=parent
25
26
  @options = options
26
27
  self.name=name || "nested_form_#{next_nested_form}"
28
+ set_attributes_from(options)
27
29
  end
28
30
 
31
+ def allow_destroy?
32
+ dbi.klass.nested_attributes_options[name][:allow_destroy]
33
+ end
34
+
35
+ def update_only?
36
+ dbi.klass.nested_attributes_options[name][:update_only]
37
+ end
38
+
39
+ def build_method
40
+ @build_method || self.name
41
+ end
42
+ # Set field style - normal or simple. Default - normal.
29
43
  def field_style=(value)
30
44
  allowed_values = [:normal,:simple]
31
45
  raise ArgumentError, "Only #{allowed_values.inspect} are allowed" unless allowed_values.include?(value)
32
46
  @field_style = value
33
47
  end
34
48
 
49
+ # Detect if it's possible to add more than one field group, like if model has many other objects.
35
50
  def expandable?
36
51
  @expandable == true || (@expandable == nil && macro == :many)
37
52
  end
38
53
 
54
+ # Create field, that is not real field, but represents nested attributes as one.
55
+ # It is used to create label.
56
+ def as_field
57
+ Lolita::Configuration::Field.add(dbi,self.name, :string)
58
+ end
59
+
60
+ # Parent (a.k.a tab) dbi
39
61
  def dbi
40
62
  @parent.dbi
41
63
  end
42
64
 
65
+ # Fields setter. Fields should be array and each element should be Lolita::Configuration::Field object.
43
66
  def fields=(new_fields)
44
67
  @fields = new_fields
45
68
  end
46
69
 
70
+ # Return all fields. Each time fields ar returned from @fields if its defined or calculated by using #field_rejection_proc
71
+ # or collected from parent (tab) where fields nested form is same with self.
47
72
  def fields
48
73
  if @fields
49
74
  @fields
@@ -54,10 +79,12 @@ module Lolita
54
79
  end
55
80
  end
56
81
 
82
+ # Parent (tab) dbi klass
57
83
  def klass
58
84
  dbi.reflect_on_association(name).klass
59
85
  end
60
86
 
87
+ # Parent (tab) dbi klass reflection with #name and macros of that.
61
88
  def macro
62
89
  dbi.association_macro(dbi.reflect_on_association(name))
63
90
  end
@@ -67,6 +94,12 @@ module Lolita
67
94
  def next_nested_form
68
95
  @@last_nested_form+=1
69
96
  end
97
+
98
+ def set_attributes_from(options)
99
+ options.each{|key,value|
100
+ instance_variable_set(:"@#{key}",value)
101
+ }
102
+ end
70
103
  end
71
104
  end
72
105
  end
data/lib/lolita/rails.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'lolita/rails/routes'
2
-
2
+ require 'haml'
3
3
 
4
4
  ActiveSupport.on_load(:action_controller) {
5
5
  include Lolita::Controllers::ViewUserHelpers
@@ -16,5 +16,9 @@ module Lolita
16
16
  class Engine < Rails::Engine
17
17
  config.lolita=Lolita
18
18
  config.i18n.load_path += Dir[File.join(Lolita.root,'config', 'locales','default', '*.{yml}')]
19
+ config.before_initialize do
20
+ Haml.init_rails(binding)
21
+ Haml::Template.options[:format] = :html5
22
+ end
19
23
  end
20
24
  end
@@ -0,0 +1,21 @@
1
+ module Lolita
2
+ module SystemConfiguration
3
+ class Application
4
+
5
+ attr_writer :name
6
+
7
+ def name
8
+ @name || default_name
9
+ end
10
+
11
+ def default_name
12
+ if defined?(Rails)
13
+ Rails::Application.subclasses.first.to_s.split("::").first
14
+ else
15
+ "Lolita"
16
+ end
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,161 @@
1
+ module Lolita
2
+ module SystemConfiguration
3
+ class Base
4
+ attr_reader :scope, :modules, :routes, :controllers,:resources
5
+ attr_accessor :mappings,:default_route,:user_classes,:authentication
6
+ attr_writer :default_locale
7
+
8
+ def initialize(scope)
9
+ @scope=scope
10
+ @mappings={}
11
+ @resources={}
12
+ @default_module=nil
13
+ @user_classes=[]
14
+ @modules=[]
15
+ @routes={}
16
+ @controllers={}
17
+ end
18
+
19
+ def application &block
20
+ @application ||= Lolita::SystemConfiguration::Application.new
21
+ if block_given?
22
+ yield @application
23
+ end
24
+ @application
25
+ end
26
+
27
+ def navigation
28
+ @navigation||=Lolita::Navigation::Base.new()
29
+ @navigation
30
+ end
31
+
32
+ def locales=(value)
33
+ unless value.is_a?(Array)
34
+ @locales=[value]
35
+ else
36
+ @locales=value
37
+ end
38
+ end
39
+
40
+ def locales
41
+ @locales || []
42
+ end
43
+
44
+ def locale()
45
+ @locale || default_locale
46
+ end
47
+
48
+ def locale=given_locale
49
+ @locale=if locales.include?(given_locale.to_s.to_sym)
50
+ given_locale.to_s.to_sym
51
+ else
52
+ Lolita.default_locale
53
+ end
54
+ end
55
+ # Return default locale. First looks for defined default locale for Lolita, when not found than
56
+ # take first of defined #locales for Lolita, if there no defined locales for Lolita, than
57
+ # look for I18n and take default locale from there or if there is no I18n than take :en
58
+ def default_locale
59
+ @default_locale || self.locales.first || (defined?(::I18n) ? ::I18n.default_locale : :en)
60
+ end
61
+ # Call (with #call) to route klass
62
+ # And return all names of routes that are needed for resource.
63
+ # When with #add_module routes are defined like
64
+ # Lolita.add_module MyModule, :route=>:my_module
65
+ # then this will be passed to the method that creates routes, but
66
+ # when Proc is passed to <i>:route</i> then this Proc should return
67
+ # name of route or nil.
68
+ # These names then are used for methods like <em>lolita_[route_name]_route</em>
69
+ # that should be required somewhere in you module.
70
+ def conditional_routes(klass=nil)
71
+ @routes.map{|name,route|
72
+ if route.first
73
+ if route.last.respond_to?(:call)
74
+ route.last.call(klass)
75
+ else
76
+ route.last
77
+ end
78
+ end
79
+ }.compact
80
+ end
81
+
82
+ # Find all routes that is needed for defined classes
83
+ # And return only one for each different route.
84
+ def common_routes(klasses)
85
+ @routes.map{|name,route|
86
+ unless route.first
87
+ klasses.map{|klass| route.last.respond_to?(:call) ? route.last.call(klass) : route.last}
88
+ end
89
+ }.flatten.compact.uniq
90
+ end
91
+
92
+ # Include module in Lolita, don't know why i need this
93
+ def use(module_name)
94
+ Lolita.send(:include,module_name)
95
+ end
96
+
97
+ def add_mapping(resource,options={})
98
+ mapping = Lolita::Mapping.new(resource, options)
99
+ self.mappings[mapping.name] = mapping
100
+ mapping
101
+ end
102
+
103
+ # Add new module to Lolita
104
+ # Accpted options
105
+ # * <tt>controller</tt> - not in use
106
+ # * <tt>nested</tt> - is route stands itsefl or is used in combination with resource
107
+ # * <tt>route</tt> - Symbol of route name or lambad, that return route name based on resource.
108
+ # Route name is used to call method lolita_[route_name] in Mapper class, and that should draw route.
109
+ # * <tt>:name</tt> - name of module, underscored symbol. Used to draw default route, by default always
110
+ # lolita_rest is called, but if route with resource name is found, than by default this route will be drawn.
111
+ # Like lolita_for :posts, can go to different controller than rest and do other things.
112
+ # * <tt>:path</tt> - some file that will be included. Deprecated will be removed
113
+ # ====Example
114
+ # Lolita.add_module Lolita::Posts, :route=>:post, :name=>:post
115
+ # lolita_for :posts #=> create url whatever is defined in lolita_post method, and goes to :controller=>"lolita/posts"
116
+ # Lolita.add_module Lolita::FileUpload, :route=>lambda{|resource| resource.lolita.tabs.by_type(:file) ? :file_upload : nil}
117
+ # lolita_for :users #=> creat default rest urls and also call method lolita_file_upload if user lolita define :file tab.
118
+ # To add route for public interface that goes to added module, than use
119
+ # Lolita.add_module Post, :name=>:posts
120
+ # And then when in routes.rb will be defined lolita_for(:posts) it will call method <i>lolita_posts_route</i>
121
+ # and that method should define resource.
122
+ # ====Example
123
+ # # require this in your gem or lib
124
+ # module ActionDispatch::Routing
125
+ # class Mapper
126
+ # protected
127
+ # def lolita_posts_route mapping, controllers
128
+ # resources mapping.plural,:only=>[:index,:new,:create],
129
+ # :controller=>controllers[:posts],:module=>mapping.module
130
+ # end
131
+ # end
132
+ # end
133
+ # You open Mapper class and add your method that call #resources or #match or other method that define route
134
+ # For common route for all lolita resources your method should look like this
135
+ # ====Example
136
+ # def lolita_files_route
137
+ # mapping=Lolita.add_mapping(:files,:class_name=>"Lolita::Multimedia::File",:module=>"file_upload")
138
+ # scope :module=>mapping.module do
139
+ # resources mapping.name
140
+ # end
141
+ # end
142
+ def add_module module_container, options={}
143
+ raise ArgumentError, "Can't add module without module container!" unless module_container
144
+ options.assert_valid_keys(:controller,:route,:model,:path,:name,:nested)
145
+ name=options[:name]||module_container.to_s.to_sym
146
+ self.modules<<module_container
147
+
148
+ if options.has_key?(:route)
149
+ self.routes[name]=[options.has_key?(:nested) ? options[:nested] : true,options[:route]]
150
+ end
151
+ self.controllers[name]=options[:controller] if options.has_key?(:controller)
152
+
153
+ if options[:path]
154
+ require File.join(options[:path],name.to_s)
155
+ end
156
+
157
+ end
158
+
159
+ end
160
+ end
161
+ end
data/lib/lolita.rb CHANGED
@@ -42,7 +42,11 @@ module Lolita
42
42
  module Builder
43
43
  autoload(:Custom, 'lolita/builder')
44
44
  end
45
- autoload(:BaseConfiguration,'lolita/base_configuration')
45
+
46
+ module SystemConfiguration
47
+ autoload :Base, 'lolita/system_configuration/base'
48
+ autoload :Application, 'lolita/system_configuration/application'
49
+ end
46
50
 
47
51
  module Adapter
48
52
  autoload :AbstractAdapter, 'lolita/adapter/abstract_adapter'
@@ -146,7 +150,7 @@ module Lolita
146
150
 
147
151
  def self.scope name=nil
148
152
  name||=scope_name
149
- @@scopes[name]||=Lolita::BaseConfiguration.new(name)
153
+ @@scopes[name]||=Lolita::SystemConfiguration::Base.new(name)
150
154
  @@scopes[name]
151
155
  end
152
156