Module: Narou::ServerHelpers

Defined in:
lib/web/appserver.rb

Instance Method Summary collapse

Instance Method Details

#build_ruby_versionObject

Rubyバージョンを構築



43
44
45
46
47
48
49
50
# File 'lib/web/appserver.rb', line 43

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 という文字列に変換



81
82
83
84
85
86
87
88
89
90
# File 'lib/web/appserver.rb', line 81

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

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



67
68
69
70
71
72
73
74
75
76
# File 'lib/web/appserver.rb', line 67

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で装飾する(除外タグ指定用)



34
35
36
37
38
# File 'lib/web/appserver.rb', line 34

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で装飾する



25
26
27
28
29
# File 'lib/web/appserver.rb', line 25

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エスケープヘルパー



95
96
97
# File 'lib/web/appserver.rb', line 95

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

#notepad_text_pathObject



114
115
116
# File 'lib/web/appserver.rb', line 114

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

#select_valid_novel_ids(ids) ⇒ Object

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



56
57
58
59
60
61
62
# File 'lib/web/appserver.rb', line 56

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

#value_to_msg(value) ⇒ Object

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



103
104
105
106
107
108
109
110
111
112
# File 'lib/web/appserver.rb', line 103

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