# -*- coding: utf-8 -*- # # @file # @brief HTMLの描画ルーチン # @author ongaeshi # @date 2010/10/17 require 'rubygems' require 'rack' require File.join(File.dirname(__FILE__), 'grep') module Grenweb class HTMLRendeler include Rack::Utils def initialize(script_name) @script_name = Pathname(script_name) end def header(title, header1) < #{title}

gren-icon #{header1}

EOS end def footer < EOS end def header_home(title, header1, version) < #{title}

gren-icon #{header1} #{version}

EOS end def footer_home(package, files) <
EOS end def result_record(record, patterns, nth=1) if (patterns.size > 0) <#{record.shortpath}
#{result_record_match_line(record, patterns, nth)}
      
EOS else <#{record.shortpath} EOS end end def result_record_match_line(record, patterns, nth) str = "" grep = Grep.new(record.content) lines = grep.match_lines_or(patterns) unless (lines.empty?) index = lines[0].index (index - nth..index + nth).each do |i| if (0 <= i && i < grep.content.size) match_datas = (i == index) ? lines[0].match_datas : [] str << line(i + 1, grep.content[i], match_datas) + "\n" end end end str end def record_content(record) < #{record_content_line(record)} EOS end def record_content_line(record) str = "" grep = Grep.new(record.content) grep.content.each_with_index do |l, index| str << line(index + 1, l, []) + "\n" end str end def line(lineno, line, match_datas) sprintf("%5d: %s", lineno, match_strong(Rack::Utils::escape_html(line), match_datas)) end def match_strong(line, match_datas) match_datas.each do |m| line = line.split(m[0]).join('' + m[0] + '') unless (m.nil?) end line end def pagination_link(page, label) href = "?page=#{page}" pagination_span("#{label}") end def pagination_span(content) "#{content}\n" end def empty_summary() <

gren web検索

EOS end def search_summary(keyword, total_records, range, elapsed) < #{keyword}の検索結果: #{total_records}件中 #{range.first} - #{range.last}件(#{elapsed}秒)
EOS end def view_summary(path, elapsed) < #{path}(#{elapsed}秒) EOS end def search_box(text = "") <

EOS end def sample_code <
  1. キーワードで検索
    #{link('def open')}
  2. 1フレーズとして検索
    #{link('"def open"')}
  3. パッケージ名で絞り込み
    #{link('def open p:gren')}
  4. ファイル名や拡張子で絞り込み
    #{link('def open f:test s:rb')}
  5. 組み合わせ
    #{link('p:gren p:tidtools s:rb f:test assert f:cli')}
EOS end def link(keyword) "#{keyword}" end def fullpath(path) unless (path == '') (@script_name + path).to_s else @script_name.to_s end end end end