lolita 4.0.2 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ecde238f39add82144a021f79e9fe92c67f85b7
4
- data.tar.gz: 7cfc0a8722cd3707f8870979a3e3bbefb20ca478
3
+ metadata.gz: 9fc5f5493358ac19cab98481772713454a697efa
4
+ data.tar.gz: 4ce3c24b5ee5141170446006d1e8eea17c940733
5
5
  SHA512:
6
- metadata.gz: 74a47007e7e24320173ae6ddc85275fe569cc49d3a7cb5241be0a91f9bb1ea5dc227acc83a6e0461f74a95dc5d3f29d550fc028459c3e3c65df770c4508c5028
7
- data.tar.gz: 4deae66dae75aa62e668f2ce1b4d8438a8c533fbab0a8a77013a4a2498da1a1feb49d4afa2990ccccc506fd1094d0ce5c6b4c6446e9231bf15e0a8c3b9a1a431
6
+ metadata.gz: 39029642a07f3ef333f82e940046f184a6fe28d6bff0233cea828a08d7d4da9a9d1d2f5a838e841313a656176a8f790aed0393a734aa66b9b2428a5c2798965f
7
+ data.tar.gz: a2aeecba8f7e0fe7d2d183ffcefdd9dd061016e9b3b2b5f6437d8b3b536bb4a0eab18fa8277a070b003f1dc8fc2c637433bd70f9ef22ccbb65ac140171f3b98e
@@ -48,6 +48,7 @@ pre, code, kbd, samp { font-family: monospace, sans-serif; }
48
48
 
49
49
 
50
50
  a:hover, a:active { outline: none; }
51
+ a.pointer { cursor: pointer; }
51
52
 
52
53
  ul, ol { margin-left: 2em; }
53
54
  ol { list-style-type: decimal; }
@@ -2,20 +2,19 @@ module Components
2
2
  module Lolita
3
3
  module ConfigurationComponent
4
4
  def link_to_remove_fields(name, f)
5
- f.hidden_field(:_destroy) + link_to(name, "#", onclick: "remove_fields(this)")
5
+ f.hidden_field(:_destroy) + link_to(name, '#', onclick: 'remove_fields(this); return false;')
6
6
  end
7
7
 
8
8
  def link_to_add_fields(name, f, nested_form)
9
9
  new_object = nested_form.klass.new
10
- fields_content = ""
10
+ fields_content = ''
11
11
  f.fields_for(nested_form.name, new_object, child_index: "new_#{nested_form.name}") do |builder|
12
- self.current_form(builder) do
12
+ current_form(builder) do
13
13
  fields_content = render_component(nested_form, :"fields")
14
14
  end
15
15
  end
16
- link_to(name, "#", onclick: "add_fields(this, \"#{nested_form.name}\", \"#{escape_javascript(fields_content)}\")")
16
+ link_to(name, '', class: 'pointer', onclick: "add_fields(this, \"#{nested_form.name}\", \"#{escape_javascript(fields_content)}\"); return false;")
17
17
  end
18
-
19
18
  end
20
19
  end
21
20
  end
@@ -1,2 +1,2 @@
1
- %td{:class => "first-column cell"}
1
+ %td{:class => "first-column cell"}
2
2
  = check_box_tag "#{resource_name}[id]", record.id
@@ -1,6 +1,6 @@
1
- - sort_mapping = {"desc" => '⇓', "asc" => '⇑'}
2
- - new_params = params.reject{|k,v| ["controller","action"].include?(k.to_s)}
3
- - direction_indicator = raw(sort_mapping[column.current_sort_state(new_params)[1]])
4
- - new_params[:s] = column.sort_params(new_params)
5
-
6
- = link_to raw("#{column.title.to_s.capitalize} #{direction_indicator}"), lolita_resources_path(new_params)
1
+ - sort_mapping = {"desc" => '⇓', "asc" => '⇑'}
2
+ - new_params = params.reject{|k,v| ["controller","action"].include?(k.to_s)}
3
+ - direction_indicator = raw(sort_mapping[column.current_sort_state(new_params)[1]])
4
+ - new_params[:s] = column.sort_params(new_params)
5
+
6
+ = link_to raw("#{column.title.to_s.capitalize} #{direction_indicator}"), lolita_resources_path(new_params)
@@ -9,4 +9,4 @@
9
9
  - self.current_form = old_form
10
10
  - if nested_form.expandable? && !nested_form.update_only?
