Module: Narou::ServerHelpers

Defined in:
lib/web/appserver.rb

Instance Method Summary collapse

Instance Method Details

#build_ruby_versionObject

Rubyバージョンを構築



46
47
48
49
50
51
52
53
# File 'lib/web/appserver.rb', line 46

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



84
85
86
87
88
89
90
91
92
93
# File 'lib/web/appserver.rb', line 84

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

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



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

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



37
38
39
40
41
# File 'lib/web/appserver.rb', line 37

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



28
29
30
31
32
# File 'lib/web/appserver.rb', line 28

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



98
99
100
# File 'lib/web/appserver.rb', line 98

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

#notepad_text_pathObject



117
118
119
# File 'lib/web/appserver.rb', line 117

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

#query_to_boolean(value, default: false) ⇒ Object



121
122
123
124
125
126
127
128
129
130
# File 'lib/web/appserver.rb', line 121

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 を返す



59
60
61
62
63
64
65
# File 'lib/web/appserver.rb', line 59

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

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



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

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