Class: View

Inherits:
Object
  • Object
show all
Defined in:
lib/view.rb

Overview

Copyright © 2011 Cornelius Schumacher <[email protected]>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(handler) ⇒ View

Returns a new instance of View.



22
23
24
# File 'lib/view.rb', line 22

def initialize handler
  @manifest_handler = handler
end

Instance Attribute Details

#enable_disqusObject

Returns the value of attribute enable_disqus.



19
20
21
# File 'lib/view.rb', line 19

def enable_disqus
  @enable_disqus
end

#enable_searchObject

Returns the value of attribute enable_search.



19
20
21
# File 'lib/view.rb', line 19

def enable_search
  @enable_search
end

#group_nameObject

Returns the value of attribute group_name.



19
20
21
# File 'lib/view.rb', line 19

def group_name
  @group_name
end

#libraryObject

Returns the value of attribute library.



19
20
21
# File 'lib/view.rb', line 19

def library
  @library
end

#manifestObject

Returns the value of attribute manifest.



19
20
21
# File 'lib/view.rb', line 19

def manifest
  @manifest
end

#rootObject (readonly)

Returns the value of attribute root.



20
21
22
# File 'lib/view.rb', line 20

def root
  @root
end

Instance Method Details

#commercial_librariesObject



216
217
218
# File 'lib/view.rb', line 216

def commercial_libraries
  @manifest_handler.commercial_libraries
end

#create(output_dir) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/view.rb', line 26

def create output_dir
  puts "Creating web site in '#{output_dir}' from '#{@manifest_handler.settings.manifest_path}'"
  
  assert_dir output_dir

  system "cp #{view_dir}/favicon.ico #{output_dir}"
  
  assert_dir "#{output_dir}/public"
  system "cp #{view_dir}/public/* #{output_dir}/public/"
  
  assert_dir "#{output_dir}/schema"
  system "cp #{schema_dir}/* #{output_dir}/schema"

  create_inqlude_all(output_dir)


  @root = ""

  render_template "index", output_dir
  render_template "development", output_dir
  render_template "unreleased", output_dir
  render_template "commercial", output_dir
  render_template "all", output_dir
  render_template "about", output_dir
  render_template "get", output_dir
  render_template "contribute", output_dir
  render_template "search", output_dir
  

  groups_path = "#{output_dir}/groups/"
  assert_dir groups_path
  
  @root = "../"
  
  @group_name = "kde-frameworks"
  file_name = "groups/kde-frameworks"
  render_template "group", output_dir, file_name
  

  library_path = "#{output_dir}/libraries/"
  assert_dir library_path

  @root = "../"

  @manifest_handler.libraries.each do |library|
    @library = library
    @manifest = library.latest_manifest
    file_name = "libraries/" + library.name
    render_template "library", output_dir, file_name
  end
end

#create_inqlude_all(output_dir) ⇒ Object



78
79
80
81
82
# File 'lib/view.rb', line 78

def create_inqlude_all(output_dir)
  File.open(File.join(output_dir, "inqlude-all.json"), "w") do |f|
    f.write(@manifest_handler.generate_inqlude_all)
  end
end

#custom_urlsObject



197
198
199
200
201
202
203
204
205
206
# File 'lib/view.rb', line 197

def custom_urls
  out = ""
  urls = @manifest.urls.custom
  if urls && !urls.empty?
    urls.each do |text,url|
      out += "<li><a href=\"#{url}\">#{text}</a></li>"
    end
  end
  out
end

#disqus_enabled?Boolean

Returns:

  • (Boolean)


231
232
233
# File 'lib/view.rb', line 231

def disqus_enabled?
  @enable_disqus
end

#editor_urlObject



247
248
249
250
251
252
# File 'lib/view.rb', line 247

def editor_url
  url = "https://github.com/cornelius/inqlude-data/blob/master/"
  url += @manifest.name
  url += "/#{@manifest.name}.#{@manifest.release_date}.manifest"
  url
end

#groupObject



227
228
229
# File 'lib/view.rb', line 227

def group
  @manifest_handler.group(@group_name)
end

#group_titleObject



220
221
222
223
224
225
# File 'lib/view.rb', line 220

def group_title
  if @group_name == "kde-frameworks"
    return "KDE Frameworks"
  end
  ""
end

#libraries(maturity = nil) ⇒ Object



208
209
210
# File 'lib/view.rb', line 208

def libraries maturity = nil
  @manifest_handler.libraries(maturity)
end


