lolita 3.1.3 → 3.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/History.rdoc +13 -1
  2. data/VERSION +1 -1
  3. data/app/views/components/lolita/configuration/column/_display.html.erb +4 -0
  4. data/app/views/components/lolita/configuration/column/_header.html.erb +7 -0
  5. data/app/views/components/lolita/configuration/column/_sort.html.erb +4 -0
  6. data/app/views/components/lolita/configuration/columns/_body.html.erb +5 -0
  7. data/app/views/components/lolita/configuration/columns/_display.html.erb +2 -0
  8. data/app/views/components/lolita/configuration/{list/_checkbox_cell.html.erb → columns/_first.html.erb} +0 -0
  9. data/app/views/components/lolita/configuration/{list/_checkbox_header.html.erb → columns/_first_column_header.html.erb} +0 -0
  10. data/app/views/components/lolita/configuration/columns/_header.html.erb +9 -0
  11. data/app/views/components/lolita/configuration/{list/_tool_cell.html.erb → columns/_last.html.erb} +0 -0
  12. data/app/views/components/lolita/configuration/{list/_tool_header.html.erb → columns/_last_column_header.html.erb} +0 -0
  13. data/app/views/components/lolita/configuration/columns/_row.html.erb +7 -0
  14. data/app/views/components/lolita/configuration/list/_display.html.erb +5 -6
  15. data/app/views/components/lolita/configuration/list/_paginator.html.erb +5 -3
  16. data/app/views/components/lolita/navigation/_tree.html.erb +4 -3
  17. data/lib/generators/lolita/assets_generator.rb +7 -0
  18. data/lib/generators/lolita/install_generator.rb +1 -1
  19. data/lib/lolita.rb +7 -0
  20. data/lib/lolita/base_configuration.rb +1 -0
  21. data/lib/lolita/configuration/column.rb +27 -48
  22. data/lib/lolita/configuration/columns.rb +1 -0
  23. data/lib/lolita/configuration/filter.rb +23 -1
  24. data/lib/lolita/configuration/page.rb +10 -0
  25. data/lib/lolita/controllers/component_helpers.rb +14 -6
  26. data/lib/lolita/controllers/url_helpers.rb +35 -2
  27. data/lib/lolita/mapping.rb +7 -3
  28. data/lib/lolita/navigation/branch.rb +5 -1
  29. data/lib/lolita/navigation/tree.rb +5 -1
  30. data/lib/lolita/observed_array.rb +2 -2
  31. data/lib/lolita/rails/routes.rb +10 -8
  32. data/lib/lolita/support/formatter/base.rb +64 -0
  33. data/lib/lolita/support/formatter/rails.rb +57 -0
  34. data/lolita.gemspec +21 -13
  35. data/public/stylesheets/lolita/style.css +15 -0
  36. data/spec/configuration/column_spec.rb +13 -1
  37. data/spec/configuration/filter_spec.rb +1 -0
  38. data/spec/controllers/component_helpers_spec.rb +6 -0
  39. data/spec/controllers/lolita_rest_spec.rb +1 -0
  40. data/spec/spec_helper.rb +1 -1
  41. data/spec/support/formatter/base_spec.rb +42 -0
  42. metadata +20 -12
  43. data/app/views/components/lolita/configuration/list/_body.html.erb +0 -5
  44. data/app/views/components/lolita/configuration/list/_body_cell.html.erb +0 -3
  45. data/app/views/components/lolita/configuration/list/_header.html.erb +0 -9
  46. data/app/views/components/lolita/configuration/list/_header_cell.html.erb +0 -5
  47. data/app/views/components/lolita/configuration/list/_row.html.erb +0 -7
data/History.rdoc CHANGED
@@ -1,4 +1,16 @@
1
- === Version 3.1.3 /
1
+ === Version 3.1.4 / 2011-04-19
2
+ * Enhancements
3
+ * #render_component improved, to support any class with build method as first argument (Arturs Meister)
4
+ * list components refactore; columns and column components created (Arturs Meisters)
5
+ * documentation for Filters (Gatis Tomsons)
6
+ * sorting configuration for columns (Arturs Meisters)
7
+ * lolita:assets generator invoke :assets for all added modules
8
+
9
+ * Bug fixes
10
+ * paginator updated, to use WillPaginate only when it is accessable (Arturs Meisters)
11
+ * resource cheching for tree (Arturs Meisters)
12
+
13
+ === Version 3.1.3 / 2011-04-15
2
14
  * Enhancements
3
15
  * Lolita::Navigation::Tree and Lolita::Navigation::Branch added (Arturs Meisters)
4
16
  * Main navigation tree generate from resources (Arturs Meisters)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.3
1
+ 3.1.4
@@ -0,0 +1,4 @@
1
+ <td>
2
+ <% value=column.formatter.with(record.send(column.name.to_sym),record) %>
3
+ <%= value.to_s %>
4
+ </td>
@@ -0,0 +1,7 @@
1
+ <th <%=column.currently_sorting?(params) ? "class='active'" : ""%> >
2
+ <% if column.sortable? %>
3
+ <%= render_component column, :sort %>
4
+ <% else %>
5
+ <%= column.title %>
6
+ <% end %>
7
+ </th>
@@ -0,0 +1,4 @@
1
+ <% param_options=params.reject{|k,v| [:controller,:action].include?(k)} %>
2
+ <% options=param_options.merge(column.sort_options(params)) %>
3
+ <% direction_indicator=column.currently_sorting?(params) && options[:sd].to_s=="desc" ? raw('&uArr;') : raw('&dArr;') %>
4
+ <%= link_to raw("#{column.title} #{direction_indicator}"), lolita_resources_path(options) %>
@@ -0,0 +1,5 @@
1
+ <tbody>
2
+ <% page.each_with_index do |record,index| %>
3
+ <%= render_component columns, :row, :record=>record,:index=>index%>
4
+ <% end %>
5
+ </tbody>
@@ -0,0 +1,2 @@
1
+ <%= render_component columns,:header %>
2
+ <%= render_component columns,:body,:page=>page %>
@@ -0,0 +1,9 @@
1
+ <thead>
2
+ <tr>
3
+ <%= render_component columns,:first_column_header %>
4
+ <% columns.each do |column| %>
5
+ <%= render_component column,:header %>
6
+ <% end %>
7
+ <%= render_component columns,:last_column_header %>
8
+ </tr>
9
+ </thead>
@@ -0,0 +1,7 @@
1
+ <tr class="<%= index%2==0 ? "even" : "odd" %>">
2
+ <%= render_component columns,:first,:record=>record %>
3
+ <% columns.each do |column| %>
4
+ <%= render_component column, :record=>record %>
5
+ <% end %>
6
+ <%= render_component columns,:last,:record=>record %>
7
+ </tr>
@@ -1,12 +1,11 @@
1
1
  <div class="box">
