lipsiadmin 5.1.6 → 5.1.7
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.
- data/lib/access_control/authentication.rb +20 -20
- data/lib/access_control/base.rb +40 -40
- data/lib/controller/ext.rb +27 -27
- data/lib/controller/lipsiadmin_controller.rb +3 -3
- data/lib/controller/pdf_builder.rb +33 -31
- data/lib/controller/rescue.rb +12 -12
- data/lib/controller/responds_to_parent.rb +5 -5
- data/lib/data_base/attachment.rb +60 -60
- data/lib/data_base/attachment/attach.rb +18 -18
- data/lib/data_base/attachment/geometry.rb +7 -7
- data/lib/data_base/attachment/iostream.rb +1 -1
- data/lib/data_base/attachment/processor.rb +2 -2
- data/lib/data_base/attachment/storage.rb +11 -11
- data/lib/data_base/attachment/thumbnail.rb +2 -2
- data/lib/data_base/attachment_table.rb +27 -27
- data/lib/data_base/translate_attributes.rb +9 -9
- data/lib/data_base/utility_scopes.rb +7 -7
- data/lib/data_base/without_table.rb +10 -10
- data/lib/generator.rb +4 -4
- data/lib/loops.rb +77 -77
- data/lib/loops/base.rb +2 -2
- data/lib/loops/daemonize.rb +5 -5
- data/lib/loops/process_manager.rb +3 -3
- data/lib/loops/worker.rb +1 -1
- data/lib/loops/worker_pool.rb +1 -1
- data/lib/mailer/exception_notifier.rb +5 -5
- data/lib/mailer/pdf_builder.rb +20 -18
- data/lib/utils/literal.rb +6 -6
- data/lib/utils/pdf_builder.rb +10 -10
- data/lib/version.rb +1 -1
- data/lib/view/helpers/backend_helper.rb +123 -123
- data/lib/view/helpers/ext/button.rb +7 -7
- data/lib/view/helpers/ext/column_model.rb +18 -18
- data/lib/view/helpers/ext/component.rb +50 -50
- data/lib/view/helpers/ext/configuration.rb +5 -5
- data/lib/view/helpers/ext/grid.rb +46 -46
- data/lib/view/helpers/ext/store.rb +14 -14
- data/lib/view/helpers/ext/tool_bar.rb +6 -6
- data/lib/view/helpers/ext_helper.rb +21 -21
- data/lib/view/helpers/frontend_helper.rb +5 -5
- data/lib/view/helpers/pdf_helper.rb +7 -7
- data/lib/view/helpers/view_helper.rb +28 -28
- data/lipsiadmin_generators/attachment/attachment_generator.rb +7 -7
- data/lipsiadmin_generators/attachment/templates/controller.rb +13 -13
- data/lipsiadmin_generators/attachment/templates/migration.rb +1 -1
- data/lipsiadmin_generators/backend/backend_generator.rb +9 -9
- data/lipsiadmin_generators/backend/templates/controllers/backend/accounts_controller.rb +10 -10
- data/lipsiadmin_generators/backend/templates/controllers/backend/sessions_controller.rb +2 -2
- data/lipsiadmin_generators/backend/templates/controllers/javascripts_controller.rb +2 -2
- data/lipsiadmin_generators/backend/templates/migrations/create_accounts.rb +5 -5
- data/lipsiadmin_generators/backend/templates/models/account.rb +16 -16
- data/lipsiadmin_generators/backend/templates/models/account_access.rb +11 -11
- data/lipsiadmin_generators/backend/templates/models/notifier.rb +2 -2
- data/lipsiadmin_generators/backend_page/backend_page_generator.rb +22 -22
- data/lipsiadmin_generators/backend_page/templates/controller.rb +9 -9
- data/lipsiadmin_generators/backend_page/templates/functional_test.rb +10 -10
- data/lipsiadmin_generators/frontend/frontend_generator.rb +5 -5
- data/lipsiadmin_generators/frontend/templates/controllers/frontend/sessions_controller.rb +3 -3
- data/lipsiadmin_generators/loops/loops_generator.rb +2 -2
- data/lipsiadmin_generators/pdf/pdf_generator.rb +7 -7
- data/lipsiadmin_generators/state_session/state_session_generator.rb +9 -9
- data/lipsiadmin_generators/state_session/templates/controller.rb +2 -2
- data/lipsiadmin_generators/state_session/templates/migration.rb +2 -2
- data/resources/rdoc/horo.rb +3 -3
- metadata +4 -4
@@ -12,10 +12,10 @@ module Lipsiadmin
|
|
12
12
|
# Attachment defines an attachment as any file, though it makes special considerations
|
13
13
|
# for image files. You can declare that a model has an attached file with the
|
14
14
|
# +has_one_attachment+ method:
|
15
|
-
#
|
15
|
+
#
|
16
16
|
# From your console:
|
17
17
|
# script/generate attachment
|
18
|
-
#
|
18
|
+
#
|
19
19
|
# Then in any model you can do:
|
20
20
|
#
|
21
21
|
# class User < ActiveRecord::Base
|
@@ -29,15 +29,15 @@ module Lipsiadmin
|
|
29
29
|
#
|
30
30
|
# See the <tt>Lipsiadmin::DataBase::Attachment::ClassMethods</tt> documentation for more details.
|
31
31
|
module Attachment
|
32
|
-
|
32
|
+
|
33
33
|
class << self
|
34
34
|
# Provides configurability to Attachment. There are a number of options available, such as:
|
35
|
-
# * whiny_thumbnails: Will raise an error if Attachment cannot process thumbnails of
|
35
|
+
# * whiny_thumbnails: Will raise an error if Attachment cannot process thumbnails of
|
36
36
|
# an uploaded image. Defaults to false.
|
37
37
|
# * log: Logs progress to the Rails log. Uses ActiveRecord's logger, so honors
|
38
38
|
# log levels, etc. Defaults to true.
|
39
39
|
# * command_path: Defines the path at which to find the command line
|
40
|
-
# programs if they are not visible to Rails the system's search path. Defaults to
|
40
|
+
# programs if they are not visible to Rails the system's search path. Defaults to
|
41
41
|
# nil, which uses the first executable found in the user's search path.
|
42
42
|
# * image_magick_path: Deprecated alias of command_path.
|
43
43
|
def options
|
@@ -53,15 +53,15 @@ module Lipsiadmin
|
|
53
53
|
name = name.to_s.camelize
|
54
54
|
processor = Lipsiadmin::Attachment.const_get(name)
|
55
55
|
unless processor.ancestors.include?(Lipsiadmin::Attachment::Processor)
|
56
|
-
raise AttachmentError.new("Processor #{name} was not found")
|
56
|
+
raise AttachmentError.new("Processor #{name} was not found")
|
57
57
|
end
|
58
58
|
processor
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
def interpolates(key, &block) #:nodoc:
|
62
62
|
Lipsiadmin::Attachment.interpolations[key] = block
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
# The run method takes a command to execute and a string of parameters
|
66
66
|
# that get passed to it. The command is prefixed with the :command_path
|
67
67
|
# option from Attachment.options. If you have many commands to run and
|
@@ -80,7 +80,7 @@ module Lipsiadmin
|
|
80
80
|
end
|
81
81
|
output
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
def path_for_command(command)#:nodoc:
|
85
85
|
path = [options[:command_path] || options[:image_magick_path], command].compact
|
86
86
|
File.join(*path)
|
@@ -90,7 +90,7 @@ module Lipsiadmin
|
|
90
90
|
File.exists?("/dev/null") ? "/dev/null" : "NUL"
|
91
91
|
end
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
class AttachmentError < StandardError #:nodoc:
|
95
95
|
end
|
96
96
|
|
@@ -99,7 +99,7 @@ module Lipsiadmin
|
|
99
99
|
|
100
100
|
class NotIdentifiedByImageMagickError < AttachmentError #:nodoc:
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
# The Attachment class manages the files for a given attachment. It saves
|
104
104
|
# when the model saves, deletes when the model is destroyed, and processes
|
105
105
|
# the file upon assignment.
|
@@ -148,7 +148,7 @@ module Lipsiadmin
|
|
148
148
|
|
149
149
|
normalize_style_definition
|
150
150
|
initialize_storage
|
151
|
-
|
151
|
+
|
152
152
|
log("Attachment on #{instance.class} initialized.")
|
153
153
|
end
|
154
154
|
|
@@ -156,7 +156,7 @@ module Lipsiadmin
|
|
156
156
|
# errors, assigns attributes, processes the file, and runs validations. It
|
157
157
|
# also queues up the previous file for deletion, to be flushed away on
|
158
158
|
# #save of its host. In addition to form uploads, you can also assign
|
159
|
-
# another Attachment attachment:
|
159
|
+
# another Attachment attachment:
|
160
160
|
# new_user.avatar = old_user.avatar
|
161
161
|
# If the file that is assigned is not valid, the processing (i.e.
|
162
162
|
# thumbnailing, etc) will NOT be run.
|
@@ -193,7 +193,7 @@ module Lipsiadmin
|
|
193
193
|
|
194
194
|
solidify_style_definitions
|
195
195
|
post_process if valid?
|
196
|
-
|
196
|
+
|
197
197
|
# Reset the file size if the original file was reprocessed.
|
198
198
|
instance_write(:file_size, @queued_for_write[:original].size.to_i)
|
199
199
|
ensure
|
@@ -282,7 +282,7 @@ module Lipsiadmin
|
|
282
282
|
instance_read(:content_type)
|
283
283
|
end
|
284
284
|
|
285
|
-
# Returns the last modified time of the file as originally assigned, and
|
285
|
+
# Returns the last modified time of the file as originally assigned, and
|
286
286
|
# lives in the <attachment>_updated_at attribute of the model.
|
287
287
|
def updated_at
|
288
288
|
time = instance_read(:updated_at)
|
@@ -304,7 +304,7 @@ module Lipsiadmin
|
|
304
304
|
:basename => lambda do |attachment,style|
|
305
305
|
attachment.original_filename.gsub(/#{File.extname(attachment.original_filename)}$/, "")
|
306
306
|
end,
|
307
|
-
:extension => lambda do |attachment,style|
|
307
|
+
:extension => lambda do |attachment,style|
|
308
308
|
((style = attachment.styles[style]) && style[:format]) ||
|
309
309
|
File.extname(attachment.original_filename).gsub(/^\.+/, "")
|
310
310
|
end,
|
@@ -415,7 +415,7 @@ module Lipsiadmin
|
|
415
415
|
def solidify_style_definitions #:nodoc:
|
416
416
|
@styles.each do |name, args|
|
417
417
|
if @styles[name][:geometry].respond_to?(:call)
|
418
|
-
@styles[name][:geometry] = @styles[name][:geometry].call(instance)
|
418
|
+
@styles[name][:geometry] = @styles[name][:geometry].call(instance)
|
419
419
|
end
|
420
420
|
end
|
421
421
|
end
|
@@ -508,4 +508,4 @@ module Lipsiadmin
|
|
508
508
|
|
509
509
|
end
|
510
510
|
end
|
511
|
-
end
|
511
|
+
end
|
@@ -76,12 +76,12 @@ module Lipsiadmin
|
|
76
76
|
to_s
|
77
77
|
end
|
78
78
|
|
79
|
-
# Returns the scaling and cropping geometries (in string-based ImageMagick format)
|
80
|
-
# neccessary to transform this Geometry into the Geometry given. If crop is true,
|
81
|
-
# then it is assumed the destination Geometry will be the exact final resolution.
|
82
|
-
# In this case, the source Geometry is scaled so that an image containing the
|
83
|
-
# destination Geometry would be completely filled by the source image, and any
|
84
|
-
# overhanging image would be cropped. Useful for square thumbnail images. The cropping
|
79
|
+
# Returns the scaling and cropping geometries (in string-based ImageMagick format)
|
80
|
+
# neccessary to transform this Geometry into the Geometry given. If crop is true,
|
81
|
+
# then it is assumed the destination Geometry will be the exact final resolution.
|
82
|
+
# In this case, the source Geometry is scaled so that an image containing the
|
83
|
+
# destination Geometry would be completely filled by the source image, and any
|
84
|
+
# overhanging image would be cropped. Useful for square thumbnail images. The cropping
|
85
85
|
# is weighted at the center of the Geometry.
|
86
86
|
def transformation_to(dst, crop = false)
|
87
87
|
if crop
|
@@ -114,4 +114,4 @@ module Lipsiadmin
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
end
|
117
|
-
end
|
117
|
+
end
|
@@ -7,7 +7,7 @@ module Lipsiadmin
|
|
7
7
|
#
|
8
8
|
# Processors are required to be defined inside the Attachment module and
|
9
9
|
# are also required to be a subclass of Attachment::Processor. There are
|
10
|
-
# only two methods you must implement to properly be a subclass:
|
10
|
+
# only two methods you must implement to properly be a subclass:
|
11
11
|
# #initialize and #make. Initialize's arguments are the file that will
|
12
12
|
# be operated on (which is an instance of File), and a hash of options
|
13
13
|
# that were defined in has_attached_file's style hash.
|
@@ -46,4 +46,4 @@ module Lipsiadmin
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
49
|
-
end
|
49
|
+
end
|
@@ -9,11 +9,11 @@ module Lipsiadmin
|
|
9
9
|
# * +path+: The location of the repository of attachments on disk. This can (and, in
|
10
10
|
# almost all cases, should) be coordinated with the value of the +url+ option to
|
11
11
|
# allow files to be saved into a place where Apache can serve them without
|
12
|
-
# hitting your app. Defaults to
|
12
|
+
# hitting your app. Defaults to
|
13
13
|
# ":rails_root/public/:attachment/:id/:style/:basename.:extension"
|
14
|
-
# By default this places the files in the app's public directory which can be served
|
15
|
-
# directly. If you are using capistrano for deployment, a good idea would be to
|
16
|
-
# make a symlink to the capistrano-created system directory from inside your app's
|
14
|
+
# By default this places the files in the app's public directory which can be served
|
15
|
+
# directly. If you are using capistrano for deployment, a good idea would be to
|
16
|
+
# make a symlink to the capistrano-created system directory from inside your app's
|
17
17
|
# public directory.
|
18
18
|
# See Attachment::Attachment#interpolate for more information on variable interpolaton.
|
19
19
|
# :path => "/var/app/attachments/:class/:id/:style/:basename.:extension"
|
@@ -83,25 +83,25 @@ module Lipsiadmin
|
|
83
83
|
# database.yml file, so different environments can use different accounts:
|
84
84
|
# development:
|
85
85
|
# access_key_id: 123...
|
86
|
-
# secret_access_key: 123...
|
86
|
+
# secret_access_key: 123...
|
87
87
|
# test:
|
88
88
|
# access_key_id: abc...
|
89
|
-
# secret_access_key: abc...
|
89
|
+
# secret_access_key: abc...
|
90
90
|
# production:
|
91
91
|
# access_key_id: 456...
|
92
|
-
# secret_access_key: 456...
|
92
|
+
# secret_access_key: 456...
|
93
93
|
# This is not required, however, and the file may simply look like this:
|
94
94
|
# access_key_id: 456...
|
95
|
-
# secret_access_key: 456...
|
95
|
+
# secret_access_key: 456...
|
96
96
|
# In which case, those access keys will be used in all environments. You can also
|
97
97
|
# put your bucket name in this file, instead of adding it to the code directly.
|
98
|
-
# This is useful when you want the same account but a different bucket for
|
98
|
+
# This is useful when you want the same account but a different bucket for
|
99
99
|
# development versus production.
|
100
100
|
# * +s3_permissions+: This is a String that should be one of the "canned" access
|
101
101
|
# policies that S3 provides (more information can be found here:
|
102
102
|
# http://docs.amazonwebservices.com/AmazonS3/2006-03-01/RESTAccessPolicy.html#RESTCannedAccessPolicies)
|
103
103
|
# The default for Attachment is "public-read".
|
104
|
-
# * +s3_protocol+: The protocol for the URLs generated to your S3 assets. Can be either
|
104
|
+
# * +s3_protocol+: The protocol for the URLs generated to your S3 assets. Can be either
|
105
105
|
# 'http' or 'https'. Defaults to 'http' when your :s3_permissions are 'public-read' (the
|
106
106
|
# default), and 'https' when your :s3_permissions are anything else.
|
107
107
|
# * +s3_headers+: A hash of headers such as {'Expires' => 1.year.from_now.httpdate}
|
@@ -217,4 +217,4 @@ module Lipsiadmin
|
|
217
217
|
end
|
218
218
|
end
|
219
219
|
end
|
220
|
-
end
|
220
|
+
end
|
@@ -10,7 +10,7 @@ module Lipsiadmin
|
|
10
10
|
# which is a "WxH"-style string. +format+ will be inferred from the +file+
|
11
11
|
# unless specified. Thumbnail creation will raise no errors unless
|
12
12
|
# +whiny+ is true (which it is, by default. If +convert_options+ is
|
13
|
-
# set, the options will be appended to the convert command upon image conversion
|
13
|
+
# set, the options will be appended to the convert command upon image conversion
|
14
14
|
def initialize(file, options = {})
|
15
15
|
super
|
16
16
|
geometry = options[:geometry]
|
@@ -69,4 +69,4 @@ module Lipsiadmin
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
72
|
-
end
|
72
|
+
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
module Lipsiadmin
|
2
2
|
module DataBase
|
3
|
-
# This is the table that handle the attachments.
|
3
|
+
# This is the table that handle the attachments.
|
4
4
|
# You can define some global info like:
|
5
|
-
#
|
5
|
+
#
|
6
6
|
# attachment_styles :thumb, "128x128"
|
7
|
-
#
|
8
|
-
# In this way all models that use <tt>has_one_attachment</tt> or
|
7
|
+
#
|
8
|
+
# In this way all models that use <tt>has_one_attachment</tt> or
|
9
9
|
# <tt>has_many_attachments</tt> handle a default style called *thumb*
|
10
|
-
#
|
11
|
-
# Remember that any model that use <tt>has_one_attachment</tt> or
|
10
|
+
#
|
11
|
+
# Remember that any model that use <tt>has_one_attachment</tt> or
|
12
12
|
# <tt>has_many_attachments</tt> can override/add styles/validations etc...
|
13
|
-
#
|
13
|
+
#
|
14
14
|
class AttachmentTable < ActiveRecord::Base
|
15
15
|
def self.inherited(subclass)#:nodoc:
|
16
16
|
super
|
@@ -19,58 +19,58 @@ module Lipsiadmin
|
|
19
19
|
subclass.send(:include, Lipsiadmin::DataBase::UtilityScopes)
|
20
20
|
subclass.extend(ClassMethods)
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
set_table_name "attachments"
|
24
|
-
|
24
|
+
|
25
25
|
belongs_to :attacher, :polymorphic => true
|
26
26
|
after_save :save_attached_files
|
27
27
|
before_destroy :destroy_attached_files
|
28
28
|
define_callbacks :before_post_process, :after_post_process
|
29
29
|
define_callbacks :"before_attached_post_process", :"after_attached_post_process"
|
30
|
-
|
30
|
+
|
31
31
|
#validates_presence_of :filename
|
32
|
-
|
32
|
+
|
33
33
|
# Returns the url of the attachment, optionally you can pass the style like url(:thumb)
|
34
34
|
def url(style=nil)
|
35
35
|
file.url(style)
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
# Returns a <tt>Lipsiadmin::Attachment::Attach</tt> instance
|
39
39
|
def file
|
40
40
|
@_file ||= Lipsiadmin::Attachment::Attach.new(:attached, self, attachment_definitions)
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
# Assign a <tt>Lipsiadmin::Attachment::Attach</tt> instance to the current file
|
44
44
|
def file=(tempfile)
|
45
45
|
file.assign(tempfile)
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
# Returns true if the file exist
|
49
49
|
def file?
|
50
50
|
file.exist?
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def attachment_definitions=(options)#:nodoc:
|
54
54
|
attachment_definitions.merge!(options.symbolize_keys)
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
# This is the custom instance attachment_definition
|
58
58
|
def attachment_definitions#:nodoc:
|
59
59
|
@instance_attachment_definitions ||= self.class.attachment_definitions[self.class.name].clone
|
60
60
|
return @instance_attachment_definitions
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
validates_each(:file) do |record, attr, value|
|
64
64
|
attachment = record.file
|
65
65
|
attachment.send(:flush_errors) unless attachment.valid?
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
# Perform <tt>file</tt>.save
|
69
69
|
def save_attached_files
|
70
70
|
logger.info("[Attachment] Saving attachments.")
|
71
71
|
file.save
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
# Perform <tt>file</tt>.destroy
|
75
75
|
def destroy_attached_files
|
76
76
|
logger.info("[Attachment] Deleting attachments.")
|
@@ -78,7 +78,7 @@ module Lipsiadmin
|
|
78
78
|
file.flush_deletes
|
79
79
|
end
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
module ClassMethods#:nodoc:
|
83
83
|
|
84
84
|
def attachment_url(url)
|
@@ -88,15 +88,15 @@ module Lipsiadmin
|
|
88
88
|
def attachment_default_url(url)
|
89
89
|
attachment_default_url_for(self.name, url)
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
def attachment_path(path)
|
93
93
|
attachment_path_for(self.name, path)
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
def attachment_styles(name, styles)
|
97
97
|
attachment_styles_for(self.name, name, styles)
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
def attachment_default_style(default_style)
|
101
101
|
attachment_default_style_for(self.name, default_style)
|
102
102
|
end
|
@@ -108,15 +108,15 @@ module Lipsiadmin
|
|
108
108
|
def attachment_storage(storage)
|
109
109
|
attachment_storage_for(self.name, storage)
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
def attachment_convert_options(name, convert_options)
|
113
113
|
attachment_convert_options_for(self.name, name, convert_options)
|
114
114
|
end
|
115
|
-
|
115
|
+
|
116
116
|
def attachment_background(background)
|
117
117
|
attachment_background_for(self.name, background)
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
120
|
def attachment_processors(processors)
|
121
121
|
attachment_processors_for(self.name, processors)
|
122
122
|
end
|
@@ -137,6 +137,6 @@ module Lipsiadmin
|
|
137
137
|
validates_attachment_content_type_for(self.name, options)
|
138
138
|
end
|
139
139
|
end
|
140
|
-
|
140
|
+
|
141
141
|
end
|
142
142
|
end
|
@@ -1,23 +1,23 @@
|
|
1
1
|
module Lipsiadmin
|
2
2
|
module DataBase
|
3
|
-
# With this method we can translate define and automatically translate columns for
|
3
|
+
# With this method we can translate define and automatically translate columns for
|
4
4
|
# the current rails locale.
|
5
|
-
#
|
5
|
+
#
|
6
6
|
# Defining some columns like these:
|
7
|
-
#
|
7
|
+
#
|
8
8
|
# m.col :string, :name_it, :name_en, :name_cz
|
9
9
|
# m.col :text, :description_it, :description_en, :description_cz
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# we can call
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# myinstance.name
|
14
|
-
#
|
14
|
+
#
|
15
15
|
# or
|
16
|
-
#
|
16
|
+
#
|
17
17
|
# puts myinstance.description
|
18
|
-
#
|
18
|
+
#
|
19
19
|
# Lipsiadmin look for name_#{I18n.locale}
|
20
|
-
#
|
20
|
+
#
|
21
21
|
module TranslateAttributes
|
22
22
|
# Define <tt>method missing</tt> to intercept calls to non-localized methods (eg. +name+ instead of +name_cz+)
|
23
23
|
def method_missing(method_name, *arguments)
|
@@ -1,20 +1,20 @@
|
|
1
1
|
module Lipsiadmin
|
2
2
|
module DataBase
|
3
3
|
# This Module provides named scope for:
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# - Search records in a extjs way (but can reusable)
|
6
6
|
# - Paginate records in a extjs way (but can be reusable)
|
7
7
|
# - Add association to the model (used for search in dependents tables)
|
8
|
-
#
|
8
|
+
#
|
9
9
|
# Examples:
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# invoices = current_account.store.invoices.with(:order).ext_search(params)
|
12
12
|
# invoices_count = invoices.size
|
13
13
|
# invoices_paginated = invoices.ext_paginate(params)
|
14
|
-
#
|
14
|
+
#
|
15
15
|
module UtilityScopes
|
16
16
|
def self.included(base)#:nodoc:
|
17
|
-
base.class_eval do
|
17
|
+
base.class_eval do
|
18
18
|
named_scope :ext_search, lambda { |params|
|
19
19
|
order = params[:sort].blank? && params[:dir].blank? ? nil : "#{params[:sort]} #{params[:dir]}"
|
20
20
|
conditions = nil
|
@@ -31,7 +31,7 @@ module Lipsiadmin
|
|
31
31
|
{ :order => order, :limit => params[:limit], :offset => params[:start] }
|
32
32
|
}
|
33
33
|
named_scope :with, lambda { |*associations| { :include => associations } }
|
34
|
-
|
34
|
+
|
35
35
|
# You or your plugins (ex: will_paginate) now can override the search/paginate
|
36
36
|
# at the moment we can't remove them for backward compatibility.
|
37
37
|
(class << self; self end).instance_eval do
|
@@ -45,4 +45,4 @@ module Lipsiadmin
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
48
|
-
end
|
48
|
+
end
|