119
120
121
# File 'lib/view.rb', line 119

def link url
  "<a href=\"#{url}\" target=\"_blank\">#{url}</a>"
end


186
187
188
189
190
191
192
193
194
195
# File 'lib/view.rb', line 186

def link_item key, label
  if m.urls.send(key)
    out = "<li><a href=\""
    out += m.urls.send(key)
    out += "\">#{label}</a></li>"
    return out
  else
    return ""
  end
end


123
124
125
126
127
128
# File 'lib/view.rb', line 123

def link_to title, url
  if url !~ /^mailto:/ && url !~ /^http:/ && url !~ /^https:/ && url !~ /^ftp:/
    url = "#{@root}#{url}.html"
  end
  "<a href=\"#{url}\">#{title}</a>"
end


115
116
117
# File 'lib/view.rb', line 115

def link_to_manifest name
  "<a href=\"#{@root}libraries/#{name}.html\">#{name}</a>"
end

#list_attribute(attribute) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/view.rb', line 130

def list_attribute attribute
  attr = @manifest.send(attribute)
  return "" if !attr || attr.size == 0

  # We assume attribute is plural formed by adding an 's'

  label = attribute.capitalize

  entries = Array.new
  attr.each do |a|
    entries.push markup_email( a )
  end

  if attr.size > 1
    return list_attribute_content label, entries.join(", ")
  else
    return list_attribute_content label[0..-2], entries.first
  end
end

#list_attribute_content(label, value) ⇒ Object



150
151
152
153
154
155
156
# File 'lib/view.rb', line 150

def list_attribute_content label, value
  out = "<div class='attribute'>"
  out += "  <div class='label'>" + label + ":" + "</div>"
  out += "  <div class='value'>" + value + "</div>"
  out += "</div>"
  out
end

#mObject



111
112
113
# File 'lib/view.rb', line 111

def m
  @manifest
end

#markup_email(email) ⇒ Object



175
176
177
178
179
180
181
182
183
184
# File 'lib/view.rb', line 175

def markup_email email
  if email =~ /(.*) <(.*)>/
    name = $1
    email = $2
    
    return "<a href=\"mailto:#{email}\">#{name}</a>"
  else
    return email
  end
end

#more_urls?Boolean

Returns:

  • (Boolean)


235
236
237
238
239
240
241
242
243
244
245
# File 'lib/view.rb', line 235

def more_urls?
  @manifest.urls.class.all_keys.each do |key, type|
    if key != :homepage && key != :screenshots && key != :logo &&
       key != :description_source
      if @manifest.urls.send(key)
        return true
      end
    end
  end
  return false
end

#old_versionsObject



254
255
256
257
# File 'lib/view.rb', line 254

def old_versions
  versions = @library.versions.reject{ |v| v == @manifest.version }
  versions.reverse
end

#render_descriptionObject



259
260
261
262
# File 'lib/view.rb', line 259

def render_description
  doc = Kramdown::Document.new(@manifest.description)
  doc.to_html
end

#render_template(name, output_dir, file_name = nil) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/view.rb', line 84

def render_template name, output_dir, file_name = nil
  layout = template "layout"
  layout_engine = Haml::Engine.new layout

  page = template name
  @content = Haml::Engine.new( page ).render( binding )

  output_path = ""
  if file_name
    output_path = "#{output_dir}/#{file_name}.html"
  else
    output_path = "#{output_dir}/#{name}.html"
  end

  File.open output_path, "w" do |file|
    file.puts layout_engine.render( binding )
  end
end

#style_sheetObject



107
108
109
# File 'lib/view.rb', line 107

def style_sheet
  "<link href='#{@root}public/inqlude.css' rel='stylesheet' type='text/css' />"
end

#unreleased_librariesObject



212
213
214
# File 'lib/view.rb', line 212

def unreleased_libraries
  @manifest_handler.unreleased_libraries
end

#version_contentObject



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/view.rb', line 158

def version_content
  if @manifest.class == ManifestGeneric
    raise InqludeError.new("Can't get version for generic manifest '#{@manifest.name}'")
  end
  out = @manifest.version
  out += " (#{@manifest.maturity})"
  out += "<span class='release-date'>"
  out += "released on #{@manifest.release_date}"
  out += "</span>"
  if !old_versions.empty?
    out += "<span class='old-versions'>"
    out += "(older versions: #{old_versions.join(", ")})"
    out += "</span>"
  end
  out
end

#yankObject



103
104
105
# File 'lib/view.rb', line 103

def yank
  @content
end