Module: EditorHelper

Defined in:
app/helpers/editor_helper.rb

Instance Method Summary collapse

Instance Method Details

#toolbox_character_field(name = 'VAR') ⇒ String

ツールボックスのブロックに対して、キャラクターの入力フィールドの値を設定する

Parameters:

  • name (String) (defaults to: 'VAR')

    名前

Returns:

  • (String)

    XML



7
8
9
# File 'app/helpers/editor_helper.rb', line 7

def toolbox_character_field(name = 'VAR')
  %(<field name="#{h name}">char1</field>).html_safe
end

#toolbox_key_field(name = 'KEY', value = 'K_SPACE') ⇒ String

ツールボックスのブロックに対して、キーの入力フィールドの値を設定する

Parameters:

  • name (String) (defaults to: 'KEY')

    名前

  • value (String) (defaults to: 'K_SPACE')

    キーの名前。K_SPACE、K_Aなど

Returns:

  • (String)

    XML



16
17
18
# File 'app/helpers/editor_helper.rb', line 16

def toolbox_key_field(name = 'KEY', value = 'K_SPACE')
  %(<field name="#{h name}">#{h value}</field>).html_safe
end

#toolbox_number_value(name, value = 0) ⇒ String

ツールボックスのブロックに対して、数値型の入力のブロックを設定する

Parameters:

  • name (String)

    入力値の名前

  • value (Numeric) (defaults to: 0)

    数値

Returns:

  • (String)

    XML



48
49
50
51
52
53
54
55
56
57
# File 'app/helpers/editor_helper.rb', line 48

def toolbox_number_value(name, value = 0)
  value = value.to_i unless value.is_a?(Numeric)
  "    <value name=\"\#{h name}\">\n      <block type=\"math_number\">\n        <field name=\"NUM\">\#{h value}</field>\n      </block>\n    </value>\n  XML\nend\n".strip_heredoc.html_safe

#toolbox_pin_field(value, name = 'PIN') ⇒ String

ツールボックスのブロックに対して、PINの入力フィールドの値を設定する

Parameters:

  • value (String)

    ピン

  • name (String) (defaults to: 'PIN')

    名前

Returns:

  • (String)

    XML



39
40
41
# File 'app/helpers/editor_helper.rb', line 39

def toolbox_pin_field(value, name = 'PIN')
  %(<field name="#{h name}">#{h value}</field>).html_safe
end

#toolbox_pod_field(name = 'POD', value = :down) ⇒ String

push or down field for Toolbox

Parameters:

  • name (String) (defaults to: 'POD')

    field name

  • value (String) (defaults to: :down)

    :push or :down

Returns:

  • (String)

    XML



25
26
27
28
29
30
31
32
# File 'app/helpers/editor_helper.rb', line 25

def toolbox_pod_field(name = 'POD', value = :down)
  if value == :down
    pod = 'down'
  else
    pod = 'push'
  end
  %(<field name="#{h name}">#{pod}</field>).html_safe
end

#toolbox_t(*args) ⇒ Object Also known as: tt

I18n.t wrapper for Toolbox that’s defualt scope is ‘editor.toolbox’.



76
77
78
79
80
81
82
# File 'app/helpers/editor_helper.rb', line 76

def toolbox_t(*args)
  if args.length == 1 && args.first[0] == '.'
    t(args.first[1..-1], scope: 'editor.toolbox')
  else
    t(*args)
  end
end

#toolbox_text_value(name = 'TEXT', value = '') ⇒ String

ツールボックスのブロックに対して、テキスト型の入力のブロックを設定する

Parameters:

  • name (String) (defaults to: 'TEXT')

    入力値の名前

  • value (String) (defaults to: '')

    文字列

Returns:

  • (String)

    XML



64
65
66
67
68
69
70
71
72
# File 'app/helpers/editor_helper.rb', line 64

def toolbox_text_value(name = 'TEXT', value = '')
  "    <value name=\"\#{h name}\">\n      <block type=\"text\">\n        <field name=\"TEXT\">\#{h value}</field>\n      </block>\n    </value>\n  XML\nend\n".strip_heredoc.html_safe