2
- <%= render_component :"lolita/configuration/list", :title %>
3
- <%= render_component :"lolita/configuration/list", :new_resource%>
4
- <%= render_component :"lolita/configuration/list", :filter, :list => list %>
2
+ <%= render_component list, :title %>
3
+ <%= render_component list, :new_resource%>
4
+ <%= render_component list, :filter %>
5
5
  <div class="list">
6
6
  <table>
7
- <%= render_component :"lolita/configuration/list", :header, :columns=>list.columns %>
8
- <%= render_component :"lolita/configuration/list", :body, :page=>page,:columns=>list.columns %>
7
+ <%= render_component list.columns,:page=>page %>
9
8
  </table>
10
9
  </div>
11
- <%= render_component :"lolita/configuration/list", :paginator,:page=>page, :columns=>list.columns %>
10
+ <%= render_component list,:paginator,:page=>page %>
12
11
  </div>
@@ -1,3 +1,5 @@
1
- <div class="paginator">
2
- <%= will_paginate page %>
3
- </div>
1
+ <% if page.is_a?(WillPaginate::Collection) %>
2
+ <div class="paginator">
3
+ <%= will_paginate page %>
4
+ </div>
5
+ <% end %>
@@ -1,4 +1,5 @@
1
- <ul>
1
+ <ul <%=tree.parent ? "class='subtree'" : ""%> >
2
+ <% last_branch=tree.branches.last %>
2
3
  <%tree.branches.each do |branch|
3
4
  if branch.object.is_a?(Lolita::Mapping)
4
5
  branch.options[:url]||=lolita_resources_path(branch.object)
@@ -6,7 +7,7 @@
6
7
  else
7
8
 
8
9
  branch.options[:url]=if branch.options[:url].respond_to?(:call)
9
- self.instance_eval(&(branch.options[:url]))
10
+ branch.options[:url].call(self,branch)
10
11
  else
11
12
  branch.options[:url]
12
13
  end
@@ -14,7 +15,7 @@
14
15
  end
15
16
 
16
17
  %>
17
- <li <%=active ? "class='active'" : ""%>>
18
+ <li class="<%=active ? "active" : ""%> <%=branch.children.branches.any? ? "with-subtree" : ""%> <%=branch==last_branch ? "last-in-subtree" : ""%>">
18
19
  <%= link_to branch.title, branch.options[:url] %>
19
20
  <% if branch.children.branches.any? %>
20
21
  <%= render_component(:"lolita/navigation",:tree,:tree=>branch.children) %>
@@ -7,6 +7,13 @@ module Lolita
7
7
  def copy_all
8
8
  copy_dir("public")
9
9
  end
10
+
11
+ def call_modules
12
+ Lolita.modules.each do |module_name|
13
+ command="#{module_name.to_s.underscore.gsub("/","_")}:assets"
14
+ invoke command rescue nil
15
+ end
16
+ end
10
17
  end
11
18
  end
12
19
  end
@@ -19,7 +19,7 @@ module Lolita
19
19
  def install_modules
20
20
  Lolita.modules.each do |module_name|
21
21
 
22
- invoke "#{module_name.to_s.underscore.gsub("/","_")}:install"
22
+ invoke "#{module_name.to_s.underscore.gsub("/","_")}:install" rescue nil
23
23
  end
24
24
  end
25
25
 
data/lib/lolita.rb CHANGED
@@ -124,6 +124,13 @@ module Lolita
124
124
  autoload :Branch, "lolita/navigation/branch"
125
125
  end
126
126
 
127
+ module Support
128
+ module Formatter
129
+ autoload :Base, 'lolita/support/formatter/base'
130
+ autoload :Rails, 'lolita/support/formatter/rails'
131
+ end
132
+ end
133
+
127
134
  @@scopes={}
128
135
 
129
136
  def self.scope name=nil
@@ -134,6 +134,7 @@ module Lolita
134
134
  # end
135
135
  # end
136
136
  def add_module module_container, options={}
137
+ raise ArgumentError, "Can't add module without module container!" unless module_container
137
138
  options.assert_valid_keys(:controller,:route,:model,:path,:name,:nested)
138
139
  name=options[:name]||module_container.to_s.to_sym
139
140
  self.modules<<module_container
@@ -2,8 +2,10 @@ module Lolita
2
2
  module Configuration
3
3
  class Column
4
4
 
5
+ include Lolita::Builder
6
+
5
7
  MAX_TEXT_SIZE=20
6
- lolita_accessor :name,:title,:type,:options,:format
8
+ lolita_accessor :name,:title,:type,:options,:sortable
7
9
 
8
10
  def initialize(*args,&block)
9
11
  self.set_attributes(*args)
@@ -11,49 +13,32 @@ module Lolita
11
13
  validate
12
14
  set_default_values
13
15
  end
14
-
15
- #
16
- # column do
17
- # name "UID"
18
- # format do(values)
19
- # values.first+values.last
20
- # end
21
- # end
22
- # <%= column.with_format([@post.id,@post.user_id])%>
23
- def with_format(value) #TODO test
24
- if @format.respond_to?(:call)
25
- @format.call(value)
26
- elsif @format && (value.is_a?(Time) || value.is_a?(Date))
27
- format_for_datetime(value)
28
- else
29
- format_from_type(value)
30
- end
16
+
17
+ def sortable?
18
+ @sortable
31
19
  end
32
20
 
