docjs 0.2 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -8,6 +8,10 @@ Doc.js is a JavaScript-Documentation tool which detects `tokens` in your comment
8
8
  documentation out of it. Doc.js could be ported pretty easy to any other language, because the most
9
9
  of it's parts are language agnostic.
10
10
 
11
+ Demo Projects
12
+ -------------
13
+ - [arrayJS](http://b-studios.github.com/arrayJS/)
14
+
11
15
  Features
12
16
  --------
13
17
  - One command to install
@@ -25,6 +29,13 @@ If you read this, you may belong to one of the following groups:
25
29
  2. You need some more {file:USE.md information, how to use Doc.js}
26
30
  3. You want to {file:CUSTOMIZE.md customize Doc.js}, to exactly fit your needs
27
31
 
32
+ Useful Information
33
+ ------------------
34
+ - List of supported {file:USE.md#Available_Tokens Tokens}
35
+ - Built in {Token::Handler Handlers}
36
+ - Overview about {Generator::Generator Generators}
37
+
38
+
28
39
  Supported Ruby-Version
29
40
  ----------------------
30
41
  Currently **only ruby > 1.9.x is supported**. Support for 1.8.x is not planned, because there are
@@ -39,6 +50,9 @@ find the time to fix thoses and the first problem in 1.8.x so only 1.9+ is suppo
39
50
  the time to work on 1.8 compatibility you would make me (and possibly some other 1.8 users) very
40
51
  happy.
41
52
 
53
+ Architectural Insides
54
+ ---------------------
55
+ {DocJs} is a good starting point if you want to get started with information about the structure of DocJs.
42
56
 
43
57
  Installation
44
58
  ------------
data/bin/docjs CHANGED
@@ -3,53 +3,60 @@
3
3
  require 'pathname'
4
4
  require Pathname.new(__FILE__).realpath + '../../lib/boot'
5
5
 
6
- # @todo The general flow of information should be documented here
7
- #
8
- # --String--> [Parser] --Commentstream--> [CodeObjectFactory] --Objectstream--> [Registry]
9
- #
10
- # Parser
11
- # ------
12
- # Turns the incoming stream of characters (string) into a stream of
13
- # {Parser::Comment comments}. Those comments contain the parsed doclines, which
14
- # are simply all lines found in the comment and all tokenlines.
15
-
16
6
  # configure approot
17
7
  Configs.set :root => Pathname.new(__FILE__).realpath + '../..'
18
8
 
19
- # Pipeline:
20
- # 1. load options from shell and specified YAML-file (if any)
21
- # 2. load files
22
- # 3. parse files
23
- # 4. turn into objects and save to dom
24
- # 5. render templates
9
+ # Program Flow
10
+ # ------------
11
+ # ![Program flow](img/md_total_flow.svg)
12
+ #
13
+ # 1. {#setup_application Prepare Doc.js} - Read configurations and setup application environment
14
+ # 2. {Processor.prepare_documents Process Markdown Documents} - Read the optional markdown-documents and add them to the internal
15
+ # datastructure.
16
+ # 3. {Parser::Parser Process JavaScript Files} - Parse JavaScript-Files and add the found comments to the Dom.
17
+ # Afterwards process the tokens within the comments.
18
+ # 4. {Generator::Generator Render Templates} - Apply the Outputgenerators and save the rendered templates to disk
19
+ # 5. Copy static resources - Finalize the output and copy the javascript, images and stylesheets to
20
+ # the output-directory
21
+ #
22
+ # The {Processor} is the central module, which controls the workflow described above. It separates
23
+ # the tasks into different stages, which are performed one after another. (You can see this in
24
+ # the source-code of {DocJs#docjs})
25
+ #
26
+ # The Command Line Interface
27
+ # --------------------------
28
+ # The `DocJs`-class serves as command line interface (cli) and therefore extends Thor. It allows us
29
+ # to create tasks, which then in turn can be called from the command line.
30
+ # This way every instance method of `DocJs` will be turned into a commandline task.
31
+ #
32
+ # docjs help configure
33
+ #
34
+ # Will create an instance of DocJs and call the {#help} method on it. (Which results in the help screen
35
+ # being displayed). As help expects one argument 'configure' is passed to the call of `help`. All
36
+ # additional commandline arguments would be parsed by Thor and added to the instance variable
37
+ # `configs`.
38
+ #
39
+ # The Internal Datastructure
40
+ # --------------------------
41
+ # All parsed CodeObjects (i.e. comments found in your JavaScript-soures) are internally represented
42
+ # as a Dom-Tree. They can be accessed via {Dom.root}
43
+ #
44
+ # Also all Markdown-Documents are stored in the same Dom-tree, but under a different root-node called
45
+ # {Dom.docs}.
46
+ #
47
+ # For more information about storing and retreiving Data in DocJs see {Dom}.
48
+ #
49
+ #
50
+ # @see https://github.com/wycats/thor/wiki
51
+ # @see Processor
25
52
  #
26
53
  # @note options declared in a docjs.yml will override command-line ones
54
+ # @note for more information about the **instance methods** please type `docjs help` or
55
+ # `docjs help TASK` into your commandline or reference the {file:README.md#Guides guides}.
27
56
  class DocJs < Thor
28
57
 
29
58
  include Thor::Actions
30
-
31
- def help(task = nil)
32
-
33
- # Introduction
34
- unless task
35
- say "Welcome to Doc.js", :bold
36
- say "If you are using Doc.js for the first time in your project, you may want to create a config file (like docjs.yml)
37
- A guided wizard can help you achieving this goal - Simply run the following command:
38
- docjs configure
39
- \n
40
- After creating a config-file (like docjs.yml) the documentation can be generated by running:
41
- docjs docjs.yml
42
-
43
- For further information, please visit http://b-studios.github.com/doc.js\n\n"
44
-
45
- self.class.help(shell, false)
46
59
 
47
- # Help for a specific task
48
- else
49
- self.class.task_help(shell, task)
50
- end
51
- end
52
-
53
60
  desc "CONFIG_FILE", "Starts documentation process"
54
61
  set_options :files =>
55
62
  { :type => :array, :aliases => '-f', :default => [] },
@@ -78,10 +85,12 @@ For further information, please visit http://b-studios.github.com/doc.js\n\n"
78
85
  configs = config_file ? merge_options(options, config_file) : options
79
86
 
80
87
  begin
88
+
89
+ # PREPARE DOCJS
90
+
81
91
  # Setup Logger and Configs
82
92
  setup_application configs
83
93
 
84
- # Load application specific files
85
94
  Logger.info "Loading Application-Templates"
86
95
  load_templates
87
96
 
@@ -89,24 +98,54 @@ For further information, please visit http://b-studios.github.com/doc.js\n\n"
89
98
  DocJs.source_root(Configs.templates)
90
99
  self.destination_root = Configs.output
91
100
 
92
- # Process specified docs and add them to dom-tree
93
- Processor.prepare_documents
94
101
 
95
- # Kickoff js-file-processing and template-rendering!
96
- Processor.process_and_render
102
+ # PROCESS MARKDOWN DOCUMENTS
103
+ Processor.prepare_documents # Stage #1
104
+
105
+ # PROCESS JAVASCRIPT FILES
106
+ Processor.process_files_to_dom # Stage #2
107
+
108
+ # RENDER TEMPLATES
109
+ Processor.start_generators # Stage #3
110
+
97
111
 
98
- # Finally copy all
112
+ # COPY STATIC RESOURCES
99
113
  Logger.info "Copying template resources to output"
100
- directory 'resources/img', './img' # copy resources
114
+ directory 'resources/img', './img'
101
115
  directory 'resources/css', './css'
102
116
  directory 'resources/js', './js'
103
-
117
+
118
+ # Print error on console, if something bad happend
104
119
  rescue Exception => error
105
120
  Logger.error error.message + "\n" + error.backtrace.map{|l| " #{l}" }.join("\n")
106
121
  end
107
122
  end
108
123
 
109
124
 
125
+
126
+ def help(task = nil)
127
+
128
+ # Introduction
129
+ unless task
130
+ say "Welcome to Doc.js", :bold
131
+ say "If you are using Doc.js for the first time in your project, you may want to create a config file (like docjs.yml)
132
+ A guided wizard can help you achieving this goal - Simply run the following command:
133
+ docjs configure
134
+ \n
135
+ After creating a config-file (like docjs.yml) the documentation can be generated by running:
136
+ docjs docjs.yml
137
+
138
+ For further information, please visit http://b-studios.github.com/doc.js\n\n"
139
+
140
+ self.class.help(shell, false)
141
+
142
+ # Help for a specific task
143
+ else
144
+ self.class.task_help(shell, task)
145
+ end
146
+ end
147
+
148
+
110
149
 
111
150
  desc "configure [NEW_CONFIGFILE]", "Helps you creating your docjs.yml to start off with doc.js"
112
151
  def configure(output_file = "docjs.yml", preconfigured = {})
@@ -3,53 +3,60 @@
3
3
  require 'pathname'
4
4
  require Pathname.new(__FILE__).realpath + '../../lib/boot'
5
5
 
6
- # @todo The general flow of information should be documented here
7
- #
8
- # --String--> [Parser] --Commentstream--> [CodeObjectFactory] --Objectstream--> [Registry]
9
- #
10
- # Parser
11
- # ------
12
- # Turns the incoming stream of characters (string) into a stream of
13
- # {Parser::Comment comments}. Those comments contain the parsed doclines, which
14
- # are simply all lines found in the comment and all tokenlines.
15
-
16
6
  # configure approot
17
7
  Configs.set :root => Pathname.new(__FILE__).realpath + '../..'
18
8
 
19
- # Pipeline:
20
- # 1. load options from shell and specified YAML-file (if any)
21
- # 2. load files
22
- # 3. parse files
23
- # 4. turn into objects and save to dom
24
- # 5. render templates
9
+ # Program Flow
10
+ # ------------
11
+ # ![Program flow](img/md_total_flow.svg)
12
+ #
13
+ # 1. {#setup_application Prepare Doc.js} - Read configurations and setup application environment
14
+ # 2. {Processor.prepare_documents Process Markdown Documents} - Read the optional markdown-documents and add them to the internal
15
+ # datastructure.
16
+ # 3. {Parser::Parser Process JavaScript Files} - Parse JavaScript-Files and add the found comments to the Dom.
17
+ # Afterwards process the tokens within the comments.
18
+ # 4. {Generator::Generator Render Templates} - Apply the Outputgenerators and save the rendered templates to disk
19
+ # 5. Copy static resources - Finalize the output and copy the javascript, images and stylesheets to
20
+ # the output-directory
21
+ #
22
+ # The {Processor} is the central module, which controls the workflow described above. It separates
23
+ # the tasks into different stages, which are performed one after another. (You can see this in
24
+ # the source-code of {DocJs#docjs})
25
+ #
26
+ # The Command Line Interface
27
+ # --------------------------
28
+ # The `DocJs`-class serves as command line interface (cli) and therefore extends Thor. It allows us
29
+ # to create tasks, which then in turn can be called from the command line.
30
+ # This way every instance method of `DocJs` will be turned into a commandline task.
31
+ #
32
+ # docjs help configure
33
+ #
34
+ # Will create an instance of DocJs and call the {#help} method on it. (Which results in the help screen
35
+ # being displayed). As help expects one argument 'configure' is passed to the call of `help`. All
36
+ # additional commandline arguments would be parsed by Thor and added to the instance variable
37
+ # `configs`.
38
+ #
39
+ # The Internal Datastructure
40
+ # --------------------------
41
+ # All parsed CodeObjects (i.e. comments found in your JavaScript-soures) are internally represented
42
+ # as a Dom-Tree. They can be accessed via {Dom.root}
43
+ #
44
+ # Also all Markdown-Documents are stored in the same Dom-tree, but under a different root-node called
45
+ # {Dom.docs}.
46
+ #
47
+ # For more information about storing and retreiving Data in DocJs see {Dom}.
48
+ #
49
+ #
50
+ # @see https://github.com/wycats/thor/wiki
51
+ # @see Processor
25
52
  #
26
53
  # @note options declared in a docjs.yml will override command-line ones
54
+ # @note for more information about the **instance methods** please type `docjs help` or
55
+ # `docjs help TASK` into your commandline or reference the {file:README.md#Guides guides}.
27
56
  class DocJs < Thor
28
57
 
29
58
  include Thor::Actions
30
-
31
- def help(task = nil)
32
-
33
- # Introduction
34
- unless task
35
- say "Welcome to Doc.js", :bold
36
- say "If you are using Doc.js for the first time in your project, you may want to create a config file (like docjs.yml)
37
- A guided wizard can help you achieving this goal - Simply run the following command:
38
- docjs configure
39
- \n
40
- After creating a config-file (like docjs.yml) the documentation can be generated by running:
41
- docjs docjs.yml
42
-
43
- For further information, please visit http://b-studios.github.com/doc.js\n\n"
44
-
45
- self.class.help(shell, false)
46
59
 
47
- # Help for a specific task
48
- else
49
- self.class.task_help(shell, task)
50
- end
51
- end
52
-
53
60
  desc "CONFIG_FILE", "Starts documentation process"
54
61
  set_options :files =>
55
62
  { :type => :array, :aliases => '-f', :default => [] },
@@ -78,10 +85,12 @@ For further information, please visit http://b-studios.github.com/doc.js\n\n"
78
85
  configs = config_file ? merge_options(options, config_file) : options
79
86
 
80
87
  begin
88
+
89
+ # PREPARE DOCJS
90
+
81
91
  # Setup Logger and Configs
82
92
  setup_application configs
83
93
 
84
- # Load application specific files
85
94
  Logger.info "Loading Application-Templates"
86
95
  load_templates
87
96
 
@@ -89,24 +98,54 @@ For further information, please visit http://b-studios.github.com/doc.js\n\n"
89
98
  DocJs.source_root(Configs.templates)
90
99
  self.destination_root = Configs.output
91
100
 
92
- # Process specified docs and add them to dom-tree
93
- Processor.prepare_documents
94
101
 
95
- # Kickoff js-file-processing and template-rendering!
96
- Processor.process_and_render
102
+ # PROCESS MARKDOWN DOCUMENTS
103
+ Processor.prepare_documents # Stage #1
104
+
105
+ # PROCESS JAVASCRIPT FILES
106
+ Processor.process_files_to_dom # Stage #2
107
+
108
+ # RENDER TEMPLATES
109
+ Processor.start_generators # Stage #3
110
+
97
111
 
98
- # Finally copy all
112
+ # COPY STATIC RESOURCES
99
113
  Logger.info "Copying template resources to output"
100
- directory 'resources/img', './img' # copy resources
114
+ directory 'resources/img', './img'
101
115
  directory 'resources/css', './css'
102
116
  directory 'resources/js', './js'
103
-
117
+
118
+ # Print error on console, if something bad happend
104
119
  rescue Exception => error
105
120
  Logger.error error.message + "\n" + error.backtrace.map{|l| " #{l}" }.join("\n")
106
121
  end
107
122
  end
108
123
 
109
124
 
125
+
126
+ def help(task = nil)
127
+
128
+ # Introduction
129
+ unless task
130
+ say "Welcome to Doc.js", :bold
131
+ say "If you are using Doc.js for the first time in your project, you may want to create a config file (like docjs.yml)
132
+ A guided wizard can help you achieving this goal - Simply run the following command:
133
+ docjs configure
134
+ \n
135
+ After creating a config-file (like docjs.yml) the documentation can be generated by running:
136
+ docjs docjs.yml
137
+
138
+ For further information, please visit http://b-studios.github.com/doc.js\n\n"
139
+
140
+ self.class.help(shell, false)
141
+
142
+ # Help for a specific task
143
+ else
144
+ self.class.task_help(shell, task)
145
+ end
146
+ end
147
+
148
+
110
149
 
111
150
  desc "configure [NEW_CONFIGFILE]", "Helps you creating your docjs.yml to start off with doc.js"
112
151
  def configure(output_file = "docjs.yml", preconfigured = {})
@@ -4,8 +4,8 @@ Gem::Specification.new do |s|
4
4
 
5
5
 
6
6
  s.name = 'docjs'
7
- s.version = '0.2'
8
- s.date = '2011-06-28'
7
+ s.version = '0.2.1'
8
+ s.date = '2012-10-06'
9
9
  s.summary = "Javascript Documentation Generator"
10
10
  s.description = "Create beautiful Javascript documentations with this ruby-gem. It's pretty easy to customize and add your own tokens/DSL."
11
11
  s.homepage = "https://github.com/b-studios/doc.js"
@@ -1,3 +1,93 @@
1
+ Customization
2
+ =============
3
+ All of the following Guides require modifications of the default-templates. To start of with your own
4
+ templates simply type:
5
+
6
+ docjs scaffold TEMPLATE_PATH
7
+
8
+ in your console and replace `TEMPLATE_PATH` with the path you wish the templates to be generated in.
9
+ This command will copy the default templates to `TEMPLATE_PATH`, which results in a structure similiar
10
+ to:
11
+
12
+ my_templates/
13
+ generators/
14
+ helpers/
15
+ resources/
16
+ tokens/
17
+ types/
18
+ views/
19
+ application.rb
20
+
21
+ If you take a look at `application.rb` you will see, that all it does is to require the files, which
22
+ are placed within the other template-folders.
23
+
24
+ generators/
25
+ -----------
26
+ Contains all custom generators, which are needed to create html or json-files from the internal data-
27
+ structure. In section {file:CUSTOMIZE.md#Modifying_a_Generator Modifying a Generator} you can learn
28
+ a bit more about the use of a generator and how to customize it.
29
+
30
+ **Contents:**
31
+
32
+ - {Generator::ApiIndexGenerator}
33
+ - {Generator::ApiPagesGenerator}
34
+ - {Generator::DocsGenerator}
35
+ - {Generator::JsonGenerator}
36
+
37
+ helpers/
38
+ --------
39
+ Helpers are, like helpers in Rails, included into your generator and can be used there and in the views
40
+ aswell. (See Section Helpers in {Generator::Generator})
41
+
42
+ **Contents:**
43
+
44
+ - {Helper::Template}
45
+
46
+ resources/
47
+ ----------
48
+ Contains all static template resources like **css**, **js** and **img** files
49
+
50
+ **Contents:**
51
+
52
+ - `css/application.css`
53
+ - `scss/application.scss` and all partials (starting with an underscore)
54
+ - `js/application.js` and all required libraries
55
+ - `img/object.png` and all other icons
56
+
57
+ tokens/
58
+ -------
59
+ Only consists of one file `tokens.rb`, which contains all the registered Tokens. You may find some more
60
+ information about the tokens in the {file:USE.md Usage-Guide}.
61
+
62
+ **Contents:**
63
+
64
+ - `tokens.rb`
65
+
66
+ types/
67
+ ------
68
+ Types are special tokens. They categorize the Comments respectively CodeObject's by subclassing them.
69
+ Per default these are
70
+
71
+ **Contents:**
72
+
73
+ - {CodeObject::Object} (@object)
74
+ - {CodeObject::Function} (@function, @constructor, @method)
75
+ - {CodeObject::Prototype} (@prototype)
76
+
77
+ See {file:USE.md#Types Usage-Guide}
78
+
79
+ views/
80
+ ------
81
+ Contains the `html.erb` template-files and partials, which will be rendered by the {Generator::Generator Generators}
82
+
83
+ **Contents:**
84
+
85
+ - `function/` All templates to render {CodeObject::Function @function-documentation}
86
+ - `object/` All templates to render {CodeObject::Object @object-documentation}
87
+ - `layouts/` Contains all layouts like `application.html.erb` and `json.html.erb`
88
+ - `tokens/` All templates, which a necessary to render a token (See {file:CUSTOMIZE.md#Creating_a_custom_template the Guide below})
89
+
90
+
1
91
  1. Example - Adding a simple token
2
92
  ==================================
3
93
  You can extend Doc.js on different levels. The easiest way of customization is to add a simple token.