Module: Redmineup::Liquid::Filters::Base
- Includes:
- MoneyHelper
- Defined in:
- lib/redmineup/liquid/filters/base.rb
Instance Method Summary
collapse
-
#attachment(input, file_name) ⇒ Object
-
#call_method(input, method_name) ⇒ Object
-
#ceil(input) ⇒ Object
-
#concat(input, *args) ⇒ Object
-
#currency(input, currency_code = nil) ⇒ Object
-
#custom_field(input, field_name) ⇒ Object
-
#custom_fields(input) ⇒ Object
-
#dasherize(input) ⇒ Object
-
#date_range(input, distanse) ⇒ Object
example: today | date_range: ‘2015-12-12’ }.
-
#default(input, value) ⇒ Object
-
#encode(input) ⇒ Object
-
#floor(input) ⇒ Object
-
#ljust(input, integer, padstr = '') ⇒ Object
left justify and padd a string.
-
#md5(input) ⇒ Object
-
#modulo(input, operand) ⇒ Object
-
#multi_line(input) ⇒ Object
-
#plus_days(input, distanse) ⇒ Object
example: today | plus_days: 2 }.
-
#random(input) ⇒ Object
-
#rjust(input, integer, padstr = '') ⇒ Object
right justify and padd a string.
-
#round(input, n = 0) ⇒ Object
-
#shuffle(array) ⇒ Object
-
#textile(input) ⇒ Object
-
#textilize(input) ⇒ Object
-
#underscore(input) ⇒ Object
-
#utc(input) ⇒ Object
#all_currencies, #collection_for_currencies_select, #deal_currency_icon, #object_price, #price_to_currency, #prices_collection_by_currency
Instance Method Details
#attachment(input, file_name) ⇒ Object
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/redmineup/liquid/filters/base.rb', line 117
def attachment(input, file_name)
if input.respond_to?(:attachments)
if input.attachments.is_a?(Hash)
attachment = input.attachments[file_name]
else
attachment = input.attachments.detect{|a| a.file_name == file_name}
end
AttachmentDrop.new attachment if attachment
end
end
|
#call_method(input, method_name) ⇒ Object
94
95
96
97
98
|
# File 'lib/redmineup/liquid/filters/base.rb', line 94
def call_method(input, method_name)
if input.respond_to?(method_name)
input.method(method_name).call
end
end
|
#ceil(input) ⇒ Object
82
83
84
|
# File 'lib/redmineup/liquid/filters/base.rb', line 82
def ceil(input)
to_number(input).ceil.to_i
end
|
#concat(input, *args) ⇒ Object
132
133
134
135
136
|
# File 'lib/redmineup/liquid/filters/base.rb', line 132
def concat(input, *args)
result = input.to_s
args.flatten.each { |a| result << a.to_s }
result
end
|
#currency(input, currency_code = nil) ⇒ Object
90
91
92
|
# File 'lib/redmineup/liquid/filters/base.rb', line 90
def currency(input, currency_code = nil)
price_to_currency(input, currency_code || container_currency, :converted => false)
end
|
#custom_field(input, field_name) ⇒ Object
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/redmineup/liquid/filters/base.rb', line 100
def custom_field(input, field_name)
if input.respond_to?(:custom_field_values)
custom_value = input.custom_field_values.detect { |cfv| cfv.custom_field.name == field_name }
if custom_value
result = custom_value.custom_field.format.formatted_custom_value(nil, custom_value)
result = result.to_s if result.is_a?(CustomFieldEnumeration)
result
end
end
end
|
#custom_fields(input) ⇒ Object
111
112
113
114
115
|
# File 'lib/redmineup/liquid/filters/base.rb', line 111
def custom_fields(input)
if input.respond_to?(:custom_field_values)
input.custom_field_values.map { |cfv| cfv.custom_field.name }
end
end
|
#dasherize(input) ⇒ Object
25
26
27
|
# File 'lib/redmineup/liquid/filters/base.rb', line 25
def dasherize(input)
input.to_s.gsub(' ', '-').gsub('/', '-').dasherize
end
|
#date_range(input, distanse) ⇒ Object
example:
{{ today | date_range: '2015-12-12' }}
59
60
61
62
|
# File 'lib/redmineup/liquid/filters/base.rb', line 59
def date_range(input, distanse)
return '' if input.nil?
(input.to_date - distanse.to_date).to_i rescue 'Invalid date'
end
|
#default(input, value) ⇒ Object
17
18
19
|
# File 'lib/redmineup/liquid/filters/base.rb', line 17
def default(input, value)
input.blank? ? value : input
end
|
#encode(input) ⇒ Object
example:
{{ "http:://www.example.com?key=hello world" | encode }}
=> http%3A%3A%2F%2Fwww.example.com%3Fkey%3Dhello+world
45
46
47
|
# File 'lib/redmineup/liquid/filters/base.rb', line 45
def encode(input)
::Rack::Utils.escape(input)
end
|
#floor(input) ⇒ Object
86
87
88
|
# File 'lib/redmineup/liquid/filters/base.rb', line 86
def floor(input)
to_number(input).floor.to_i
end
|
#ljust(input, integer, padstr = '') ⇒ Object
left justify and padd a string
144
145
146
|
# File 'lib/redmineup/liquid/filters/base.rb', line 144
def ljust(input, integer, padstr = '')
input.to_s.ljust(integer, padstr)
end
|
#md5(input) ⇒ Object
37
38
39
|
# File 'lib/redmineup/liquid/filters/base.rb', line 37
def md5(input)
Digest::MD5.hexdigest(input) unless input.blank?
end
|
#modulo(input, operand) ⇒ Object
71
72
73
|
# File 'lib/redmineup/liquid/filters/base.rb', line 71
def modulo(input, operand)
apply_operation(input, operand, :%)
end
|
#multi_line(input) ⇒ Object
128
129
130
|
# File 'lib/redmineup/liquid/filters/base.rb', line 128
def multi_line(input)
input.to_s.gsub("\n", '<br/>').html_safe
end
|
#plus_days(input, distanse) ⇒ Object
example:
{{ today | plus_days: 2 }}
51
52
53
54
55
|
# File 'lib/redmineup/liquid/filters/base.rb', line 51
def plus_days(input, distanse)
return '' if input.nil?
days = distanse.to_i
input.to_date + days.days rescue 'Invalid date'
end
|
#random(input) ⇒ Object
33
34
35
|
# File 'lib/redmineup/liquid/filters/base.rb', line 33
def random(input)
rand(input.to_i)
end
|
#rjust(input, integer, padstr = '') ⇒ Object
right justify and padd a string
139
140
141
|
# File 'lib/redmineup/liquid/filters/base.rb', line 139
def rjust(input, integer, padstr = '')
input.to_s.rjust(integer, padstr)
end
|
#round(input, n = 0) ⇒ Object
75
76
77
78
79
80
|
# File 'lib/redmineup/liquid/filters/base.rb', line 75
def round(input, n = 0)
result = to_number(input).round(to_number(n))
result = result.to_f if result.is_a?(BigDecimal)
result = result.to_i if n == 0
result
end
|
#shuffle(array) ⇒ Object
29
30
31
|
# File 'lib/redmineup/liquid/filters/base.rb', line 29
def shuffle(array)
array.to_a.shuffle
end
|
#textile(input) ⇒ Object
148
149
150
|
# File 'lib/redmineup/liquid/filters/base.rb', line 148
def textile(input)
::RedCloth3.new(input).to_html
end
|
#textilize(input) ⇒ Object
13
14
15
|
# File 'lib/redmineup/liquid/filters/base.rb', line 13
def textilize(input)
RedCloth3.new(input).to_html
end
|
#underscore(input) ⇒ Object
21
22
23
|
# File 'lib/redmineup/liquid/filters/base.rb', line 21
def underscore(input)
input.to_s.gsub(' ', '_').gsub('/', '_').underscore
end
|
#utc(input) ⇒ Object
66
67
68
69
|
# File 'lib/redmineup/liquid/filters/base.rb', line 66
def utc(input)
return '' if input.nil?
input.to_time.utc rescue 'Invalid date'
end
|