Permalink
Browse files

big refactoring ongoing

  • Loading branch information...
1 parent 2ff303e commit 15a6390ea029e94454a82bcc28232bc124dda2ac @msuarz msuarz committed Aug 29, 2012
Showing with 55 additions and 77 deletions.
  1. +11 −15 src/frankendoc.coffee
  2. +1 −1 src/readers/classes.coffee
  3. +9 −7 src/readers/code.coffee
  4. +23 −1 src/readers/docs.coffee
  5. +9 −52 src/readers/files.coffee
  6. +2 −1 src/settings.coffee
View
26 src/frankendoc.coffee
@@ -5,30 +5,26 @@ class Frank
constructor: ->
require('./readers/settings').read()
+ @docs = require('./readers/' + settings.docs.reader).read()
+ @code = require('./readers/' + settings.code.reader).read()
@runner = new (require('./runner/runner').Runner)
- @files = new (require('./readers/files').Files)
- @classes = new (require('./readers/classes').Classes)
@report = new (require('./reports/' + settings.report).Report)
- read: ->
- @files.read()
- @classes.read @files.code
-
run: ->
@report.start()
- @read()
-
- for doc in @files.docs()
- if doc.is_suite
- then @report.suite doc
- else @run_doc doc
-
+ @run_docs()
@report.stop()
+ run_docs: -> for doc in @docs
+ if doc.is_suite
+ then @report.suite doc
+ else @run_doc doc
+
run_doc: (doc) ->
@report.running doc.name
- results = @runner.run_steps @classes.new(), doc.steps
- @report.finished results
+ @report.finished @run_steps doc.steps
+
+ run_steps: (steps) -> @runner.run_steps @code.new(), steps
@frank = -> Fiber(-> new Frank().run()).run()
View
2 src/readers/classes.coffee
@@ -1,6 +1,6 @@
class @Classes
- read: (files) ->
+ constructor: (files) ->
@classes = []
@names = []
for file in files
View
16 src/readers/code.coffee
@@ -1,12 +1,14 @@
-{ Files } = require 'files'
+{ Files } = require './files'
+{ Classes } = require './classes'
-class @Code
+@read = -> new Classes read_files()
+
+read_files = ->
- constructor: ->
@code = []
- @files = new @Files
+ files = new Files
ext: /\.(js|coffee)$/
- add: (file) => @code.push file
-
- read: -> @files.read settings.code.root
+ found: (file) => @code.push file
+ files.read settings.code.root
+ @code
View
24 src/readers/docs.coffee
@@ -1,5 +1,27 @@
-{ Doc } = require './doc'
+fs = require 'fs'
+path = require 'path'
_ = require 'underscore'
+{ Doc } = require './doc'
+{ Files } = require './files'
+
+@read = ->
+ @docs = new @Docs
+ files = new Files
+
+ ext: new RegExp "\\#{settings.docs.type}$"
+
+ found: (file) => @docs.add(
+ path.basename file, settings.docs.type
+ fs.readFileSync file, 'utf8'
+ )
+
+ start: (dir) => @docs.add_suite path.basename dir
+ end: (dir) => @docs.add_suite path.basename dir
+
+
+ files.read settings.docs.root
+ @docs.docs
+
class @Docs
View
61 src/readers/files.coffee
@@ -1,66 +1,23 @@
fs = require 'fs'
path = require 'path'
-{ Reader } = require './confluence'
-{ Docs } = require './docs'
-
class @Files
- constructor: ->
- @code = []
- @_docs = new Docs
-
- docs: -> @_docs.docs
+ constructor: (opt) ->
+ @[key] = value for key, value of opt
is_dir: -> fs.statSync(@file).isDirectory()
skip_dir: -> @file.match /node_modules$/
- find_files: (dir, ext, add) ->
- @add_suite dir
+ read: (dir) ->
+ @start? dir
for file in fs.readdirSync dir
- @find_file path.resolve(dir, file), ext, add
+ @read_file path.resolve dir, file
- @add_suite dir
+ @end? dir
- find_file: (@file, ext, add) ->
+ read_file: (@file) ->
if @is_dir()
- then @find_files(@file, ext, add) unless @skip_dir()
- else add() if @file.match(ext)
-
- read: ->
- @read_docs()
- @read_code()
-
- use_reader: -> @_docs = new Reader().read()
-
- read_docs: ->
- return @use_reader() if settings.docs.source isnt 'files'
-
- docs_type = new RegExp "\\#{settings.docs.type}$"
-
- @find_files settings.docs.root, docs_type, @add_doc
-
- add_doc: => @_docs.add(
- path.basename @file, settings.docs.type
- @contents()
- )
-
- add_suite: (name) -> @_docs.add_suite path.basename name
-
- contents: -> fs.readFileSync @file, 'utf8'
-
- read_code: ->
- @find_files settings.code.root, /\.(js|coffee)$/, =>
- @code.push @file
-
-class Code
-
- constructor: ->
- @code = []
- @files = new @File
- ext: /\.(js|coffee)$/
- add: (file) => @code.push file
-
- read: -> @files.read settings.code.root
-
+ then @read @file unless @skip_dir()
+ else @found @file if @file.match @ext
View
3 src/settings.coffee
@@ -10,10 +10,11 @@
bringing documents alive
'''
docs:
- source: 'files'
+ reader: 'docs'
root: '.'
type: '.txt'
multiline_arg: '"""'
report: 'console'
code:
+ reader: 'code'
root: '.'

0 comments on commit 15a6390

Please sign in to comment.