11
11
  %p
12
- =link_to_add_fields ::I18n.t("lolita.nested_form.add", :resource_name => nested_form.klass.lolita_model_name.human.downcase), current_form, nested_form
12
+ =link_to_add_fields ::I18n.t("lolita.nested_form.add", :resource_name => nested_form.klass.lolita_model_name.human.underscore), current_form, nested_form
@@ -25,12 +25,11 @@ module Lolita
25
25
  # end
26
26
  # end
27
27
  class Column < Lolita::Configuration::Base
28
-
29
- MAX_TEXT_SIZE=20
28
+ MAX_TEXT_SIZE = 20
30
29
  attr_reader :list_association_name
31
- lolita_accessor :name,:title,:type,:options,:sortable, :association
32
-
33
- def initialize(dbi,*args,&block)
30
+ lolita_accessor :name, :title, :type, :options, :sortable, :association
31
+
32
+ def initialize(dbi, *args, &block)
34
33
  set_and_validate_dbi(dbi)
35
34
  set_attributes(*args)
36
35
  instance_eval(&block) if block_given?
@@ -39,14 +38,14 @@ module Lolita
39
38
  detect_association
40
39
  end
41
40
 
42
- def list *args, &block
41
+ def list(*args, &block)
43
42
  if args && args.any? || block_given?
44
43
  detect_association
45
- list_association = args[0] && @dbi.associations[args[0].to_s.to_sym] || self.association
44
+ list_association = args[0] && @dbi.associations[args[0].to_s.to_sym] || association
46
45
  list_dbi = list_association && Lolita::DBI::Base.create(list_association.klass)
47
46
  fail Lolita::UnknownDBPError.new("DBI is not specified for list in column #{self}") unless list_dbi
48
47
  @list_association_name = list_association.name
49
- Lolita::LazyLoader.lazy_load(self,:@list,Lolita::Configuration::NestedList, list_dbi, self, :association_name => list_association.name, &block)
48
+ Lolita::LazyLoader.lazy_load(self, :@list, Lolita::Configuration::NestedList, list_dbi, self, association_name: list_association.name, &block)
50
49
  else
51
50
  @list
52
51
  end
@@ -55,8 +54,8 @@ module Lolita
55
54
  # Return value of column from given record. When record matches foreign key patter, then foreign key is used.
56
55
  # In other cases it just ask for attribute with same name as column.
57
56
  def value(record)
58
- if self.association
59
- if self.association.macro == :one && dbi.klass.respond_to?(:human_attribute_name)
57
+ if association
58
+ if association.macro == :one && dbi.klass.respond_to?(:human_attribute_name)
60
59
  dbi.klass.human_attribute_name(association.name)
61
60
  # dbi.record(record.send(association.name)).title
62
61
  elsif dbi.klass.respond_to?(:human_attribute_name)
@@ -65,20 +64,20 @@ module Lolita
65
64
  "#{association.name} (#{record.send(association.name).count})"
66
65
  end
67
66
  else
68
- record.send(self.name)
67
+ record.send(name)
69
68
  end
70
69
  end
71
70
 
72
- def formatted_value(record,view)
73
- self.formatter.with(self.value(record), record, view)
71
+ def formatted_value(record, view)
72
+ formatter.with(value(record), record, view)
74
73
  end
75
74
 
76
75
  # Set/Get title. Getter return title what was set or ask for human_attribute_name to model.
77
- def title(new_title=nil)
76
+ def title(new_title = nil)
78
77
  if new_title
79
78
  @title = new_title
80
79
  end
81
- Lolita::Utils.dynamic_string(@title, :default => @name && @dbi.klass.human_attribute_name(@name))
80
+ Lolita::Utils.dynamic_string(@title, default: @name && @dbi.klass.human_attribute_name(@name))
82
81
  end
83
82
 
84
83
  def sortable?
@@ -87,40 +86,52 @@ module Lolita
87
86
 
88
87
  # Find if any of received sort options matches this column.
89
88
  def current_sort_state(params)
90
- @sortable && sort_pairs(params).detect{|pair| pair[0]==self.name.to_s} || []
89
+ @sortable && sort_pairs(params).find { |pair| pair[0] == sort_by_name } || []
91
90
  end
92
91
 
93
92
  # Return string with sort options for column if column is sortable.
94
- def sort_params params
93
+ def sort_params(params)
95
94
  if @sortable
96
95
  pairs = sort_pairs(params)
97
96
  found_pair = false