33
- def format_from_type(value) #TODO test
34
- if value
35
- if value.is_a?(String)
36
- value
37
- elsif value.is_a?(Integer)
38
- value
39
- elsif value.is_a?(Date)
40
- if defined?(I18n)
41
- I18n.localize(value, :format => :long)
42
- else
43
- value.to_s
44
- end
45
- elsif value.is_a?(Time)
46
- if defined?(I18n)
47
- I18n.localize(value, :format => :long)
48
- else
49
- value.to_s
50
- end
51
- else
52
- value.to_s
53
- end
21
+ def currently_sorting?(params)
22
+ @sortable && params[:sc].to_s==self.name.to_s
23
+ end
24
+
25
+ def sort_options(params)
26
+ direction=if params[:sc].to_s==self.name.to_s
27
+ params[:sd].to_s=="asc" ? "desc" : "asc"
54
28
  else
55
- ""
29
+ "desc"
30
+ end
31
+ {:sc=>self.name,:sd=>direction}
32
+ end
33
+
34
+ # Define format, for details see Lolita::Support::Formatter::Base and Lolita::Support::Formater::Rails
35
+ def formatter(value=nil,&block)
36
+ if block_given?
37
+ @formatter=Lolita::Support::Formatter::Base.new(value,&block)
38
+ elsif value || !@formatter
39
+ @formatter=Lolita::Support::Formatter::Rails.new(value)
56
40
  end
41
+ @formatter
57
42
  end
58
43
 
59
44
  def set_attributes(*args)
@@ -73,16 +58,10 @@ module Lolita
73
58
  private
74
59
 
75
60
  def set_default_values
61
+ @sortable||=true
62
+ @sort_direction||=:desc
76
63
  @title||=@name.to_s.humanize
77
64
  end
78
-
79
- def format_for_datetime value
80
- if defined?(I18n)
81
- I18n.localize(value, :format => @format)
82
- else
83
- value.to_s
84
- end
85
- end
86
65
 
87
66
  def validate
88
67
  raise ArgumentError.new("Column must have name.") unless self.name
@@ -4,6 +4,7 @@ module Lolita
4
4
 
5
5
  include Enumerable
6
6
  include ObservedArray
7
+ include Lolita::Builder
7
8
 
8
9
  attr_accessor :list
9
10
  attr_reader :dbi
@@ -1,6 +1,29 @@
1
1
  # coding: utf-8
2
2
  module Lolita
3
3
  module Configuration
4
+ # Lolita::Configuration::Filter is for filtering data in list view.
5
+ # By now it supports these field types:
6
+ # - Array
7
+ # - Boolean
8
+ #
9
+ # To use it, call "filter" method in list block, filter method accepts field names
10
+ # as arguments. You can pass block and configure each field. Field configuration is just like in tab configuration.
11
+ #
12
+ # === Examples
13
+ #
14
+ # # this will build country select field and is_deleted checkbox
15
+ # list do
16
+ # filter :country, :is_deleted
17
+ # end
18
+ #
19
+ # # For example you have text field "status" with values opened,closed,rejected
20
+ # list do
21
+ # filter do
22
+ # field :status, :array, :options_for_select => %w(open closed rejected)
23
+ # field :is_deleted, :title => "Deleted"
24
+ # end
25
+ # end
26
+ #
4
27
  class Filter
5
28
  include Lolita::Builder
6
29
  attr_reader :dbi
@@ -61,7 +84,6 @@ module Lolita
61
84
  end
62
85
 
63
86
  def field_name field
64
- #'f_'+('a'..'z').to_a[self.fields.index(field)]
65
87
  "f_#{field.name}"
66
88
  end
67
89
 
@@ -109,7 +109,17 @@ module Lolita
109
109
  self.send(meth,options.delete(meth))
110
110
  end
111
111
  }
112
+ parse_params
112
113
  end
114
+
115
+ def parse_params
116
+ if @params
117
+ if @params.has_key?(:sc)
118
+ self.send((@params[:sd] || :asc).to_sym,@params[:sc])
119
+ end
120
+ end
121
+ end
122
+
113
123
  end
114
124
  end
115
125
  end
@@ -26,19 +26,27 @@ module Lolita
26
26
  # render_component "lolita/list", :display
27
27
  # render_component "lolita/list/display"
28
28
  def render_component *args
29
- @opts=args.extract_options!
30
- name=args[0]
31
- state=args[1]
32
- format=@opts.delete(:format)
33
-
29
+ name,state,options=get_render_options(*args)
30
+ format=options.delete(:format)
31
+
34
32
  raise "Can't render component without name!" unless name
35
33
  will_use_component name
36
34
  component_name=File.join(name.to_s,state ? state.to_s : nil)
37
35
  partial_name=File.join("/components",component_name)
38
- output=output_component(partial_name,component_name,:format=>format,:locals=>@opts)
36
+ output=output_component(partial_name,component_name,:format=>format,:locals=>options)
39
37
  self.respond_to?(:raw) ? raw(output) : output
40
38
  end
41
39
 
40
+ def get_render_options *args
41
+ options=args.extract_options!
42
+ if args.first.respond_to?(:build)
43
+ name,state,options=args[0].build("",args[1],options)
44
+ else
45
+ name,state=args
46
+ end
47
+ return name,state,options
48
+ end
49
+
42
50
  def output_component(partial_name,name,options={})
43
51
  output=""
44
52
  if options[:format]
@@ -1,5 +1,21 @@
1
1
  module Lolita
2
2
  module Controllers
3
+ # This module is included in all controllers and views. UrlHelper provide methods to generate lolita
4
+ # resource paths. As all resources goes to one controller (by default), than it is very difficult to
5
+ # generate url with <em>:controller</em> and <em>:action</em>.
6
+ # There are four methods for path:
7
+ # * lolita_resources_path - goes to index action
8
+ # * lolita_resource_path - goes to create, destroy or show, it depends what kind of method is used
9
+ # * new_lolita_resource_path - goes to new action
10
+ # * edit_lolita_resource_path - goes to edit action
11
+ # All of those methods accept <em>mapping</em> as a first argument and optional <em>options</em> that
12
+ # will be passed to path gererator. It is possible to pass only options, than current mapping will be used.
13
+ # ====Example
14
+ # # lets say, that current mapping is for posts
15
+ # edit_lolita_resource_path(:id=>4) #=> /lolita/posts/4/edit
16
+ # edit_lolita_resource_path(comment_mapping,:id=>1,:parent_id=>2) #=> /lolita/comments/1/edit?parent_id=2
17
+ # For custom actions there are method #lolita_resource_name that make it easier to generate custom method.
18
+ # All other methods use that for real resource path method generation.
3
19
  module UrlHelpers
