Module: Gonzui::HTMLMaker

Included in:
GonzuiAbstractServlet
Defined in:
lib/gonzui/webapp/servlet.rb

Instance Method Summary collapse

Instance Method Details

#make_content_script_typeObject



33
34
35
36
37
38
39
40
# File 'lib/gonzui/webapp/servlet.rb', line 33

def make_content_script_type
  [:meta, 
    {
      "http-equiv" => "content-script-type", 
      :content => "text/javascript"
    }
  ]
end

#make_cssObject



42
43
44
45
46
47
48
49
50
# File 'lib/gonzui/webapp/servlet.rb', line 42

def make_css
  [:link, 
    { 
      :rel => "stylesheet", 
      :href => make_doc_uri("gonzui.css"),
      :media => "all", :type => "text/css" 
    }
  ]
end


52
53
54
55
56
57
58
59
60
# File 'lib/gonzui/webapp/servlet.rb', line 52

def make_footer
  [:div, {:class => "footer"}, 
    [:a, {:href => make_markup_uri}, _("List of all packages")],
    " - ",
    [:a, {:href => make_stat_uri}, _("Statistics")],
    " - ",
    [:a, {:href => Gonzui::GONZUI_URI}, _("About gonzui")],
  ]
end

#make_format_selectObject



138
139
140
141
142
143
# File 'lib/gonzui/webapp/servlet.rb', line 138

def make_format_select
  make_property_select(get_short_name(:format),
                       @search_query.format,
                       :each_format, 
                       "binary")
end

#make_h1Object



81
82
83
# File 'lib/gonzui/webapp/servlet.rb', line 81

def make_h1
  [:h1, [:a, {:href => make_top_uri}, @config.site_title]]
end

#make_htmlObject



62
63
64
# File 'lib/gonzui/webapp/servlet.rb', line 62

def make_html
  [:html, {:xmlns => "http://www.w3.org/1999/xhtml"}]
end

#make_license_selectObject



145
146
147
148
149
# File 'lib/gonzui/webapp/servlet.rb', line 145

def make_license_select
  make_property_select(get_short_name(:license),
                       @search_query.license,
                       :each_license)
end

#make_metaObject



65
66
67
# File 'lib/gonzui/webapp/servlet.rb', line 65

def make_meta
  [:meta, {:name => "robots", :content => "noarchive"}]
end

#make_meta_and_cssObject



69
70
71
# File 'lib/gonzui/webapp/servlet.rb', line 69

def make_meta_and_css
  [ make_meta, make_content_script_type, make_css ]
end

#make_navi(nitems, from, max_per_page, max_pages = nil) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/gonzui/webapp/servlet.rb', line 85

def make_navi(nitems, from, max_per_page, max_pages = nil)
  return "" if nitems <= max_per_page
  navi = [:div, {:class => "navi"}]
  if from > 0
    f = [from - max_per_page, 0].max
    uri = do_make_navi(f)
    navi.push([:a, {:href => uri}, _("prev")], " ")
  end

  if nitems > max_per_page
    (0..((nitems - 1) / max_per_page)).each {|i|
      break if max_pages and i >= max_pages 
      f = i * max_per_page
      if f == from
        navi.push((i + 1).to_s + " ")
      else
        uri = do_make_navi(f)
        navi.push([:a, {:href => uri}, (i + 1).to_s], " ")
      end
    }
  end

  if from + max_per_page < nitems
    f = [from + max_per_page, 0].max
    uri = do_make_navi(f)
    navi.push([:a, {:href => uri}, _("next")])
  end
  return navi
end

#make_property_select(short_name, current_value, each, *excludes) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/gonzui/webapp/servlet.rb', line 120

def make_property_select(short_name, current_value, each, *excludes)
  select = [:select, {:name => short_name}]
  o = [:option, {:type => "radio", :name => short_name, :value => "all"}, 
    _("All")]
  select.push(o)
  @dbm.send(each) {|id, abbrev, name|
    next if excludes.include?(abbrev)
    o = [:option, 
      {:type => "radio", :name => short_name, :value => abbrev},
      _(name)]
    if abbrev == current_value
      o[1][:selected] = "selected"
    end
    select.push(o)
  }
  return select
end

#make_scriptObject



115
116
117
118
# File 'lib/gonzui/webapp/servlet.rb', line 115

def make_script
  [:script, {:type => "text/javascript", 
      :src => make_doc_uri("gonzui.js")}, ""]
end

#make_search_form(options = {}) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/gonzui/webapp/servlet.rb', line 151

def make_search_form(options = {})
  query = @search_query.string
  form = [:form,  {:method => "get", :action => 
      make_uri_general(SearchServlet)}]
  iquery  = [:input, {:type => "text", :size => 50, 
      :name => get_short_name(:basic_query), 
      :value => query}]
  isubmit = [:input, {:type => "submit", :value => _("Search")}]
  p = [:p]
  p.push(iquery)
  if options[:central]
    p.push([:br]) 
  else
    p.push(" ")
  end

  p.push(isubmit)
  select = make_format_select
  p.push([:br])
  p.push(_("Format: "))
  p.push(select)
  p.push(make_spacer)
  uri = make_advanced_search_uri(@search_query)
  p.push([:a, {:href => uri, :onclick => "passQuery(this)"},
           _("Advanced Search")])
  p.push([:script, "initFocus();"])
  form.push(p)
  return form
end

#make_spacerObject



181
182
183
# File 'lib/gonzui/webapp/servlet.rb', line 181

def make_spacer
  [:span, {:class => "spacer" }, " "]
end

#make_status_line(status_title, *options) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/gonzui/webapp/servlet.rb', line 185

def make_status_line(status_title, *options)
  status_line = [:table, {:class => "status"}]
  items = do_make_status_line(*options)
  right = (items.pop or "")

  tds = []
  tds.push([:td, {:class => "left"}, status_title])
  items.each {|item|
    tds.push([:td, {:class => "center"}, item])
  }
  unless right.empty?
    r = [:td, {:class => "right"}, right]
    r.push(" (", [:strong, sprintf("%.2f", Time.now - @start_time)],
           _(" seconds)"))
    tds.push(r)
  end
  status_line.push([:tr, *tds])
  return status_line
end

#make_title(sub_title = nil) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/gonzui/webapp/servlet.rb', line 73

def make_title(sub_title = nil)
  if sub_title
    return [:title, sprintf("%s: %s", @config.site_title, sub_title)]
  else
    return [:title, @config.site_title]
  end
end