Permalink
Browse files

extract render_file_list.coffee

  • Loading branch information...
1 parent d9fc009 commit 76b18e5591fc997be635700f10c9c56b35fd4c2e Steve Howell committed Jan 29, 2012
Showing with 51 additions and 44 deletions.
  1. +1 −44 list_files.coffee
  2. +50 −0 render_file_list.coffee
View
@@ -1,23 +1,5 @@
file_utils = require './file_utils'
-
-table = (headers, rows) ->
- html = '<table>'
- html += '<tr>'
- ths = ("<th>#{th}</th>" for th in headers)
- html += ths.join ''
- html += '</tr>'
- for row in rows
- html += '<tr>'
- td = (cell) ->
- if cell.toString().match /^\d+$/
- align = "center"
- else
- align = "left"
- "<td align='#{align}' class='view_files'>#{cell}</td>"
- html += (td cell for cell in row).join ''
- html += '</tr>'
- html += '</table>'
- html
+{render} = require './render_file_list'
list_files = (top_level_dir, get_files, coffee_file_regex, cb) ->
@@ -63,29 +45,4 @@ data_for_file = (cs_file, cs_root, js_files, top_level_dir) ->
data.js_path = file_utils.relative_path top_level_dir, js_file
data
-row_for_file = (data) ->
- view_link = "<a href='#{data.cs_href}'>#{data.cs_root}</a>"
- row = [data.cs_num_lines, view_link]
- if data.js_path
- row.push data.js_path
- row
-
-render = (dirs) ->
- html = ''
- for dir in dirs
- html += dir_header dir.path
- rows = (row_for_file data for data in dir.rows)
- html += render_dir_files rows
- html
-
-dir_header = (path) ->
- """
- <hr>
- <h3>#{path}</h3>
- """
-
-render_dir_files = (rows) ->
- headers = ['line count for CS', 'coffee', 'JS file']
- table headers, rows
-
exports.list_files = list_files
View
@@ -0,0 +1,50 @@
+# This code renders the main part of the main page, where you list all
+# the coffeescript files, broken out by directory.
+
+render = (dirs) ->
+ # Uncomment the next line if you want to see a raw view of the data.
+ # return "<pre>#{JSON.stringify dirs, null, ' '}</pre>"
+ html = ''
+ for dir in dirs
+ html += dir_header dir.path
+ rows = (row_for_file data for data in dir.rows)
+ html += render_dir_files rows
+ html
+
+row_for_file = (data) ->
+ view_link = "<a href='#{data.cs_href}'>#{data.cs_root}</a>"
+ row = [data.cs_num_lines, view_link]
+ if data.js_path
+ row.push data.js_path
+ row
+
+dir_header = (path) ->
+ """
+ <hr>
+ <h3>#{path}</h3>
+ """
+
+render_dir_files = (rows) ->
+ headers = ['line count for CS', 'coffee', 'JS file']
+ table headers, rows
+
+table = (headers, rows) ->
+ html = '<table>'
+ html += '<tr>'
+ ths = ("<th>#{th}</th>" for th in headers)
+ html += ths.join ''
+ html += '</tr>'
+ for row in rows
+ html += '<tr>'
+ td = (cell) ->
+ if cell.toString().match /^\d+$/
+ align = "center"
+ else
+ align = "left"
+ "<td align='#{align}' class='view_files'>#{cell}</td>"
+ html += (td cell for cell in row).join ''
+ html += '</tr>'
+ html += '</table>'
+ html
+
+exports.render = render

0 comments on commit 76b18e5

Please sign in to comment.