4
20
 
5
21
  def self.included(model_klass)
@@ -40,32 +56,49 @@ module Lolita
40
56
 
41
57
  protected
42
58
 
59
+ # Path for index.
43
60
  def lolita_resources_path(*args)
44
61
  options=args.extract_options!
45
62
  mapping=args[0]
46
63
  send(lolita_resource_name(:mapping=>mapping,:plural=>true),options)
47
64
  end
48
65
 
49
- def lolita_resource_path(*args) # TODO test
66
+ # Path for show, create and destroy
67
+ def lolita_resource_path(*args)
50
68
  options=args.extract_options!
51
69
  mapping=args[0]
52
70
  send(lolita_resource_name(:mapping=>mapping),options)
53
71
  end
54
72
 
73
+ # Path for new.
55
74
  def new_lolita_resource_path(*args)
56
75
  options=args.extract_options!
57
76
  mapping=args[0]
58
77
  send(lolita_resource_name(:mapping=>mapping,:action=>:new),options)
59
78
  end
60
79
 
80
+ # Path for edit.
61
81
  def edit_lolita_resource_path(*args)
62
82
  options=args.extract_options!
63
83
  options[:id]||=resource.id if resource
64
- raise "Can edit resource without id." unless options[:id]
84
+ #raise "Can edit resource without id." unless options[:id]
65
85
  mapping=args[0]
66
86
  send(lolita_resource_name(:mapping=>mapping,:action=>:edit),options)
67
87
  end
68
88
 
89
+ # It return symbol, that represents named route method for path, like <i>lolita_posts_path</i> and so on.
90
+ # It accepts those options:
91
+ # * <tt>:mapping</tt> - Lolita::Mapping object, that is used to detect name of named route.
92
+ # by default it uses Lolita::InternalHelpers#lolita_mapping.
93
+ # * <tt>:plural</tt> - What kind of named route should use, plural or singular.
94
+ # * <tt>:action</tt> - Action is used to put before named route like <i>:edit</i>.
95
+ # ====Example
96
+ # # current mapping is for posts
97
+ # lolita_resource_name(:action=>:edit) #=> :edit_lolita_post_path
98
+ # lolita_resource_name(:plural=>true,:action=>:list) #=> :list_lolita_posts_path
99
+ # # for different mapping
100
+ # lolita_resource_name(:mapping=>comments_mapping) #=> :lolita_comment_path
101
+ # This methods is very useful to create your own paths in views.
69
102
  def lolita_resource_name(options={}) #TODO test if path is right
70
103
  options.assert_valid_keys(:mapping,:plural,:action)
71
104
  mapping=(options[:mapping]||lolita_mapping)
@@ -11,14 +11,18 @@ module Lolita
11
11
  # # add paths like this to routes
12
12
  # # admin_posts GET /admin/posts {:controller=>"lolita/rest", :action=>:index}
13
13
  # # edit_admin_posts GET /admin/post/1/edit {:controller=>"lolita/rest",:action=>:edit}
14
- # * <tt>:module</tt> - change module for path, it changes :controller that is used for lolita, like,
15
- # :module=>"admin", change controller to "admin/posts". If this is used without :path then no named routes will be generated
14
+ # * <tt>:module</tt> - change module for path, it changes <i>:controller</i> that is used for lolita, like,
15
+ # <code>:module=>"admin"</code>, change controller to "admin/posts". If this is used without :path then no named routes will be generated
16
+ # Instances of this class is used all over the Lolita, this class itself represent what name does resource has,
17
+ # what controller to use, what model is related with it and so on. This is used to generate urls and paths.
18
+ # Also eahc request containers information with mapping related to it.
16
19
  class Mapping
17
20
  attr_reader :class_name,:path,:singular,:plural,:path_prefix,:module,:controllers,:as
18
21
  alias :name :singular
19
22
 
20
- # TODO how it is when lolita plugin extend default path and there is module is this not break the logic?
23
+
21
24
  def initialize(name,options={})
25
+ # TODO how it is when lolita plugin extend default path and there is module is this not break the logic?
22
26
  @as=options[:as]
23
27
  @plural=(options[:as] ? options[:as] : name).to_sym
24
28
  @singular=(options[:singular] || @plural.to_s.singularize).to_sym
@@ -19,7 +19,11 @@ module Lolita
19
19
  end
20
20
 
21
21
  def children
22
- @children||=Lolita::Navigation::Tree.new("#{name}_children_tree")
22
+ unless @children
23
+ tree=Lolita::Navigation::Tree.new("#{name}_children_tree")
24
+ tree.set_parent(self)
25
+ @children=tree
26
+ end
23
27
  @children
24
28
  end
25
29
 
@@ -18,7 +18,7 @@ module Lolita
18
18
 
19
19
  add_hooks :before_branch_added, :after_branch_added
20
20
 
21
- attr_reader :name,:root,:default_position,:branches
21
+ attr_reader :name,:root,:default_position,:branches,:parent
22
22
 
23
23
  def initialize(name)
24
24
  @name=name
@@ -77,6 +77,10 @@ module Lolita
77
77
  raise ArgumentError, "Branch #{given_branch.inspect} not exists in #{self.inspect}"
78
78
  end
79
79
 
80
+ def set_parent(new_parent)
81
+ @parent=new_parent
82
+ end
83
+
80
84
  private
81
85
 
82
86
  def adding_branch *branch
@@ -1,4 +1,5 @@
1
- # This module overwrite Array methods that change Array to change element that is added to Array.
1
+ module Lolita
2
+ # This module overwrite Array methods that change Array to change element that is added to Array.
2
3
  # Class that include this module must have collection_variable method that return collection
