Module: Narou::ServerHelpers

Defined in:
lib/web/server_helpers.rb

Overview

rubocop:disable Style/ClassAndModuleChildren

Constant Summary collapse

RELOAD_TIMING_DEFAULT =
"every"

Instance Method Summary collapse

Instance Method Details

#build_ruby_versionObject

Rubyバージョンを構築



32
33
34
35
36
37
38
39
# File 'lib/web/server_helpers.rb', line 32

def build_ruby_version
  begin
    `"#{RbConfig.ruby}" -v`.strip
  rescue
    config = RbConfig::CONFIG
    "ruby #{RUBY_VERSION}p#{config["PATCHLEVEL"]} [#{RUBY_PLATFORM}]"
  end
end

#convert_boolean_to_on_off(bool) ⇒ Object

nil true false を nil on off という文字列に変換



70
71
72
73
74
75
76
77
78
79
# File 'lib/web/server_helpers.rb', line 70

def convert_boolean_to_on_off(bool)
  case bool
  when TrueClass
    "on"
  when FalseClass
    "off"
  else
    "nil"
  end
end

#convert_on_off_to_boolean(str) ⇒ Object

フォーム情報の真偽値データを実際のデータに変換



56
57
58
59
60
61
62
63
64
65
# File 'lib/web/server_helpers.rb', line 56

def convert_on_off_to_boolean(str)
  case str
  when "on"
    true
  when "off"
    false
  else
    nil
  end
end

#decorate_exclusion_tags(tags) ⇒ Object

タグをHTMLで装飾する(除外タグ指定用)



23
24
25
26
27
# File 'lib/web/server_helpers.rb', line 23

def decorate_exclusion_tags(tags)
  tags.sort.map do |tag|
    %!<span class="tag label label-#{Command::Tag.get_color(tag)}" data-exclusion-tag="#{escape_html(tag)}">^tag:#{escape_html(tag)}</span>!
  end.join(" ")
end

#decorate_tags(tags) ⇒ Object

タグをHTMLで装飾する



14
15
16
17
18
# File 'lib/web/server_helpers.rb', line 14

def decorate_tags(tags)
  tags.sort.map do |tag|
    %!<span class="tag label label-#{Command::Tag.get_color(tag)}" data-tag="#{escape_html(tag)}">#{escape_html(tag)}</span>!
  end.join(" ")
end

#h(text) ⇒ Object

HTMLエスケープヘルパー



84
85
86
# File 'lib/web/server_helpers.rb', line 84

def h(text)
  Rack::Utils.escape_html(text)
end

#notepad_text_pathObject



103
104
105
# File 'lib/web/server_helpers.rb', line 103

def notepad_text_path
  File.join(Narou.local_setting_dir, "notepad.txt")
end

#query_to_boolean(value, default: false) ⇒ Object



107
108
109
110
111
112
113
114
115
116
# File 'lib/web/server_helpers.rb', line 107

def query_to_boolean(value, default: false)
  case value
  when "1", 1, "true", true
    true
  when "0", 0, "false", false
    false
  else
    default
  end
end

#select_valid_novel_ids(ids) ⇒ Object

有効な novel ID だけの配列を生成する ID が指定されなかったか、1件も存在しない場合は nil を返す



45
46
47
48
49
50
51
# File 'lib/web/server_helpers.rb', line 45

def select_valid_novel_ids(ids)
  return nil unless ids.kind_of?(Array)
  result = ids.select do |id|
    id =~ /^\d+$/
  end
  result.empty? ? nil : result
end

#table_reload_timingObject



118
119
120
# File 'lib/web/server_helpers.rb', line 118

def table_reload_timing
  Inventory.load("local_setting")["webui.table.reload-timing"] || RELOAD_TIMING_DEFAULT
end

#value_to_msg(value) ⇒ Object

与えられたデータが真偽値だった場合、設定画面用に「はい」「いいえ」に変換する 真偽値ではなかった場合、そのまま返す



92
93
94
95
96
97
98
99
100
101
# File 'lib/web/server_helpers.rb', line 92

def value_to_msg(value)
  case value
  when TrueClass
    "はい"
  when FalseClass
    "いいえ"
  else
    value
  end
end