Top Level Namespace
Defined Under Namespace
Modules: Ansi2html, Cardio, CarrierWave, Decko, Rails
Classes: Card, CardController, Cardname, Object, StandardError
Constant Summary
collapse
- RESOURCE_TYPE_REGEXP =
/^([a-zA-Z][\-+.a-zA-Z\d]*):/
- TOGGLE_MAP =
{ close: %w[open open], open: %w[close closed] }.freeze
Instance Method Summary
collapse
Instance Method Details
#alias_task(name, old_name) ⇒ Object
1
2
3
4
5
6
7
8
9
|
# File 'decko/lib/rake_tasks/alias.rb', line 1
def alias_task name, old_name
t = Rake::Task[old_name]
desc t. if t.
task name, *t.arg_names do |_, args|
args = t.arg_names.map { |a| args[a] }
t.invoke(args)
end
end
|
#append_to_namespace(namespace, part) ⇒ Object
11
12
13
|
# File 'decko/lib/rake_tasks/alias.rb', line 11
def append_to_namespace namespace, part
[namespace, part].compact.join(":")
end
|
1
2
3
|
# File 'mod/format/set/all/data.rb', line 1
def cast
real? ? { id: id } : { name: name, type_id: type_id, content: db_content }
end
|
#check_json_syntax ⇒ Object
7
8
9
10
11
|
# File 'mod/format/set/type/json.rb', line 7
def check_json_syntax
parse_content
rescue JSON::ParserError => e
errors.add t(:format_invalid_json), e.message.sub(/^\d+: /, "").to_s
end
|
#checked? ⇒ Boolean
1
2
3
|
# File 'mod/format/set/type/toggle.rb', line 1
def checked?
content == "1"
end
|
#clean_html? ⇒ Boolean
1
2
3
|
# File 'mod/format/set/type/html.rb', line 1
def clean_html?
false
end
|
#diff_args ⇒ Object
5
6
7
|
# File 'mod/format/set/type/html.rb', line 5
def diff_args
{ diff_format: :raw }
end
|
#event: validate_json ⇒ Object
3
4
5
|
# File 'mod/format/set/type/json.rb', line 3
event :validate_json, :validate, on: :save, changed: :content do
check_json_syntax if content.present?
end
|
#event: validate_number ⇒ Object
7
8
9
|
# File 'mod/format/set/type/number.rb', line 7
event :validate_number, :validate, on: :save do
errors.add :content, t(:format_not_numeric, content: content) unless content.number?
end
|
1
2
3
4
|
# File 'mod/format/set/all/base.rb', line 1
def format opts={}
opts = { format: opts.to_sym } if [Symbol, String].member? opts.class
Card::Format.new self, opts
end
|
#item_names(_args = {}) ⇒ Object
17
18
19
|
# File 'mod/format/set/type/json.rb', line 17
def item_names _args={}
parse_content.keys.map(&:to_name)
end
|
#item_value(name) ⇒ Object
25
26
27
|
# File 'mod/format/set/type/json.rb', line 25
def item_value name
parse_content[name]
end
|
#item_values ⇒ Object
21
22
23
|
# File 'mod/format/set/type/json.rb', line 21
def item_values
parse_content.values
end
|
#link_task(task, from: nil, to: nil, namespace: nil) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'decko/lib/rake_tasks/alias.rb', line 15
def link_task task, from: nil, to: nil, namespace: nil
case task
when Hash
task.each do |key, val|
link_task val, from: from, to: to,
namespace: append_to_namespace(namespace, key)
end
when Array
task.each do |t|
link_task t, from: from, to: to, namespace: namespace
end
else
shared_part = append_to_namespace namespace, task
alias_task "#{from}:#{shared_part}", "#{to}:#{shared_part}"
end
end
|
#parse_content ⇒ Object
13
14
15
|
# File 'mod/format/set/type/json.rb', line 13
def parse_content
content.blank? ? "" : JSON.parse(content)
end
|
#pod_content ⇒ Object
27
28
29
|
# File 'mod/format/set/all/data.rb', line 27
def pod_content
structure ? nil : db_content
end
|
#pod_fields(marks) ⇒ Object
13
14
15
16
17
|
# File 'mod/format/set/all/data.rb', line 13
def pod_fields marks
marks.each_with_object({}) do |mark, hash|
hash[mark] = [name, mark].card&.pod_content
end.compact_blank
end
|
#pod_hash(field_tags: []) ⇒ Object
5
6
7
8
9
10
11
|
# File 'mod/format/set/all/data.rb', line 5
def pod_hash field_tags: []
{ name: pod_name,
type: pod_type,
codename: codename,
content: pod_content,
fields: pod_fields(field_tags) }.compact_blank
end
|
23
24
25
|
# File 'mod/format/set/all/data.rb', line 23
def pod_name
simple? ? name.s : name.part_names.map(&:codename_or_string)
end
|
19
20
21
|
# File 'mod/format/set/all/data.rb', line 19
def pod_type
type_name.codename_or_string
end
|
#view: core ⇒ Object
5
6
7
8
9
10
11
12
|
# File 'mod/format/set/type/toggle.rb', line 5
view :core do
case card.content.to_i
when 1 then t(:format_toggle_yes)
when 0 then t(:format_toggle_no)
else
"?"
end
end
|