3
4
  # variable that hold all records.
4
5
  # Also build_element method must have with element and &block as arguments
@@ -29,7 +30,6 @@
29
30
  # ...
30
31
  # end
31
32
  # end
32
- module Lolita
33
33
  module ObservedArray
34
34
 
35
35
  def method_missing(method,*args,&block)
@@ -33,7 +33,7 @@ module ActionDispatch::Routing
33
33
  # lolita_for :galleries
34
34
  # # lolita_for try to call :lolita_gallery in Mapper class
35
35
  def lolita_for *resources
36
- #TODO refactor
36
+
37
37
  return if migrating?
38
38
  options = resources.extract_options!
39
39
 
@@ -56,22 +56,19 @@ module ActionDispatch::Routing
56
56
  mapping=Lolita.add_mapping(resource,options)
57
57
  Lolita.resources[mapping.name]=mapping
58
58
  target_class=mapping.to
59
- Lolita::Navigation::Tree[:"left_side_navigation"].append(mapping,:title=>mapping.name.to_s.humanize)
59
+ #TODO refactor all these variables
60
60
  all_resource_classes<<target_class
61
61
 
62
62
  lolita_scope mapping.name do
63
63
  yield if block_given?
64
64
 
65
65
  with_lolita_exclusive_scope mapping.fullpath,mapping.path do
66
+
66
67
  # if not defined lolita default configuration in model, than can't use :rest
67
68
  if !target_class.respond_to?(:lolita) && !Lolita::routes[mapping.name]
68
- warn("Lolita not found in #{target_class}. Including Lolita::Configuration")
69
- target_class.send(:include, Lolita::Configuration)
70
- #raise Lolita::NotFound, "Lolita not found in #{target_class}. Include Lolita::Configuration"
69
+ raise Lolita::NotFound, "Lolita not found in #{target_class}. Include Lolita::Configuration"
71
70
  elsif target_class.respond_to?(:lolita) && target_class.instance_variable_get(:@lolita).nil?
72
- warn "Calling #lolita on #{target_class}, because lolita not initialized yet."
73
- target_class.lolita
74
- #raise Lolita::NotInitialized, "Call lolita method in #{target_class}."
71
+ raise Lolita::NotInitialized, "Call lolita method in #{target_class}."
75
72
  else
76
73
  route=Lolita.routes[mapping.name] || Lolita.default_route
77
74
  end
@@ -86,6 +83,11 @@ module ActionDispatch::Routing
86
83
  end
87
84
 
88
85
  end
86
+
87
+ tree=Lolita::Navigation::Tree[:"left_side_navigation"]
88
+ unless tree.branches.detect{|b| b.object.is_a?(Lolita::Mapping) && b.object.to==mapping.to}
89
+ tree.append(mapping,:title=>mapping.name.to_s.humanize)
90
+ end
89
91
  }
90
92
  Lolita.common_routes(all_resource_classes).each do |route_name|
91
93
  send(:"lolita_#{route_name}_route")
@@ -0,0 +1,64 @@
1
+ module Lolita
2
+ module Support
3
+ # Containes different kind of formaters.
4
+ module Formatter
5
+ # Change output format of different input types.
6
+ # To define, pass block, or String.
7
+ # ====Exmaple
8
+ # Lolita::Support::Formatter.new do |value|
9
+ # value.to_i**2
10
+ # end
11
+ # # or as String
12
+ # Lolita::Support::Formatter.new("%Y-%m")
13
+ # To format any value with defined formater call #with
14
+ # ====Example
15
+ # # Previous examples may be called like this
16
+ # formatter.with(1)
17
+ # formatter.with(Date.today)
18
+ class Base
19
+ def initialize(format=nil,&block)
20
+ @format=format
21
+ @block=block if block_given?
22
+ end
23
+
24
+ def format
25
+ @format
26
+ end
27
+
28
+ def block
29
+ @block
30
+ end
31
+
32
+ def with(value,*optional_values)
33
+ if @block
34
+ @block.call(value,*optional_values)
35
+ elsif @format
36
+ use_format_for(value,*optional_values)
37
+ else
38
+ use_default_format(value,*optional_values)
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def use_default_format(value,*optional_values)
45
+ value
46
+ end
47
+
48
+ def use_format_for(value, *optional_values)
49
+ if value.respond_to?(:format)
50
+ call_block(value,*optional_values)
51
+ else
52
+ value.to_s.unpack(@format)
53
+ end
54
+ end
55
+
56
+ def call_block(value,*optional_values)
57
+ value.send(:format,value,*optional_values)
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,57 @@
1
+ module Lolita
2
+ module Support
3
+ module Formatter
4
+
5
+ # Formater for work with rails, it localize Date and Time.
6
+ # Also
7
+ class Rails < Lolita::Support::Formatter::Base
8
+
9
+
10
+ private
11
+
12
+ def use_format_for(value,*optional_values)
13
+ if @format && (value.is_a?(Time) || value.is_a?(Date))
14
+ localize_time_with_format(value,*optional_values)
15
+ else
16
+ use_default_format(value,*optional_values)
17
+ end
18
+ end
19
+
20
+ def localize_time_with_format(value,*optional_values)
21
+ if defined?(I18n)
22
+ I18n.localize(value, :format => @format)
23
+ else
24
+ use_default_format(value,*optional_values)
25
+ end
26
+ end
27
+
28
+ def use_default_format(value,*optional_values)
29
+ if value
30
+ if value.is_a?(String)
31
+ value
32
+ elsif value.is_a?(Numeric)
33
+ value
34
+ elsif value.is_a?(Date)
35
+ if defined?(I18n)
36
+ I18n.localize(value, :format => :long)
37
+ else
38
+ value.strftime("%Y/%m%/%d")
39
+ end
40
+ elsif value.is_a?(Time)
41
+ if defined?(I18n)
42
+ I18n.localize(value, :format => :long)
43
+ else
44
+ value.strftime("%Y/%m/%d %H:%M:%S")
45
+ end
46
+ else
47
+ value.to_s
48
+ end
49
+ else
50
+ ""
51
+ end
52
+ end
53
+ end
54
+
55
+ end
56
+ end
57
+ end
data/lolita.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{lolita}
8
- s.version = "3.1.3"
8
+ s.version = "3.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["ITHouse (Latvia) and Arturs Meisters"]
12
- s.date = %q{2011-04-15}
12
+ s.date = %q{2011-04-19}
13
13
  s.description = %q{Great Rails CMS, that turns your business logic into good-looking, fully functional workspace. }
