class Object
Constants
- HASH
Public Instance Methods
additional_info(path, parms)
click to toggle source
# File lib/milkode/cdweb/app.rb, line 340 def additional_info(path, parms) suffix = File.extname path cadet = HASH[suffix] if (cadet) result = cadet.find do |v| Database.instance.record(path.gsub(/#{suffix}\Z/, v)) end if (result) path2 = path.gsub(/#{suffix}\Z/, result) " (<a href='#{url_for Mkurl.new(File.join('/home', path2), params).inherit_query_shead}'>#{result}</a>) " else '' end else '' end end
create_checkbox(name, value, label)
click to toggle source
# File lib/milkode/cdweb/app.rb, line 239 def create_checkbox(name, value, label) str = (value) ? 'checked' : '' "<label class='checkbox inline'><input type='checkbox' name='#{name}' value='on' #{str}/>#{label}</label>" end
create_favorite_list(package_list)
click to toggle source
# File lib/milkode/cdweb/app.rb, line 305 def create_favorite_list(package_list) return "" if package_list.favorite_list_size == 0 <<EOF <div class="favorite_list"> #{t(:favorite)}: #{package_list.favorite_list(params)} </div> </div> EOF end
create_select_package(path)
click to toggle source
# File lib/milkode/cdweb/app.rb, line 216 def create_select_package(path) value = package_name(path) value = '---' if value == "root" data = ['---'] + Database.instance.packages(nil) <<EOF <select name="package" id="package" onchange="select_package()"> #{data.map{|v| "<option value='#{v}' #{v == value ? 'selected' : ''}>#{v}</option>"}.join} </select> EOF end
create_select_package_home()
click to toggle source
# File lib/milkode/cdweb/app.rb, line 228 def create_select_package_home value = '---' data = ['---'] + Database.instance.packages(nil) <<EOF <select name="package" id="package_home" onchange="select_package_home()"> #{data.map{|v| "<option value='#{v}' #{v == value ? 'selected' : ''}>#{v}</option>"}.join} </select> EOF end
create_select_shead(value)
click to toggle source
# File lib/milkode/cdweb/app.rb, line 200 def create_select_shead(value) value ||= "package" data = [ ['all' , t(:all) ], ['package' , t(:package) ], ['directory', t(:directory)], ] <<EOF <select name="shead" id="shead"> #{data.map{|v| "<option value='#{v[0]}' #{v[0] == value ? 'selected' : ''}>#{v[1]}</option>"}.join} </select> EOF end
current_name(path)
click to toggle source
# File lib/milkode/cdweb/app.rb, line 364 def current_name(path) (path == "") ? 'root' : File.basename(path) end
escape_path(src)
click to toggle source
# File lib/milkode/cdweb/app.rb, line 187 def escape_path(src) escape_url(src).gsub("%2F", '/') end
favstar(path)
click to toggle source
# File lib/milkode/cdweb/app.rb, line 385 def favstar(path) pname = package_name(path) if pname != "root" classes = Database.instance.fav?(pname) ? "star favorited" : "star" "<a href=\"javascript:\" class=\"#{classes}\" milkode-package-name=\"#{pname}\">Favorite Me</a>" else "" end end
filelist_title(path)
click to toggle source
# File lib/milkode/cdweb/app.rb, line 372 def filelist_title(path) (path == "") ? "Package List" : path end
goto_github_project(path)
click to toggle source
# File lib/milkode/cdweb/app.rb, line 396 def goto_github_project(path) return "" if (path == "") paths = path.split('/') package = Database.instance.yaml_package(paths[0]) return "" unless package.options[:github] image_href = 'https://raw.github.com/github/media/master/octocats/blacktocat-16.png' url = "https://github.com/#{package.options[:github]}" if (paths.size == 1) "<a href='#{url}' target=\"_blank\"><img src='#{image_href}'></img></a>" else "<a href='#{url}/tree/master/#{paths[1..-1].join('/')}' target=\"_blank\"><img src='#{image_href}'></img></a>" end end
headicon(name, suburl)
click to toggle source
# File lib/milkode/cdweb/app.rb, line 317 def headicon(name, suburl) "<img alt='' style='vertical-align:center; border: 0px; margin: 0px;' src='#{suburl}/images/#{name}'>" end
link(query, text = nil)
click to toggle source
– utility –
# File lib/milkode/cdweb/app.rb, line 192 def link(query, text = nil) if text.nil? "<a href='#{'/home?query=' + escape_url(query)}'>#{query}</a>" else "<a href='#{'/home?query=' + escape_url(query)}'>#{text}</a>" end end
package_name(path)
click to toggle source
# File lib/milkode/cdweb/app.rb, line 360 def package_name(path) (path == "") ? 'root' : path.split('/')[0] end
package_path(homeurl, path)
click to toggle source
# File lib/milkode/cdweb/app.rb, line 60 def package_path(homeurl, path) homeurl + path.sub(homeurl, "").split('/')[0,2].join('/') end
path_title(path)
click to toggle source
# File lib/milkode/cdweb/app.rb, line 368 def path_title(path) (path == "") ? "root" : path end
search_summary_hook(path)
click to toggle source
.search-summary に追加情報を表示したい時はこの関数をオーバーライド
# File lib/milkode/cdweb/app.rb, line 414 def search_summary_hook(path) goto_github_project(path) end
t(*args)
click to toggle source
# File lib/milkode/cdweb/app.rb, line 439 def t(*args) update_locale I18n.t(*args, locale: @locale) end
topic_path(path, params)
click to toggle source
# File lib/milkode/cdweb/app.rb, line 321 def topic_path(path, params) href = '' path = File.join('home', path) path.split('/').map_with_index {|v, index| href += '/' + v "<a id='topic_#{index}' href='#{url_for Mkurl.new(href, params).inherit_query_shead}' onclick='topic_path(\"topic_#{index}\");'>#{v}</a>" }.join('/') end
ua_locale()
click to toggle source
for I18N
# File lib/milkode/cdweb/app.rb, line 419 def ua_locale # Pulls the browser's language @env["HTTP_ACCEPT_LANGUAGE"][0,2] end
update_locale()
click to toggle source
# File lib/milkode/cdweb/app.rb, line 424 def update_locale unless @locale begin # Support session @locale = params[:locale] || session[:locale] || ua_locale || 'en' session[:locale] = @locale rescue NameError # 'session' variable can't find during testing @locale = 'en' end # Reload with sinatra-reloader I18n.reload! if ENV['MILKODE_SINATRA_RELOADER'] end end
update_result_str(result, before)
click to toggle source
# File lib/milkode/cdweb/app.rb, line 376 def update_result_str(result, before) r = [] r << "#{result.package_count} packages" if result.package_count > 1 r << "#{result.file_count} records" r << "#{result.add_count} add" r << "#{result.update_count} update" "#{r.join(', ')} (#{Time.now - before} sec)" end