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 =

LOCALIZE first item

{ 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.full_comment if t.full_comment
  task name, *t.arg_names do |_, args|
    # values_at is broken on Rake::TaskArguments
    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

#castObject



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_syntaxObject



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

Returns:

  • (Boolean)


1
2
3
# File 'mod/format/set/type/toggle.rb', line 1

def checked?
  content == "1"
end

#clean_html?Boolean

Returns:

  • (Boolean)


1
2
3
# File 'mod/format/set/type/html.rb', line 1

def clean_html?
  false
end

#diff_argsObject



5
6
7
# File 'mod/format/set/type/html.rb', line 5

def diff_args
  { diff_format: :raw }
end

#event: validate_jsonObject



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_numberObject



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

#format(opts = {}) ⇒ Object



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_valuesObject



21
22
23
# File 'mod/format/set/type/json.rb', line 21

def item_values
  parse_content.values
end


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_contentObject



13
14
15
# File 'mod/format/set/type/json.rb', line 13

def parse_content
  content.blank? ? "" : JSON.parse(content)
end

#pod_contentObject



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

#pod_nameObject



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

#pod_typeObject



19
20
21
# File 'mod/format/set/all/data.rb', line 19

def pod_type
  type_name.codename_or_string
end

#view: coreObject



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