14
14
  s.email = %q{support@ithouse.lv}
15
15
  s.extra_rdoc_files = [
@@ -30,6 +30,17 @@ Gem::Specification.new do |s|
30
30
  "app/controllers/lolita/rest_controller.rb",
31
31
  "app/helpers/components/lolita/configuration/list_component.rb",
32
32
  "app/helpers/lolita_helper.rb",
33
+ "app/views/components/lolita/configuration/column/_display.html.erb",
34
+ "app/views/components/lolita/configuration/column/_header.html.erb",
35
+ "app/views/components/lolita/configuration/column/_sort.html.erb",
36
+ "app/views/components/lolita/configuration/columns/_body.html.erb",
37
+ "app/views/components/lolita/configuration/columns/_display.html.erb",
38
+ "app/views/components/lolita/configuration/columns/_first.html.erb",
39
+ "app/views/components/lolita/configuration/columns/_first_column_header.html.erb",
40
+ "app/views/components/lolita/configuration/columns/_header.html.erb",
41
+ "app/views/components/lolita/configuration/columns/_last.html.erb",
42
+ "app/views/components/lolita/configuration/columns/_last_column_header.html.erb",
43
+ "app/views/components/lolita/configuration/columns/_row.html.erb",
33
44
  "app/views/components/lolita/configuration/field/_display.html.erb",
34
45
  "app/views/components/lolita/configuration/field/_label.html.erb",
35
46
  "app/views/components/lolita/configuration/field/_object.html.erb",
@@ -52,20 +63,11 @@ Gem::Specification.new do |s|
52
63
  "app/views/components/lolita/configuration/field/string/text/_display.html.erb",
53
64
  "app/views/components/lolita/configuration/field/time/_display.html.erb",
54
65
  "app/views/components/lolita/configuration/field_set/_display.html.erb",
55
- "app/views/components/lolita/configuration/list/_body.html.erb",
56
- "app/views/components/lolita/configuration/list/_body_cell.html.erb",
57
- "app/views/components/lolita/configuration/list/_checkbox_cell.html.erb",
58
- "app/views/components/lolita/configuration/list/_checkbox_header.html.erb",
59
66
  "app/views/components/lolita/configuration/list/_display.html.erb",
60
67
  "app/views/components/lolita/configuration/list/_filter.html.erb",
61
- "app/views/components/lolita/configuration/list/_header.html.erb",
62
- "app/views/components/lolita/configuration/list/_header_cell.html.erb",
63
68
  "app/views/components/lolita/configuration/list/_new_resource.html.erb",
64
69
  "app/views/components/lolita/configuration/list/_paginator.html.erb",
65
- "app/views/components/lolita/configuration/list/_row.html.erb",
66
70
  "app/views/components/lolita/configuration/list/_title.html.erb",
67
- "app/views/components/lolita/configuration/list/_tool_cell.html.erb",
68
- "app/views/components/lolita/configuration/list/_tool_header.html.erb",
69
71
  "app/views/components/lolita/configuration/tab/_display.html.erb",
70
72
  "app/views/components/lolita/configuration/tab/_fields.html.erb",
71
73
  "app/views/components/lolita/configuration/tab/content/_display.html.erb",
@@ -140,6 +142,8 @@ Gem::Specification.new do |s|
140
142
  "lib/lolita/rails/all.rb",
141
143
  "lib/lolita/rails/routes.rb",
142
144
  "lib/lolita/ruby_ext/accessors.rb",
145
+ "lib/lolita/support/formatter/base.rb",
146
+ "lib/lolita/support/formatter/rails.rb",
143
147
  "lib/lolita/test/matchers.rb",
144
148
  "lolita.gemspec",
145
149
  "public/images/lolita/plus.png",
@@ -212,6 +216,7 @@ Gem::Specification.new do |s|
212
216
  "spec/configuration/page_spec.rb",
213
217
  "spec/configuration/tab_spec.rb",
214
218
  "spec/configuration/tabs_spec.rb",
219
+ "spec/controllers/component_helpers_spec.rb",
215
220
  "spec/controllers/internal_helpers_spec.rb",
216
221
  "spec/controllers/lolita_rest_nested_resources_spec.rb",
217
222
  "spec/controllers/lolita_rest_spec.rb",
@@ -308,7 +313,8 @@ Gem::Specification.new do |s|
308
313
  "spec/spec_helper.rb",
309
314
  "spec/support/factories/category.rb",
310
315
  "spec/support/factories/post.rb",
311
- "spec/support/factories/tag.rb"
316
+ "spec/support/factories/tag.rb",
317
+ "spec/support/formatter/base_spec.rb"
312
318
  ]
313
319
  s.homepage = %q{http://github.com/ithouse/lolita}
314
320
  s.licenses = ["MIT"]
@@ -328,6 +334,7 @@ Gem::Specification.new do |s|
328
334
  "spec/configuration/page_spec.rb",
329
335
  "spec/configuration/tab_spec.rb",
330
336
  "spec/configuration/tabs_spec.rb",
337
+ "spec/controllers/component_helpers_spec.rb",
331
338
  "spec/controllers/internal_helpers_spec.rb",
332
339
  "spec/controllers/lolita_rest_nested_resources_spec.rb",
333
340
  "spec/controllers/lolita_rest_spec.rb",
@@ -365,7 +372,8 @@ Gem::Specification.new do |s|
365
372
  "spec/spec_helper.rb",
366
373
  "spec/support/factories/category.rb",
367
374
  "spec/support/factories/post.rb",
368
- "spec/support/factories/tag.rb"
375
+ "spec/support/factories/tag.rb",
376
+ "spec/support/formatter/base_spec.rb"
369
377
  ]
370
378
 
371
379
  if s.respond_to? :specification_version then
