Class: HtmlComposer
- Inherits:
-
Object
- Object
- HtmlComposer
- Defined in:
- lib/gitstrider/html_composer.rb
Instance Method Summary collapse
- #flush_table_section ⇒ Object
-
#initialize(root, report_relative_path) ⇒ HtmlComposer
constructor
A new instance of HtmlComposer.
- #write_html_footer ⇒ Object
- #write_html_header ⇒ Object
- #write_table_section_footer(file_path) ⇒ Object
- #write_table_section_header ⇒ Object
- #write_table_section_row(file_path, users_data) ⇒ Object
- #write_user_data(path, users_data) ⇒ Object
Constructor Details
#initialize(root, report_relative_path) ⇒ HtmlComposer
Returns a new instance of HtmlComposer.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/gitstrider/html_composer.rb', line 4 def initialize(root, report_relative_path) # removing the report directory dir_name = File.dirname(report_relative_path) if File.exist?(dir_name) FileUtils.rm_r dir_name end FileUtils.mkdir_p "#{root}/#{dir_name}/resources/" gem_path = File.(File.dirname(__FILE__)) vendor_resources = "#{gem_path}/vendor/." resources_dir = "#{root}/#{dir_name}/resources/." FileUtils.cp_r vendor_resources, resources_dir @report_relative_path = "#{root}/#{report_relative_path}" end |
Instance Method Details
#flush_table_section ⇒ Object
151 152 153 154 155 156 157 158 |
# File 'lib/gitstrider/html_composer.rb', line 151 def flush_table_section begin file = File.open(@report_relative_path, "a") file.write(@new_entry) ensure file.close unless file == nil end end |
#write_html_footer ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/gitstrider/html_composer.rb', line 98 def begin file = File.open(@report_relative_path, "a") file.write( " </table> <div class=\"footer pull-right\"> <p>visit <a href=\"https://github.com/hadibadjian/gitstrider\">GitStrider Github</a></p> </div> </body> </html>") ensure file.close unless file == nil end end |
#write_html_header ⇒ Object
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/gitstrider/html_composer.rb', line 28 def write_html_header begin File.delete(@report_relative_path) if File.exists?(@report_relative_path) file = File.open(@report_relative_path, "w") file.write( "<html> <head> <title>Contribution Log</title> <script src=\"resources/jquery-1.11.0.min.js\"></script> <script src=\"resources/jquery.peity.min.js\"></script> <script src=\"resources/bootstrap.min.js\"></script> <link rel=\"stylesheet\" href=\"resources/bootstrap.min.css\"> <script> window.onload = function() { $(\"span.pie\").peity(\"pie\") } </script> <style> body { padding: 20px; } .full_path { font-size: 10px; } .base_name { font-size: 1em; } .percentage { font-size: 12px; display: inline-block; text-align: center; } .committer { font-size: 14px; display: inline-block; text-align: center; } .h1 { font-size: 2em; } .footer { font-size: 1.5em; } .user_data { float: left; width: 80px; margin-left: 5px; } </style> </head> <body> <div class=\"h1\"> <p>Contribution Log created at #{Time.now}</p> </div> <table>") ensure file.close unless file == nil end end |
#write_table_section_footer(file_path) ⇒ Object
119 120 121 122 123 |
# File 'lib/gitstrider/html_composer.rb', line 119 def (file_path) @new_entry.concat("<tr> <td colspan=\"2\" class=\"full_path\">#{file_path}<td> </tr>") end |
#write_table_section_header ⇒ Object
113 114 115 116 117 |
# File 'lib/gitstrider/html_composer.rb', line 113 def write_table_section_header @new_entry = String.new @new_entry.concat("<tr />") end |
#write_table_section_row(file_path, users_data) ⇒ Object
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 |
# File 'lib/gitstrider/html_composer.rb', line 125 def write_table_section_row(file_path, users_data) file_name = File.basename(file_path) @new_entry.concat("<tr> <td class=\"base_name\"> #{file_name} </td> <td>"); users_data.each { |key, user_data| user_name = key user_commits = user_data[:commits] file_lines = user_data[:file_lines].to_f percentage = (user_commits / file_lines * 100).round(2) if percentage > 10 @new_entry.concat("<div class=\"user_data\"> <span class=\"pie\">#{user_commits}/#{file_lines}</span> <span class=\"percentage\"> #{percentage}% </span><br /> <span class=\"committer\">#{user_name}</span> </div>") end } @new_entry.concat("</td></tr>") end |
#write_user_data(path, users_data) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/gitstrider/html_composer.rb', line 21 def write_user_data(path, users_data) write_table_section_header write_table_section_row(path, users_data) (path) flush_table_section end |