auxiliary_addons 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README +27 -0
- data/Rakefile +23 -0
- data/auxiliary_addons.gemspec +17 -0
- data/changelog +26 -0
- data/init.rb +2 -0
- data/install.rb +1 -0
- data/knownbugs +17 -0
- data/lib/auxiliary_addons.rb +50 -0
- data/lib/auxiliary_addons/error_helper.rb +24 -0
- data/lib/auxiliary_addons/filter_utils.rb +43 -0
- data/lib/auxiliary_addons/form_helper.rb +139 -0
- data/lib/auxiliary_addons/html_helper.rb +48 -0
- data/lib/auxiliary_addons/jscript_helper.rb +25 -0
- data/lib/auxiliary_addons/list_helper.rb +54 -0
- data/lib/auxiliary_addons/ruby_addons.rb +42 -0
- data/lib/auxiliary_addons/tableless_model.rb +16 -0
- data/lib/auxiliary_addons/validateable_model.rb +37 -0
- data/roadmap +19 -0
- data/spec/lib/auxiliary_addons/error_helper_spec.rb +5 -0
- data/spec/lib/auxiliary_addons/filter_utils_spec.rb +5 -0
- data/spec/lib/auxiliary_addons/form_helper_spec.rb +5 -0
- data/spec/lib/auxiliary_addons/html_helper_spec.rb +6 -0
- data/spec/lib/auxiliary_addons/jscript_helper_spec.rb +5 -0
- data/spec/lib/auxiliary_addons/list_helper_spec.rb +5 -0
- data/spec/lib/auxiliary_addons/ruby_addons_spec.rb +6 -0
- data/spec/lib/auxiliary_addons/tableless_model_spec.rb +7 -0
- data/spec/lib/auxiliary_addons/validateable_model_spec.rb +7 -0
- data/spec/lib/auxiliary_addons_spec.rb +7 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +23 -0
- data/tasks/auxiliary_addons_tasks.rake +4 -0
- data/uninstall.rb +1 -0
- metadata +81 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Artem Rufanov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
AuxiliaryAddons
|
2
|
+
===================
|
3
|
+
|
4
|
+
AuxiliaryAddons is a gem that contains basic helpers.
|
5
|
+
|
6
|
+
* The gem supports ruby 1.9.x & rails 3.x
|
7
|
+
* The gem supports ruby 1.8.7 & rails 2.5.x
|
8
|
+
* The gem allows ...
|
9
|
+
|
10
|
+
Quick Start
|
11
|
+
=======
|
12
|
+
In your Gemfile:
|
13
|
+
|
14
|
+
gem "auxiliary_addons", ">= 0.5.4"
|
15
|
+
|
16
|
+
Installation
|
17
|
+
=======
|
18
|
+
|
19
|
+
* Type 'gem install --local auxiliary_addons' with root account if you have installed RubyGems.
|
20
|
+
|
21
|
+
|
22
|
+
Example
|
23
|
+
=======
|
24
|
+
|
25
|
+
Example goes here.
|
26
|
+
|
27
|
+
Copyright (c) 2011 arufanov, released under the MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the auxiliary_addons plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.libs << 'test'
|
12
|
+
t.pattern = 'test/**/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate documentation for the auxiliary_addons plugin.'
|
17
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
18
|
+
rdoc.rdoc_dir = 'rdoc'
|
19
|
+
rdoc.title = 'AuxiliaryAddons'
|
20
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
21
|
+
rdoc.rdoc_files.include('README')
|
22
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'date'
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.name = %q{auxiliary_addons}
|
4
|
+
s.version = "0.5.4"
|
5
|
+
s.date = Date.today.to_s
|
6
|
+
s.summary = %q{AuxiliaryAddons is a gem that contains basic helpers.}
|
7
|
+
s.description = %q{AuxiliaryAddons is a gem that contains basic helpers.}
|
8
|
+
s.author = %q{Artem Rufanov}
|
9
|
+
s.email = %q{developers@majoron.com}
|
10
|
+
s.homepage = %q{http://www.majoron.com/project/rbundle/auxiliary_addons}
|
11
|
+
s.files = Dir.glob('**/*') - Dir.glob('distrib/**/*') - Dir.glob('lib/api/**/*') - Dir.glob('doc/*.xpr')
|
12
|
+
s.bindir = 'bin'
|
13
|
+
s.executables = Dir.glob('bin/*').collect {|f| File.basename(f)}
|
14
|
+
s.require_paths << 'doc' << 'examples' << 'lib' << 'test'
|
15
|
+
s.has_rdoc = true
|
16
|
+
s.required_ruby_version = '>= 1.8.7'
|
17
|
+
end
|
data/changelog
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Introduction:
|
2
|
+
To see the latest list of the change log please visit the Change Log page at www.majoron.com.
|
3
|
+
|
4
|
+
Legend:
|
5
|
+
Follow notation is used at change log, roadmap and known bugs. Each bug begins with a version,
|
6
|
+
then follow category of the bug inside {}. It can be bug report, feature request and etc.
|
7
|
+
Then follow component inside []. After follow bug number at bug tracking system between // signs.
|
8
|
+
And then follow a short description of the bug.
|
9
|
+
|
10
|
+
Example:
|
11
|
+
For example bug: "1.0 { Feature Request } [ AntHill ] / 380 / STLport support required" means
|
12
|
+
that bug was created for 1.0 version of the AntHill component, bug is feature request with
|
13
|
+
380 number at bug tracking system. And bug requires STLPort support implementation.
|
14
|
+
|
15
|
+
Version 0.5
|
16
|
+
-----------
|
17
|
+
0.5 { Bug Report } [ AuxiliaryAddons ] / X / Ruby 2.5.x support
|
18
|
+
0.5 { Bug Report } [ AuxiliaryAddons ] / X / Handle special case (all selected) at cast_ids_to_i function
|
19
|
+
0.5 { Bug Report } [ AuxiliaryAddons ] / X / Changelog, roadmap, knownbugs have been created
|
20
|
+
0.5 { Bug Report } [ AuxiliaryAddons ] / X / Add the @attributes to tableless module
|
21
|
+
0.5 { Bug Report } [ AuxiliaryAddons ] / X / Implement validateable_model and tablelessmodel
|
22
|
+
0.5 { Bug Report } [ AuxiliaryAddons ] / X / Fixed: DEPRECATION WARNING: Errors#on have been deprecated, use Errors#[] instead.
|
23
|
+
0.5 { Bug Report } [ AuxiliaryAddons ] / X / Renamed markers/arrow_(up|down).png to arrows/arrow_(up|down).png
|
24
|
+
0.5 { Bug Report } [ AuxiliaryAddons ] / X / Fixed problem with output += image_tag("img.png") bu using raw
|
25
|
+
0.5 { Bug Report } [ AuxiliaryAddons ] / X / Implemented set_focus_on_load based on prototype and jquery library
|
26
|
+
0.5 { Bug Report } [ AuxiliaryAddons ] / X / Implemented cast_ids_to_i function
|
data/init.rb
ADDED
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
data/knownbugs
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Introduction:
|
2
|
+
To see the latest list of the known bugs please visit the Known bugs page at www.majoron.com.
|
3
|
+
|
4
|
+
Legend:
|
5
|
+
Follow notation is used at change log, roadmap and known bugs. Each bug begins with a version,
|
6
|
+
then follow category of the bug inside {}. It can be bug report, feature request and etc.
|
7
|
+
Then follow component inside []. After follow bug number at bug tracking system between // signs.
|
8
|
+
And then follow a short description of the bug.
|
9
|
+
|
10
|
+
Example:
|
11
|
+
For example bug: "1.0 { Feature Request } [ AntHill ] / 380 / STLport support required" means
|
12
|
+
that bug was created for 1.0 version of the AntHill component, bug is feature request with
|
13
|
+
380 number at bug tracking system. And bug requires STLPort support implementation.
|
14
|
+
|
15
|
+
Version 0.5
|
16
|
+
-----------
|
17
|
+
0.5 { Bug Report } [ AuxiliaryAddons ] / X / There isn't known bugs
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# Include
|
2
|
+
require 'rubygems'
|
3
|
+
require 'active_support'
|
4
|
+
require 'auxiliary_addons/error_helper'
|
5
|
+
require 'auxiliary_addons/filter_utils'
|
6
|
+
require 'auxiliary_addons/form_helper'
|
7
|
+
require 'auxiliary_addons/html_helper'
|
8
|
+
require 'auxiliary_addons/jscript_helper'
|
9
|
+
require 'auxiliary_addons/list_helper'
|
10
|
+
require 'auxiliary_addons/ruby_addons'
|
11
|
+
|
12
|
+
# Only for Rails 3.x
|
13
|
+
if Rails::VERSION::MAJOR >= 3
|
14
|
+
require 'auxiliary_addons/tableless_model'
|
15
|
+
require 'auxiliary_addons/validateable_model'
|
16
|
+
end
|
17
|
+
|
18
|
+
# =
|
19
|
+
#
|
20
|
+
module AuxiliaryAddons
|
21
|
+
|
22
|
+
# default options that can be overridden on the global level
|
23
|
+
@@options = {
|
24
|
+
:use_prototype => false, #
|
25
|
+
:use_jquery => true, #
|
26
|
+
:use_jquery_no_conflict => false, #
|
27
|
+
}
|
28
|
+
mattr_reader :options
|
29
|
+
|
30
|
+
def self.enable_activerecord
|
31
|
+
ActiveRecord::Base.send :include, AuxiliaryAddons::RubyAddons
|
32
|
+
ActiveRecord::Base.send :include, AuxiliaryAddons::FilterUtils
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.enable_actionpack
|
36
|
+
ActionController::Base.send :include, AuxiliaryAddons::RubyAddons
|
37
|
+
|
38
|
+
ActionView::Base.send :include, AuxiliaryAddons::RubyAddons
|
39
|
+
ActionView::Base.send :include, AuxiliaryAddons::ErrorHelper
|
40
|
+
ActionView::Base.send :include, AuxiliaryAddons::FormHelper
|
41
|
+
ActionView::Base.send :include, AuxiliaryAddons::HtmlHelper
|
42
|
+
ActionView::Base.send :include, AuxiliaryAddons::JscriptHelper
|
43
|
+
ActionView::Base.send :include, AuxiliaryAddons::ListHelper
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
if defined? Rails
|
48
|
+
AuxiliaryAddons.enable_activerecord if defined? ActiveRecord
|
49
|
+
AuxiliaryAddons.enable_actionpack if defined? ActionController
|
50
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module AuxiliaryAddons
|
2
|
+
module ErrorHelper
|
3
|
+
# ::Rails.logger.error("...")
|
4
|
+
|
5
|
+
#
|
6
|
+
# Common helpers to error processing
|
7
|
+
#
|
8
|
+
# Check is error or not for fields
|
9
|
+
def is_error_message_on(object, method)
|
10
|
+
object = instance_variable_get("@#{object}")
|
11
|
+
if object.nil? || !object.errors.on(method)
|
12
|
+
return true
|
13
|
+
end
|
14
|
+
return false
|
15
|
+
end
|
16
|
+
|
17
|
+
# Show hint on the fields if error not exists
|
18
|
+
def hint_message_on(object, method, hint, css_class = "formHint")
|
19
|
+
return if !is_error_message_on(object, method)
|
20
|
+
content_tag("div", hint, :class => css_class)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module AuxiliaryAddons
|
2
|
+
# contains auxiliary functions to build conditions
|
3
|
+
module FilterUtils
|
4
|
+
# ::Rails.logger.error("...")
|
5
|
+
|
6
|
+
def self.like
|
7
|
+
lambda do |col_name, field_name, field_value|
|
8
|
+
field_value.size()==0 ? nil : "(#{col_name} like :#{field_name})"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.less_than
|
13
|
+
lambda do |col_name, field_name, field_value|
|
14
|
+
field_value.size()==0 ? nil : "(#{col_name} < :#{field_name})"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.more_than
|
19
|
+
lambda do |col_name, field_name, field_value|
|
20
|
+
field_value.size()==0 ? nil : "(#{col_name} > :#{field_name})"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# the first parameter is a hash containing the values for each key
|
25
|
+
# the second parameter is a hash containing filter specs for each key
|
26
|
+
# the return value is the condition string to pass to the find method
|
27
|
+
def self.get_conditions(filter,filter_spec)
|
28
|
+
conditions = ""
|
29
|
+
filter_spec.each do |k,spec|
|
30
|
+
if spec.class == Array
|
31
|
+
r = spec[1].call(spec[0].to_s,k.to_s,filter[k])
|
32
|
+
else
|
33
|
+
r = spec.call(k.to_s,k.to_s,filter[k])
|
34
|
+
end
|
35
|
+
if r
|
36
|
+
conditions = conditions + (conditions.size()>0? " and "+r : r)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
return conditions
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
module AuxiliaryAddons
|
2
|
+
module FormHelper
|
3
|
+
# ::Rails.logger.error("...")
|
4
|
+
|
5
|
+
include ActionView::Helpers::FormHelper
|
6
|
+
#
|
7
|
+
# Common helpers to customize form elements
|
8
|
+
#
|
9
|
+
# Checks if there is an error for a field of given object defined by given method
|
10
|
+
|
11
|
+
def is_error_message_on(object, method)
|
12
|
+
# DEPRECATION WARNING: Errors#on have been deprecated, use Errors#[] instead.
|
13
|
+
# if object.nil? || !object.errors.on(method)
|
14
|
+
if object.nil? || !object.errors[method] || (object.errors[method].size() == 0)
|
15
|
+
return false
|
16
|
+
end
|
17
|
+
true
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# Outputs div block with a hint message related to the field of object defined by method
|
22
|
+
# The hint message is printed if there's no error on the field. The message's text is either given
|
23
|
+
# by the 'hint' parameter or defined by 'activerecord.hints.models.#{object_name}.attributes.#{method}'
|
24
|
+
# key in localization files.
|
25
|
+
#
|
26
|
+
# Besides usuals options the following one is defined:
|
27
|
+
# :hint_class - CSS class for the hint div
|
28
|
+
#
|
29
|
+
# Example:
|
30
|
+
# ..
|
31
|
+
# hint_message_on @user, :post, '(use only characters and digits)'
|
32
|
+
# # If there's no error on :post will output: <div class="form-hint">(use only characters and digits)</div>
|
33
|
+
#
|
34
|
+
def hint_message_on(object, method, hint = '', options = {})
|
35
|
+
return if is_error_message_on(object, method)
|
36
|
+
if hint.nil? || hint.blank?
|
37
|
+
# Here is patcha for rails 3.0.x
|
38
|
+
# object_name = ActionController::RecordIdentifier.singular_class_name(object)
|
39
|
+
object_name = ActiveModel::Naming.singular(object)
|
40
|
+
hint = I18n.t("activerecord.hints.models.#{object_name}.attributes.#{method.to_s}")
|
41
|
+
end
|
42
|
+
hint_class = options.delete(:hint_class) || 'form-hint'
|
43
|
+
content_tag("div", hint, :class => hint_class)
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Outputs label that appends mandatory symbol (e.g. '*') to the label's text
|
48
|
+
# Possible options are the same as for label method plus the following:
|
49
|
+
# :mandatory_symbol - symbol to applend, default is '*'
|
50
|
+
# :symbol_class = CSS class of the span element which surrounds this symbol, default is 'mandatory-field' class
|
51
|
+
#
|
52
|
+
# mandatory_label(@user, :post) # Outputs: <label for="user_post">Post<span class="mandatory-field">*</span></label>
|
53
|
+
# ..
|
54
|
+
# mandatory_label(@user, :name, 'User Name', {:mandatory_symbol => '^', :symbol_class => 'red'})
|
55
|
+
# # Outputs: <label for="user_name">User Name<span class="red">^</span></label>
|
56
|
+
#
|
57
|
+
# TODO: patch
|
58
|
+
# Instead of
|
59
|
+
# def mandatory_label(object, method, text = nil, options = {})
|
60
|
+
# text = (text.blank? ? nil : text.to_s) || object.class.human_attribute_name(method)
|
61
|
+
# use
|
62
|
+
# def mandatory_label(object_name, method, text = nil, options = {})
|
63
|
+
# if text.nil? or text.blank?
|
64
|
+
# text = Kernel::const_get(object_name.to_s.camelcase).human_attribute_name(method)
|
65
|
+
# end
|
66
|
+
def mandatory_label(object, method, text = nil, options = {})
|
67
|
+
# Here is patcha for rails 3.0.x
|
68
|
+
# object_name = ActionController::RecordIdentifier.singular_class_name(object)
|
69
|
+
object_name = ActiveModel::Naming.singular(object)
|
70
|
+
text = (text.blank? ? nil : text.to_s) || object.class.human_attribute_name(method)
|
71
|
+
mandatory_symbol = options.delete(:mandatory_symbol) || '*'
|
72
|
+
symbol_class = options.delete(:symbol_class) || 'mandatory-sign'
|
73
|
+
label_name = raw( text + "<span class=#{symbol_class}>#{mandatory_symbol}</span>")
|
74
|
+
label(object_name, method, label_name, options)
|
75
|
+
end
|
76
|
+
|
77
|
+
class CustomizedFormBuilder < ActionView::Helpers::FormBuilder
|
78
|
+
|
79
|
+
# Checks if there is an error for a field defined by given method
|
80
|
+
def is_error_message_on(method)
|
81
|
+
# DEPRECATION WARNING: Errors#on have been deprecated, use Errors#[] instead.
|
82
|
+
# if @object.nil? || !@object.errors.on(method)
|
83
|
+
if @object.nil? || !@object.errors[method] || (@object.errors[method].size == 0)
|
84
|
+
return false
|
85
|
+
end
|
86
|
+
true
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# Outputs div block with a hint message related to the field of object defined by method
|
91
|
+
# The hint message is printed if there's no error on the field. The message's text is either given
|
92
|
+
# by the 'hint' parameter or defined by 'activerecord.hints.models.#{object_name}.attributes.#{method}'
|
93
|
+
# key in localization files.
|
94
|
+
#
|
95
|
+
# Besides usuals options the following one defined:
|
96
|
+
# :hint_class - CSS class for the hint div
|
97
|
+
#
|
98
|
+
# Example:
|
99
|
+
# form_for :user do |f|
|
100
|
+
# ..
|
101
|
+
# f.hint_message_on :post, '(use only characters and digits)'
|
102
|
+
# # If there's no error on :post will output: <div class="form-hint">(use only characters and digits)</div>
|
103
|
+
#
|
104
|
+
def hint_message_on(method, hint = '', options = {})
|
105
|
+
@template.hint_message_on(@object, method, hint, options)
|
106
|
+
end
|
107
|
+
|
108
|
+
#
|
109
|
+
# Outputs label that appends mandatory symbol (e.g. '*') to the label's text
|
110
|
+
# Possible options are the same as for label method plus the following:
|
111
|
+
# :mandatory_symbol - symbol to applend, default is '*'
|
112
|
+
# :symbol_class - CSS class of the span element which surrounds this symbol, default is 'mandatory-field' class
|
113
|
+
#
|
114
|
+
# Example:
|
115
|
+
# form_for :user do |f|
|
116
|
+
# ..
|
117
|
+
# f.mandatory_label(:post) # Outputs: <label for="user_post">Post<span class="mandatory-field">*</span></label>
|
118
|
+
# ..
|
119
|
+
# f.mandatory_label(:name, 'User Name', {:mandatory_symbol => '^', :symbol_class => 'red'})
|
120
|
+
# # Outputs: <label for="user_name">User Name<span class="red">^</span></label>
|
121
|
+
#
|
122
|
+
def mandatory_label(method, text = nil, options = {})
|
123
|
+
@template.mandatory_label(@object, method, text, options)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# Customized version of form_for for our application
|
128
|
+
def form_for(record_or_name_or_array, *args, &proc)
|
129
|
+
options = args.extract_options!
|
130
|
+
super(record_or_name_or_array, *(args << options.merge(:builder => CustomizedFormBuilder)), &proc)
|
131
|
+
end
|
132
|
+
|
133
|
+
# Customized version of form_for for our application
|
134
|
+
def fields_for(record_or_name_or_array, *args, &proc)
|
135
|
+
options = args.extract_options!
|
136
|
+
super(record_or_name_or_array, *(args << options.merge(:builder => CustomizedFormBuilder)), &proc)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module AuxiliaryAddons
|
2
|
+
module HtmlHelper
|
3
|
+
# ::Rails.logger.error("...")
|
4
|
+
|
5
|
+
#
|
6
|
+
# Common HTML helpers
|
7
|
+
#
|
8
|
+
|
9
|
+
#
|
10
|
+
def hash_to_string(params = {})
|
11
|
+
result = ""
|
12
|
+
params.each do |key, value|
|
13
|
+
blank = result.blank?
|
14
|
+
result += (key.to_s + "=" + value.to_s) if blank
|
15
|
+
result += ("&" + key.to_s + "=" + value.to_s) if !blank
|
16
|
+
end
|
17
|
+
|
18
|
+
# TODO: replace whitespaced and etc
|
19
|
+
result
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
def newlines_to_htmlbrs(str)
|
24
|
+
return str if (str.nil? || str.blank?)
|
25
|
+
str.gsub!(/\n/, '</br>')
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
def erase_spaces(str)
|
30
|
+
return str if (str.nil? || str.blank?)
|
31
|
+
str.gsub!(/\s/, '')
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
def unique_id(key)
|
36
|
+
@unique_ids = Hash.new() if @unique_ids.nil?
|
37
|
+
@unique_ids[key] = 0 if @unique_ids[key].nil?
|
38
|
+
@unique_ids[key] += 1
|
39
|
+
last_id(key)
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
def last_id(key)
|
44
|
+
key + "." + @unique_ids[key].to_s
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module AuxiliaryAddons
|
2
|
+
module JscriptHelper
|
3
|
+
# ::Rails.logger.error("...")
|
4
|
+
|
5
|
+
#
|
6
|
+
# Common JScript helpers
|
7
|
+
#
|
8
|
+
|
9
|
+
#
|
10
|
+
def set_focus_on_load(id)
|
11
|
+
if ::AuxiliaryAddons.options[:use_prototype]
|
12
|
+
javascript_tag("Event.observe(window, 'load', $('#{id}').focus());")
|
13
|
+
end
|
14
|
+
if ::AuxiliaryAddons.options[:use_jquery]
|
15
|
+
if ::AuxiliaryAddons.options[:use_jquery_no_conflict]
|
16
|
+
javascript_tag("jQuery(document).ready(function(){jQuery('##{id}').focus();});")
|
17
|
+
else
|
18
|
+
javascript_tag("$(document).ready(function(){$('##{id}').focus();});")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module AuxiliaryAddons
|
2
|
+
module ListHelper
|
3
|
+
# ::Rails.logger.error("...")
|
4
|
+
|
5
|
+
#
|
6
|
+
# Common pagin and sorting helpers
|
7
|
+
#
|
8
|
+
|
9
|
+
def checkable_field_header
|
10
|
+
output = check_box_tag "ids[]", 0, false, {:id => "ids_", :onclick => "checkedAll('list',this.checked);"}
|
11
|
+
output
|
12
|
+
end
|
13
|
+
|
14
|
+
def sortable_field_header (header_name, field_name, form_name = nil)
|
15
|
+
url_params = Hash.new
|
16
|
+
if form_name.nil?
|
17
|
+
if @orderby == field_name
|
18
|
+
url_params[:orderby] = field_name + " desc"
|
19
|
+
else
|
20
|
+
url_params[:orderby] = field_name
|
21
|
+
end
|
22
|
+
else
|
23
|
+
if @orderby[form_name] == field_name
|
24
|
+
url_params["orderby[#{form_name}]"] = field_name + " desc"
|
25
|
+
else
|
26
|
+
url_params["orderby[#{form_name}]"] = field_name
|
27
|
+
end
|
28
|
+
@orderby.each do |form, sorter|
|
29
|
+
unless form.to_s == form_name.to_s
|
30
|
+
url_params["orderby[#{form}]"] = sorter
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# sort links should preserve GET parameters
|
36
|
+
if request.get?
|
37
|
+
request.params.each do |key, value|
|
38
|
+
next if key == 'controller'
|
39
|
+
next if key == 'action'
|
40
|
+
next if key == 'orderby'
|
41
|
+
next if key.starts_with?('orderby[')
|
42
|
+
url_params[key] = value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
url_params.delete("page")
|
46
|
+
|
47
|
+
output = link_to header_name, url_params
|
48
|
+
output += raw(" " + image_tag("arrows/arrow_down.png")) if @orderby == field_name
|
49
|
+
output += raw(" " + image_tag("arrows/arrow_up.png")) if @orderby == field_name + " desc"
|
50
|
+
output
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module AuxiliaryAddons
|
2
|
+
module RubyAddons
|
3
|
+
# ::Rails.logger.error("...")
|
4
|
+
|
5
|
+
# Check present of object
|
6
|
+
def is_object_here?(obj)
|
7
|
+
return false if obj.nil?
|
8
|
+
return true
|
9
|
+
end
|
10
|
+
|
11
|
+
# Check present not empty of string
|
12
|
+
def is_string_here?(str)
|
13
|
+
return false if str.nil?
|
14
|
+
return false if str.blank?
|
15
|
+
return true
|
16
|
+
end
|
17
|
+
|
18
|
+
# TODO: make paramters as hash articles
|
19
|
+
# Check present not empty of string
|
20
|
+
def is_array_items_here?(array1, array2, array3)
|
21
|
+
return true if array1.size() > 0
|
22
|
+
return true if array2.size() > 0
|
23
|
+
return true if array3.size() > 0
|
24
|
+
return false
|
25
|
+
end
|
26
|
+
|
27
|
+
# Convert params to arrary of ids
|
28
|
+
def cast_ids_to_i(params)
|
29
|
+
ids = []
|
30
|
+
ids << params["id"].to_i if !params["id"].nil?
|
31
|
+
if !params["ids"].nil?
|
32
|
+
params["ids"].each do |id|
|
33
|
+
next if id.to_i == 0 # Special case: all selected
|
34
|
+
ids << id.to_i
|
35
|
+
end
|
36
|
+
end
|
37
|
+
ids
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#
|
2
|
+
# See http://railscasts.com/episodes/193-tableless-model
|
3
|
+
#
|
4
|
+
class TablelessModel < ActiveRecord::Base
|
5
|
+
|
6
|
+
def self.columns() @columns ||= []; end
|
7
|
+
|
8
|
+
def self.column(name, sql_type = nil, default = nil, null = true)
|
9
|
+
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(attributes = nil)
|
13
|
+
super(attributes)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#
|
2
|
+
# See http://railscasts.com/episodes/219-active-model
|
3
|
+
#
|
4
|
+
class ValidateableModel
|
5
|
+
|
6
|
+
# Mixin validation
|
7
|
+
include ActiveModel::Validations
|
8
|
+
include ActiveModel::Conversion
|
9
|
+
extend ActiveModel::Naming
|
10
|
+
|
11
|
+
def self.attr_accessor(*vars)
|
12
|
+
@attributes ||= []
|
13
|
+
@attributes.concat( vars )
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.attributes
|
18
|
+
@attributes
|
19
|
+
end
|
20
|
+
|
21
|
+
# Initializer
|
22
|
+
def initialize(attributes={})
|
23
|
+
attributes && attributes.each do |name, value|
|
24
|
+
send("#{name}=", value) if respond_to? name.to_sym
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Overload persisted?
|
29
|
+
def persisted?
|
30
|
+
false
|
31
|
+
end
|
32
|
+
|
33
|
+
# Inspect
|
34
|
+
def self.inspect
|
35
|
+
"#<#{ self.to_s} #{ self.attributes.collect{ |e| ":#{ e }" }.join(', ') }>"
|
36
|
+
end
|
37
|
+
end
|
data/roadmap
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Introduction:
|
2
|
+
To see the latest list of the roadmap please visit the Roadmap page at www.majoron.com.
|
3
|
+
|
4
|
+
Legend:
|
5
|
+
Follow notation is used at change log, roadmap and known bugs. Each bug begins with a version,
|
6
|
+
then follow category of the bug inside {}. It can be bug report, feature request and etc.
|
7
|
+
Then follow component inside []. After follow bug number at bug tracking system between // signs.
|
8
|
+
And then follow a short description of the bug.
|
9
|
+
|
10
|
+
Example:
|
11
|
+
For example bug: "1.0 { Feature Request } [ AntHill ] / 380 / STLport support required" means
|
12
|
+
that bug was created for 1.0 version of the AntHill component, bug is feature request with
|
13
|
+
380 number at bug tracking system. And bug requires STLPort support implementation.
|
14
|
+
|
15
|
+
Version 0.5
|
16
|
+
-----------
|
17
|
+
0.5 { Feature Request } [ AuxiliaryAddons ] / X / Add tests
|
18
|
+
0.5 { Feature Request } [ AuxiliaryAddons ] / X / Add RailsTie
|
19
|
+
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__), '../lib')
|
3
|
+
|
4
|
+
ENV["RAILS_ENV"] = "test"
|
5
|
+
require 'rubygems'
|
6
|
+
require 'rspec'
|
7
|
+
require 'action_controller'
|
8
|
+
require 'auxiliary_addons'
|
9
|
+
|
10
|
+
module Rails
|
11
|
+
module VERSION
|
12
|
+
MAJOR = 3
|
13
|
+
end
|
14
|
+
end unless defined? Rails
|
15
|
+
|
16
|
+
# AuxiliaryAddons.root = './'
|
17
|
+
RAILS_ROOT = './' unless defined?(RAILS_ROOT)
|
18
|
+
RAILS_ENV = 'test' unless defined?(RAILS_ENV)
|
19
|
+
|
20
|
+
RSpec.configure do |config|
|
21
|
+
config.mock_with :rspec
|
22
|
+
end
|
23
|
+
|
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: auxiliary_addons
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.4
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Artem Rufanov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-16 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: AuxiliaryAddons is a gem that contains basic helpers.
|
15
|
+
email: developers@majoron.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- auxiliary_addons.gemspec
|
21
|
+
- changelog
|
22
|
+
- init.rb
|
23
|
+
- install.rb
|
24
|
+
- knownbugs
|
25
|
+
- lib/auxiliary_addons/error_helper.rb
|
26
|
+
- lib/auxiliary_addons/filter_utils.rb
|
27
|
+
- lib/auxiliary_addons/form_helper.rb
|
28
|
+
- lib/auxiliary_addons/html_helper.rb
|
29
|
+
- lib/auxiliary_addons/jscript_helper.rb
|
30
|
+
- lib/auxiliary_addons/list_helper.rb
|
31
|
+
- lib/auxiliary_addons/ruby_addons.rb
|
32
|
+
- lib/auxiliary_addons/tableless_model.rb
|
33
|
+
- lib/auxiliary_addons/validateable_model.rb
|
34
|
+
- lib/auxiliary_addons.rb
|
35
|
+
- MIT-LICENSE
|
36
|
+
- Rakefile
|
37
|
+
- README
|
38
|
+
- roadmap
|
39
|
+
- spec/lib/auxiliary_addons/error_helper_spec.rb
|
40
|
+
- spec/lib/auxiliary_addons/filter_utils_spec.rb
|
41
|
+
- spec/lib/auxiliary_addons/form_helper_spec.rb
|
42
|
+
- spec/lib/auxiliary_addons/html_helper_spec.rb
|
43
|
+
- spec/lib/auxiliary_addons/jscript_helper_spec.rb
|
44
|
+
- spec/lib/auxiliary_addons/list_helper_spec.rb
|
45
|
+
- spec/lib/auxiliary_addons/ruby_addons_spec.rb
|
46
|
+
- spec/lib/auxiliary_addons/tableless_model_spec.rb
|
47
|
+
- spec/lib/auxiliary_addons/validateable_model_spec.rb
|
48
|
+
- spec/lib/auxiliary_addons_spec.rb
|
49
|
+
- spec/spec.opts
|
50
|
+
- spec/spec_helper.rb
|
51
|
+
- tasks/auxiliary_addons_tasks.rake
|
52
|
+
- uninstall.rb
|
53
|
+
homepage: http://www.majoron.com/project/rbundle/auxiliary_addons
|
54
|
+
licenses: []
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
- doc
|
60
|
+
- examples
|
61
|
+
- lib
|
62
|
+
- test
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.8.7
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.8.10
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: AuxiliaryAddons is a gem that contains basic helpers.
|
81
|
+
test_files: []
|