@@ -99,6 +99,7 @@ header nav .username {margin-right: 15px;}
99
99
  /* navigation styles on left */
100
100
  #main nav {position: absolute; left: 0; min-width: 150px; margin-top: 5px;} /* width just for now */
101
101
  #main nav ul {margin-bottom: 50px;}
102
+ #main nav ul.subtree{margin-bottom: 0px;}
102
103
  #main nav ul li a {display: block; padding: 10px 15px; color: #737373;}
103
104
  #main nav ul li.active a {
104
105
  background: #d9d9d9;
@@ -110,6 +111,19 @@ header nav .username {margin-right: 15px;}
110
111
  -webkit-border-radius: 5px 0 0 5px;
111
112
  border-radius: 5px 0 0 5px;
112
113
  }
114
+ #main nav ul li.with-subtree a{
115
+ border-radius: 5px 0 0 0;
116
+ }
117
+ #main nav ul li.active ul.subtree a{
118
+ background: #fff;
119
+ background: -moz-linear-gradient(left, #fff, #fff);
120
+ background: -webkit-linear-gradient(left, #fff, #fff);
121
+ border: 1px solid #f9f9f9;
122
+ border-radius: 0 0 0 0;
123
+ }
124
+ #main nav ul li.active ul.subtree li.last-in-subtree a{
125
+ border-radius: 0 0 0 5px;
126
+ }
113
127
  /* --------------------------------------------- */
114
128
 
115
129
  /* main content part */