98
- pairs.each_with_index{|pair,index|
99
- if pair[0] == self.name.to_s
100
- pairs[index][1] = pair[1] == "asc" ? "desc" : "asc"
97
+ pairs.each_with_index do|pair, index|
98
+ if pair[0] == sort_by_name
99
+ pairs[index][1] = pair[1] == 'asc' ? 'desc' : 'asc'
101
100
  found_pair = true
102
101
  end
103
- }
102
+ end
104
103
  unless found_pair
105
- pairs << [self.name.to_s,"asc"]
104
+ pairs << [sort_by_name, 'asc']
106
105
  end
107
- (pairs.map{ |pair| pair.join(",") }).join("|")
106
+ (pairs.map { |pair| pair.join(',') }).join('|')
108
107
  else
109
- ""
108
+ ''
110
109
  end
111
110
  end
112
111
 
112
+ # returns value to sort by
113
+ # in default it will be column name, but you can specify it
114
+ # in field configuration
115
+ #
116
+ # === Examples
117
+ # list do
118
+ # field :name, sortable: 'some_table.first_name'
119
+ # end
120
+ def sort_by_name
121
+ @sortable.is_a?(TrueClass) ? name.to_s : @sortable.to_s
122
+ end
123
+
113
124
  # Create array of sort information from params.
114
- def sort_pairs params
115
- (params[:s] || "").split("|").map{|pair| pair.split(",")}
125
+ def sort_pairs(params)
126
+ (params[:s] || '').split('|').map { |pair| pair.split(',') }
116
127
  end
117
128
 
118
129
  # Define format, for details see Lolita::Support::Formatter and Lolita::Support::Formater::Rails
119
- def formatter(value = nil,&block)
130
+ def formatter(value = nil, &block)
120
131
  if block_given?
121
- @formatter = Lolita::Support::Formatter.new(value,&block)
132
+ @formatter = Lolita::Support::Formatter.new(value, &block)
122
133
  elsif value || !@formatter
123
- if value.kind_of?(Lolita::Support::Formatter)
134
+ if value.is_a?(Lolita::Support::Formatter)
124
135
  @formatter = value
125
136
  else
126
137
  @formatter = Lolita::Support::Formatter::Rails.new(value)
@@ -130,7 +141,7 @@ module Lolita
130
141
  end
131
142
 
132
143
  def formatter=(value)
133
- if value.kind_of?(Lolita::Support::Formatter)
144
+ if value.is_a?(Lolita::Support::Formatter)
134
145
  @formatter = value
135
146
  else
136
147
  @formatter = Lolita::Support::Formatter::Rails.new(value)
@@ -140,21 +151,21 @@ module Lolita
140
151
  def set_attributes(*args)
141
152
  options = args ? args.extract_options! : {}
142
153
  if args[0].respond_to?(:field)
143
- [:name,:type].each do |attr|
144
- send(:"#{attr}=",args[0].send(attr))
154
+ [:name, :type].each do |attr|
155
+ send(:"#{attr}=", args[0].send(attr))
145
156
  end
146
157
  elsif args[0]
147
158
  self.name = args[0]
148
159
  end
149
- options.each do |attr_name,value|
150
- send(:"#{attr_name}=",value)
160
+ options.each do |attr_name, value|
161
+ send(:"#{attr_name}=", value)
151
162
  end
152
163
  end
153
-
164
+
154
165
  private
155
166
 
156
167
  def detect_association
157
- @association ||= dbi.associations[self.name]
168
+ @association ||= dbi.associations[name]
158
169
  end
159
170
 
160
171
  def normalize_attributes
@@ -162,8 +173,8 @@ module Lolita
162
173
  end
163
174
 
164
175
  def validate
165
- fail Lolita::UnknownDBIError.new("DBI is not specified for column #{self}") unless self.dbi
166
- fail ArgumentError.new("Column must have name.") unless self.name
176
+ fail Lolita::UnknownDBIError.new("DBI is not specified for column #{self}") unless dbi
177
+ fail ArgumentError.new('Column must have name.') unless name
167
178
  end
168
179
  end
169
180
  end
@@ -2,7 +2,7 @@ module Lolita
2
2
  module Version
3
3
  MAJOR = 4
4
4
  MINOR = 0
5
- PATCH = 2
5
+ PATCH = 3
6
6
  BUILD = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lolita
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.2
4
+ version: 4.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ITHouse (Latvia) and Arturs Meisters