Class: DitzStr::HtmlView

Inherits:
View show all
Defined in:
lib/ditzstr/views.rb

Direct Known Subclasses

BrickView

Constant Summary collapse

SUPPORT_FILES =
%w(style.css blue-check.png red-check.png green-check.png green-bar.png yellow-bar.png)

Instance Method Summary collapse

Methods inherited from View

add_to_view, view_additions_for

Constructor Details

#initialize(project, config, dir) ⇒ HtmlView

Returns a new instance of HtmlView.



60
61
62
63
64
65
# File 'lib/ditzstr/views.rb', line 60

def initialize project, config, dir
  @project = project
  @config = config
  @dir = dir
  @template_dir = File.dirname DitzStr::find_ditz_file("index.rhtml")
end

Instance Method Details

#generate_component_html_str(links, c, brickargs = {}) ⇒ Object



104
105
106
107
108
# File 'lib/ditzstr/views.rb', line 104

def generate_component_html_str links, c, brickargs={}
	ErbHtml.new(@template_dir, links, :component => c, :brickargs=>brickargs,
        :issues => @project.issues_for_component(c), :project => @project).
        render_template("component")
end

#generate_index_html_str(links, brickargs = {}) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/ditzstr/views.rb', line 90

def generate_index_html_str links, brickargs={}
  	past_rels, upcoming_rels = @project.releases.partition { |r| r.released? }
	ErbHtml.new(@template_dir, links, :project => @project,
        :past_releases => past_rels, :upcoming_releases => upcoming_rels,
        :components => @project.components, :brickargs=>brickargs).
        render_template("index")
end

#generate_issue_html_str(links, issue, brickargs = {}) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/ditzstr/views.rb', line 67

def generate_issue_html_str links, issue, brickargs={}
    
    extra_summary = self.class.view_additions_for(:issue_summary).map { |b| b[issue, @config] }.compact
    extra_details = self.class.view_additions_for(:issue_details).map { |b| b[issue, @config] }.compact

    erb = ErbHtml.new(@template_dir, links, :issue => issue,
      :release => (issue.release ? @project.release_for(issue.release) : nil),
      :component => @project.component_for(issue.component),
      :project => @project,:commands=>{},:brickargs=>brickargs)

    extra_summary_html = extra_summary.map { |string, extra_binding| erb.render_string string, extra_binding }.join
    extra_details_html = extra_details.map { |string, extra_binding| erb.render_string string, extra_binding }.join

    erb.render_template("issue", { :extra_summary_html => extra_summary_html, :extra_details_html => extra_details_html })

end


110
111
112
113
114
115
116
117
118
119
120
# File 'lib/ditzstr/views.rb', line 110

def generate_links
 ## build up links
  links = {}
  @project.releases.each { |r| links[r] = "release-#{r.name}.html" }
  @project.issues.each { |i| links[i] = "issue-#{i.id}.html" }
  @project.components.each { |c| links[c] = "component-#{c.name}.html" }
  links["unassigned"] = "unassigned.html" # special case: unassigned
  links["index"] = "index.html" # special case: index

  links
end

#generate_release_html_str(links, r, brickargs = {}) ⇒ Object



84
85
86
87
88
# File 'lib/ditzstr/views.rb', line 84

def generate_release_html_str links, r, brickargs={}
	ErbHtml.new(@template_dir, links, :release => r,
        :issues => @project.issues_for_release(r), :project => @project, :brickargs=>brickargs).
        render_template("release")
end

#generate_unassigned_html_str(links, brickargs = {}) ⇒ Object



98
99
100
101
102
# File 'lib/ditzstr/views.rb', line 98

def generate_unassigned_html_str links, brickargs={}
	ErbHtml.new(@template_dir, links, :brickargs=>brickargs,
     		 :issues => @project.unassigned_issues, :project => @project).
     		 render_template("unassigned")
end

#render_allObject



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/ditzstr/views.rb', line 123

def render_all
  Dir.mkdir @dir unless File.exists? @dir
  SUPPORT_FILES.each { |f| FileUtils.cp File.join(@template_dir, f), @dir }

  links = generate_links
 
  @project.issues.each do |issue|
    fn = File.join @dir, links[issue]
    File.open(fn, "w") { |f| f.puts generate_issue_html_str links, issue}
  end

  @project.releases.each do |r|
    fn = File.join @dir, links[r]
    File.open(fn, "w") { |f| f.puts generate_release_html_str links, r}
  end

  @project.components.each do |c|
    fn = File.join @dir, links[c]
    File.open(fn, "w") { |f| f.puts generate_component_html_str links, c}
  end

  fn = File.join @dir, links["unassigned"]
  File.open(fn, "w") do |f|
    f.puts generate_unassigned_html_str links
  end

  fn = File.join @dir, links["index"]
  File.open(fn, "w") do |f|
    f.puts generate_index_html_str links
  end
  puts "Local generated URL: file://#{File.expand_path(fn)}"
end