@@ -178,6 +192,7 @@ a.create {
178
192
  .list table td input {vertical-align: middle;}
179
193
  .list table thead {background: #d5d5d5;}
180
194
  .list table thead th {text-align: left;}
195
+ .list table thead th {font-weight:normal;}
181
196
  .list table thead th a {color: #a5a5a5;}
182
197
  .list table thead th.active a {color: #6c6c6c;} /* Style for active header */
183
198
  .list table tbody tr {border-bottom: 1px solid #e3e3e3;}
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe Lolita::Configuration::Column do
4
-
4
+ let(:column){Lolita::Configuration::Column.new(:col1)}
5
5
 
6
6
  it "should create new column with Hash attributes" do
7
7
  column=Lolita::Configuration::Column.new(:name=>"col1",:title=>"Col1",:type=>String)
@@ -41,5 +41,17 @@ describe Lolita::Configuration::Column do
41
41
  end
42
42
  }.should raise_error(ArgumentError, "Column must have name.")
43
43
  end
44
+
45
+ it "should allow to add formatter" do
46
+ column.formatter do|value|
47
+ "value #{value}"
48
+ end
49
+ column.formatter.with("1").should == "value 1"
50
+ end
51
+
52
+ it "should make default formater not defined" do
53
+ column.formatter.with(1).should == 1
54
+ end
55
+
44
56
  end
45
57
 
@@ -65,6 +65,7 @@ describe Lolita::Configuration::Filter do
65
65
  end
66
66
 
67
67
  it "should return right options_for_select" do
68
+ Category.delete_all
68
69
  3.times{ Factory.create(:category)}
69
70
  filter=Lolita::Configuration::Filter.new(@dbi) do
70
71
  field :category
@@ -0,0 +1,6 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+
4
+ describe Lolita::Controllers::ComponentHelpers do
5
+
6
+ end
@@ -24,6 +24,7 @@ describe Lolita::RestController do
24
24
  end
25
25
 
26
26
  it "should overwrite list component body_cell" do
27
+ pending "Need to be seperated from whole project"
27
28
  Factory.create(:post)
28
29
  get :index
29
30
  response.body.should =~/overwritten cell/
data/spec/spec_helper.rb CHANGED
@@ -30,7 +30,7 @@ require 'rspec/rails'
30
30
  require 'ffaker'
31
31
  require 'factory_girl'
32
32
 
33
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
33
+ Dir["#{File.dirname(__FILE__)}/support/factories/**/*.rb"].each {|f| require f}
34
34
  RSpec.configure do |config|
35
35
  # config.mock_with :mocha
36
36
  # config.mock_with :flexmock
@@ -0,0 +1,42 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../simple_spec_helper')
2
+
3
+ describe Lolita::Support::Formatter::Base do
4
+ let(:klass){Lolita::Support::Formatter::Base}
5
+
6
+ context "create new" do
7
+
8
+ it "should accept value as format" do
9
+ formatter=klass.new("%Y-%m")
10
+ formatter.format.should == "%Y-%m"
11
+ end
12
+
13
+ it "should accept block" do
14
+ formatter=klass.new do |value|
15
+ value**2
16
+ end
17
+ formatter.block.should_not be_nil
18
+ end
19
+ end
20
+
21
+ context "calling formatter" do
22
+ it "should call block" do
23
+ formatter=klass.new do |value|
24
+ value.to_i+1
25
+ end
26
+ formatter.with(2).should == 3
27
+ end
28
+
29
+ it "should try to call #format method on given value" do
30
+ formatter=klass.new("M")
31
+ object=mock(Object)
32
+ object.stub!(:format).and_return(1)
33
+ object.stub!(:respond_to?).with(:format).and_return(true)
34
+ formatter.with(object).should == 1
35
+ end
36
+
37
+ it "should convert received value to string and call #unpack" do
38
+ formatter=klass.new('C')
39
+ formatter.with("\100").should == [64]
40
+ end
41
+ end
42
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: lolita
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 3.1.3
5
+ version: 3.1.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - ITHouse (Latvia) and Arturs Meisters
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-15 00:00:00 +03:00
13
+ date: 2011-04-19 00:00:00 +03:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -190,6 +190,17 @@ files:
190
190
  - app/controllers/lolita/rest_controller.rb
191
191
  - app/helpers/components/lolita/configuration/list_component.rb
192
192
  - app/helpers/lolita_helper.rb
193
+ - app/views/components/lolita/configuration/column/_display.html.erb
194
+ - app/views/components/lolita/configuration/column/_header.html.erb
195
+ - app/views/components/lolita/configuration/column/_sort.html.erb
196
+ - app/views/components/lolita/configuration/columns/_body.html.erb
197
+ - app/views/components/lolita/configuration/columns/_display.html.erb
198
+ - app/views/components/lolita/configuration/columns/_first.html.erb
199
+ - app/views/components/lolita/configuration/columns/_first_column_header.html.erb
200
+ - app/views/components/lolita/configuration/columns/_header.html.erb
201
+ - app/views/components/lolita/configuration/columns/_last.html.erb
202
+ - app/views/components/lolita/configuration/columns/_last_column_header.html.erb
203
+ - app/views/components/lolita/configuration/columns/_row.html.erb
193
204
  - app/views/components/lolita/configuration/field/_display.html.erb
194
205
  - app/views/components/lolita/configuration/field/_label.html.erb
195
206
  - app/views/components/lolita/configuration/field/_object.html.erb
@@ -212,20 +223,11 @@ files:
212
223
  - app/views/components/lolita/configuration/field/string/text/_display.html.erb
213
224
  - app/views/components/lolita/configuration/field/time/_display.html.erb
214
225
  - app/views/components/lolita/configuration/field_set/_display.html.erb
215
- - app/views/components/lolita/configuration/list/_body.html.erb
216
- - app/views/components/lolita/configuration/list/_body_cell.html.erb
217
- - app/views/components/lolita/configuration/list/_checkbox_cell.html.erb
218
- - app/views/components/lolita/configuration/list/_checkbox_header.html.erb
219
226
  - app/views/components/lolita/configuration/list/_display.html.erb
220
227
  - app/views/components/lolita/configuration/list/_filter.html.erb
221
- - app/views/components/lolita/configuration/list/_header.html.erb
222
- - app/views/components/lolita/configuration/list/_header_cell.html.erb
223
228
  - app/views/components/lolita/configuration/list/_new_resource.html.erb
224
229
  - app/views/components/lolita/configuration/list/_paginator.html.erb
225
- - app/views/components/lolita/configuration/list/_row.html.erb
226
230
  - app/views/components/lolita/configuration/list/_title.html.erb
227
- - app/views/components/lolita/configuration/list/_tool_cell.html.erb
228
- - app/views/components/lolita/configuration/list/_tool_header.html.erb
229
231
  - app/views/components/lolita/configuration/tab/_display.html.erb
230
232
  - app/views/components/lolita/configuration/tab/_fields.html.erb
231
233
  - app/views/components/lolita/configuration/tab/content/_display.html.erb
@@ -300,6 +302,8 @@ files:
300
302
  - lib/lolita/rails/all.rb
301
303
  - lib/lolita/rails/routes.rb
302
304
  - lib/lolita/ruby_ext/accessors.rb
305
+ - lib/lolita/support/formatter/base.rb
306
+ - lib/lolita/support/formatter/rails.rb
303
307
  - lib/lolita/test/matchers.rb
304
308
  - lolita.gemspec
305
309
  - public/images/lolita/plus.png
@@ -372,6 +376,7 @@ files:
372
376
  - spec/configuration/page_spec.rb
373
377
  - spec/configuration/tab_spec.rb
374
378
  - spec/configuration/tabs_spec.rb
379
+ - spec/controllers/component_helpers_spec.rb
375
380
  - spec/controllers/internal_helpers_spec.rb
376
381
  - spec/controllers/lolita_rest_nested_resources_spec.rb
377
382
  - spec/controllers/lolita_rest_spec.rb
@@ -469,6 +474,7 @@ files:
469
474
  - spec/support/factories/category.rb
470
475
  - spec/support/factories/post.rb
471
476
  - spec/support/factories/tag.rb
477
+ - spec/support/formatter/base_spec.rb
472
478
  has_rdoc: true
473
479
  homepage: http://github.com/ithouse/lolita
474
480
  licenses:
@@ -483,7 +489,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
483
489
  requirements:
484
490
  - - ">="
485
491
  - !ruby/object:Gem::Version
486
- hash: 1019725473
492
+ hash: 193616659
487
493
  segments:
488
494
  - 0
489
495
  version: "0"
@@ -513,6 +519,7 @@ test_files:
513
519
  - spec/configuration/page_spec.rb
514
520
  - spec/configuration/tab_spec.rb
515
521
  - spec/configuration/tabs_spec.rb
522
+ - spec/controllers/component_helpers_spec.rb
516
523
  - spec/controllers/internal_helpers_spec.rb
517
524
  - spec/controllers/lolita_rest_nested_resources_spec.rb
518
525
  - spec/controllers/lolita_rest_spec.rb
@@ -551,3 +558,4 @@ test_files:
551
558
  - spec/support/factories/category.rb
552
559
  - spec/support/factories/post.rb
553
560
  - spec/support/factories/tag.rb
561
+ - spec/support/formatter/base_spec.rb
@@ -1,5 +0,0 @@
1
- <tbody>
2
- <% page.each_with_index do |record,index| %>
3
- <%= render_component :"lolita/configuration/list", :row, :columns=>columns,:record=>record,:index=>index %>
4
- <% end %>
5
- </tbody>
@@ -1,3 +0,0 @@
1
- <td>
2
- <%= value.to_s %>
3
- </td>
@@ -1,9 +0,0 @@
1
- <thead>
2
- <tr>
3
- <%= render_component :"lolita/configuration/list",:checkbox_header %>
4
- <% columns.each do |column| %>
5
- <%= render_component :"lolita/configuration/list", :header_cell, :column=>column %>
6
- <% end %>
7
- <%= render_component :"lolita/configuration/list",:tool_header %>
8
- </tr>
9
- </thead>
@@ -1,5 +0,0 @@
1
- <th>
2
- <% if column %>
3
- <%= column.title %>
4
- <% end %>
5
- </th>
@@ -1,7 +0,0 @@
1
- <tr class="<%= @class_name %>">
2
- <%= render_component :"lolita/configuration/list", :checkbox_cell, :record=>record %>
3
- <% columns.each do |column| %>
4
- <%= render_component :"lolita/configuration/list",:body_cell, :value=>column.with_format(record.send(column.name.to_sym)) %>
5
- <% end %>
6
- <%= render_component :"lolita/configuration/list", :tool_cell,:record=>record %>
7
- </tr>