docjs 0.1.4 → 0.1.5

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.
Files changed (41) hide show
  1. data/README.md +33 -63
  2. data/bin/docjs +30 -8
  3. data/bin/docjs.rb +30 -8
  4. data/docjs.gemspec +2 -2
  5. data/docs/ARCHITECTURE.md +0 -0
  6. data/{CONCEPT.md → docs/CONCEPT.md} +0 -0
  7. data/{DOCUMENTATION.md → docs/DOCUMENTATION.md} +2 -4
  8. data/docs/PATTERNS.md +101 -0
  9. data/docs/guides/CUSTOMIZE.md +158 -0
  10. data/docs/guides/TRY.md +63 -0
  11. data/docs/guides/USE.md +256 -0
  12. data/lib/boot.rb +2 -6
  13. data/lib/code_object/base.rb +5 -0
  14. data/lib/dom/node.rb +1 -1
  15. data/lib/{tasks/render_task.rb → generator/generator.rb} +15 -9
  16. data/lib/helper/helper.rb +2 -2
  17. data/lib/helper/linker.rb +7 -13
  18. data/lib/processor.rb +3 -12
  19. data/lib/renderer.rb +2 -0
  20. data/lib/token/container.rb +2 -1
  21. data/lib/token/handler.rb +187 -115
  22. data/lib/token/token.rb +35 -3
  23. data/templates/application.rb +7 -5
  24. data/templates/{tasks/api_index_task.rb → generators/api_index_generator.rb} +2 -2
  25. data/templates/{tasks/typed_task.rb → generators/api_pages_generator.rb} +2 -2
  26. data/templates/{tasks/docs_task.rb → generators/docs_generator.rb} +9 -2
  27. data/templates/{tasks/json_data_task.rb → generators/json_generator.rb} +2 -2
  28. data/templates/tokens/tokens.rb +2 -2
  29. data/{lib/code_object → templates/types}/function.rb +5 -3
  30. data/{lib/code_object → templates/types}/object.rb +0 -2
  31. data/templates/types/prototype.rb +2 -3
  32. data/templates/views/tokens/_default.html.erb +0 -2
  33. data/test/code_object/prototype.rb +1 -1
  34. data/test/dom/dom.absolute_nodes.rb +2 -3
  35. data/test/dom/dom.rb +3 -3
  36. data/test/dom/node.rb +9 -9
  37. data/test/integration/converter.rb +3 -3
  38. data/test/token/handler.rb +12 -9
  39. data/test/token/tokens.rb +1 -1
  40. metadata +16 -12
  41. data/RENDERING.md +0 -8
@@ -0,0 +1,63 @@
1
+ Installation
2
+ ============
3
+ Prerequisites: You need Ruby >= 1.9 to run Doc.js
4
+
5
+ gem install docjs
6
+
7
+ After installing the gem, you can start by typing `docjs` in your console. This
8
+ will bring up a small introduction and an overview of all available commands.
9
+ To retreive some more information about one specific command simply type
10
+
11
+ docjs help COMMAND_NAME
12
+
13
+
14
+ Basic Usage
15
+ ===========
16
+
17
+ Configuration
18
+ -------------
19
+ Before you can use Doc.js you may create your own **Configuration-File**. This
20
+ can easily be done, using the built-in configuration-generator:
21
+
22
+ docjs configure
23
+
24
+ You optionally can specify the filename of your configuration file. If no file
25
+ is specified the configs will be written to `docjs.yml`.
26
+
27
+ docjs configure my_config_file.yml
28
+
29
+ The configuration is an interactive one - simply answer the questions you will
30
+ be asked.
31
+
32
+
33
+ Start documenting your code
34
+ ---------------------------
35
+ To make jsdoc recognize your documentation you have to use some special tokens.
36
+ Let's write a documented function `hello_doc`:
37
+
38
+ /**
39
+ * @function hello_doc
40
+ *
41
+ * Innovative function to greet a Person.
42
+ *
43
+ * @param [String] name the person you want to greet
44
+ * @return void
45
+ */
46
+ function hello_doc(name) {
47
+ console.log("Hello " + name + "!");
48
+ }
49
+
50
+ The symbols `@function`, `@param` and `@return` are called **tokens** in Doc.js.
51
+ There are many more by default. To see which one you can use simply type:
52
+
53
+ docjs tokens
54
+
55
+
56
+ Run the documentation and enjoy!
57
+ --------------------------------
58
+ Now it's time to kickoff the documentation-process by typing:
59
+
60
+ docjs your_config.yml
61
+
62
+ You will find the docs in the output-directory you have specified in your
63
+ config-file.
@@ -0,0 +1,256 @@
1
+ Configuration Options
2
+ =====================
3
+ You can run Doc.js with your custom configuration by either adding the desired
4
+ options as **command-line** parameter or by writing them in a **configuration**-file.
5
+ All available options are listed if you type:
6
+
7
+ docjs help docjs
8
+
9
+ For example one may run docjs using only command-line options
10
+
11
+ docjs --files="js/*.js" --output="out" --appname="My Documentation"
12
+
13
+ The same options, could be written in a config-file `docjs.yml`
14
+
15
+ files:
16
+ - js/*.js
17
+
18
+ output: out
19
+ appname: My Documentation
20
+
21
+ Then simply run:
22
+
23
+ docjs docjs.yml
24
+
25
+ **Please note that all paths you specify will be resolved relative to the current working
26
+ directory!**
27
+
28
+
29
+ List of Config-options
30
+ ----------------------
31
+
32
+ | Option | Default | Usage
33
+ |--------------|------------|-----------------------------------------------------------------------
34
+ | `appname` | MyAppName | The appname, which is stored in `Configs.options[:appname]` and can be used in the view-templates.
35
+ | `docs` | README.md | List of Markdown-documents. You can use wildcards like `docs/**/*.md`
36
+ | `files` | --- | List of JavaScript-Files. Just like the docs, you can use wildcards in the paths.
37
+ | `logfile` | --- | Use this path if you want the log-messages to be written to a file.
38
+ | `loglevel` | info | All the messages lower then the specified level will not be printed. Available levels are (in that order): `debug`, `info`, `warn`, `error`
39
+ | | |
40
+ | `output` | out | The generated documentation will be saved at this path. Please double-check it to prevent files to be overriden.
41
+ | `templates` | *internal* | If you used `scaffold` or created your own templates by hand, you have to specify this path to make docjs use them.
42
+
43
+
44
+ Note
45
+ ----
46
+ Commandline lists like `docs` and `files` are whitespace separated.
47
+
48
+ --files="first_file.js" "others/*.js"
49
+
50
+ In a configuration file, you can use a simple YAML-list:
51
+
52
+ files:
53
+ - first_file.js
54
+ - others/*.js
55
+
56
+
57
+ Types
58
+ =====
59
+ Types specify the `type` of the documented CodeObject. There are a only a few types available per
60
+ default:
61
+
62
+ - `@object`
63
+ - `@function`
64
+ - `@prototype`
65
+ - (`@constructor`)
66
+
67
+ The first two are considered primitives of the JavaScript language. Advanced concepts like classes,
68
+ mixins, pseudoclassical inheritence and so on can easily be added by
69
+ {file:CUSTOMIZE.md creating your own template} or modifying the existing one. `@prototype` is added
70
+ as type, so you can see how to create your own custom-types. More information about the `@prototype`
71
+ - type can be found in {file:PATTERNS.md#Prototypal_Inheritance the documentation-pattern-list}.
72
+
73
+ Types classify the piece of code, you are documenting - so adding a type is essential and **always
74
+ required**.
75
+
76
+ /**
77
+ * @function sayHello
78
+ */
79
+
80
+ Creates a documentation-element named `sayHello` with the type {CodeObject::Function}.
81
+
82
+ Namespacing
83
+ ===========
84
+ Because writing documentation takes enough time, there is a shorthand to express namespaces
85
+ **relative** to the parent in the surrounding scope.
86
+
87
+ /**
88
+ * @object some.namespace
89
+ */
90
+ var some.namespace = {
91
+
92
+ /**
93
+ * @function some.namespace.sayHello
94
+ */
95
+ sayHello: function() {...}
96
+ }
97
+
98
+ can be rewritten as:
99
+
100
+ /**
101
+ * @object some.namespace
102
+ */
103
+ var some.namespace = {
104
+
105
+ /**
106
+ * @function .sayHello
107
+ */
108
+ sayHello: function() {...}
109
+ }
110
+
111
+ This only works, because the JavaScript-Parser of Doc.js is working scope-aware. So you always can
112
+ use the dot-notation if your comment is in the lexical-scope of the parent comment.
113
+
114
+ The dot-notation (`.sayHello`) was inspired by file-system, where one dot refers to the current
115
+ directory. It also fit's into the JavaScript context, because the child can be accessed by using
116
+ the dot.
117
+
118
+ Please note: **If relative naming results in errors you still can use absolute naming**.
119
+
120
+ Available Tokens
121
+ ================
122
+
123
+ @author
124
+ -------
125
+ | Handler | Area | Template
126
+ |:-----------------|:-----------|:-------------
127
+ | :default | :sidebar | :default
128
+
129
+ Can be used multiple times for many authors like:
130
+
131
+ @author Jon Foo
132
+ @author Peter Bar (Editor)
133
+
134
+
135
+ @constructor
136
+ ------------
137
+ Simply creates a function-type and makes it answer `fun.constructor?` with `true`.
138
+
139
+
140
+ @deprecated
141
+ -----------
142
+ | Handler | Area | Template
143
+ |:-----------------|:---------------|:-------------
144
+ | :default | :notification | :default
145
+
146
+ @event
147
+ ------
148
+ | Handler | Area | Template
149
+ |:-------------------------|:--------|:-------------
150
+ | :named_nested_shorthand | :body | :default
151
+
152
+ @example
153
+ --------
154
+ | Handler | Area | Template
155
+ |:-----------------|:-------|:-------------
156
+ | :named_multiline | :body | :example
157
+
158
+ @function
159
+ ---------
160
+ Type
161
+
162
+
163
+ @method
164
+ -------
165
+ Type
166
+
167
+ @note
168
+ -----
169
+ | Handler | Area | Template
170
+ |:-----------------|:---------------|:-------------
171
+ | :default | :notification | :default
172
+
173
+ @object
174
+ -------
175
+ Using @object set's the type of the documented CodeObject to {CodeObject::Object}. No token will be
176
+ added. See {file:USE.md#Types types} for further information about the types in Doc.js.
177
+
178
+ @overload
179
+ ---------
180
+ | Handler | Area | Template
181
+ |:-------------|:-------|:----------
182
+ | :custom | :none | :default
183
+
184
+ You can use overloads, if your **function requires multiple signatures**.
185
+ So instead of adding your `@param`'s and `@return`'s directly to the function's documentation you
186
+ specify overloads like:
187
+
188
+ /**
189
+ * @function non.sense
190
+ *
191
+ * @overload
192
+ * Your description of this overload. Every line, not starting with `@` or intended by 2
193
+ * spaces (Which indicate linecontinuation) is treated as documentation for the overload.
194
+ *
195
+ * @param [String] name your name. We can continuate this line, by simply intending it
196
+ * two spaces. You see? Simple, hu?
197
+ * @param [Array<String>] collegues Your coworkers
198
+ * @return [Void] Returns nothing!
199
+ *
200
+ * @overload
201
+ * This is another way to use this function. It only requires one parameter.
202
+ * @param [Object] person
203
+ * @return [String] The name of the person
204
+ */
205
+
206
+ Please note, that in line 7 of this example the continuation of @overload is achieved due intending
207
+ the empty line with some spaces.
208
+
209
+
210
+ @param
211
+ ------
212
+
213
+ @private
214
+ --------
215
+ | Handler | Area | Template
216
+ |:-----------------|:-----------|:-------------
217
+ | :default | :sidebar | :default
218
+
219
+ @prop
220
+ -----
221
+
222
+ @prototype
223
+ ----------
224
+
225
+ @public
226
+ -------
227
+ | Handler | Area | Template
228
+ |:-----------------|:-----------|:-------------
229
+ | :default | :sidebar | :default
230
+
231
+ @return
232
+ -------
233
+
234
+ @see
235
+ ----
236
+
237
+ @throws
238
+ -------
239
+
240
+ @todo
241
+ -----
242
+ | Handler | Area | Template
243
+ |:-----------------|:---------------|:-------------
244
+ | :default | :notification | :default
245
+
246
+ @version
247
+ --------
248
+ | Handler | Area | Template
249
+ |:-----------------|:-----------|:-------------
250
+ | :default | :sidebar | :default
251
+
252
+ @warn
253
+ -----
254
+ | Handler | Area | Template
255
+ |:-----------------|:---------------|:-------------
256
+ | :default | :notification | :default
@@ -7,7 +7,7 @@ require_relative 'logger'
7
7
  require_relative 'configs'
8
8
  require_relative 'parser/parser'
9
9
  require_relative 'token/handler'
10
- require_relative 'code_object/function'
10
+ require_relative 'code_object/base'
11
11
  require_relative 'dom/dom'
12
12
  require_relative 'processor'
13
13
 
@@ -47,9 +47,5 @@ def load_templates(template_path = nil)
47
47
  template_path = File.absolute_path(template_path)
48
48
  end
49
49
 
50
- require template_path + '/application.rb'
51
-
52
- # After loading all template files, we can include our default-template-helper
53
- Tasks::RenderTask.use Helper::Template if Helper.const_defined? :Template
54
-
50
+ require template_path + '/application.rb'
55
51
  end
@@ -43,6 +43,11 @@ module CodeObject
43
43
  def docs=(docstring)
44
44
  @docs = docstring.strip
45
45
  end
46
+
47
+ # can be overriden by subclasses
48
+ def display_name
49
+ @name
50
+ end
46
51
 
47
52
  protected
48
53
 
@@ -128,7 +128,7 @@ module Dom
128
128
  path = path.split(NS_SEP_STRING)
129
129
  child = @children[path.shift.to_sym]
130
130
 
131
- raise WrongPath.new(path) if child.nil?
131
+ return nil if child.nil?
132
132
 
133
133
  # decend recursive
134
134
  child[path.join(NS_SEP_STRING)]
@@ -2,15 +2,18 @@ require_relative '../renderer'
2
2
  require_relative '../dom/dom'
3
3
  require_relative '../helper/helper'
4
4
 
5
- module Tasks
5
+ module Generator
6
6
 
7
- class RenderTask < Renderer
7
+ class Generator < Renderer
8
8
 
9
- include Helper::Helper
10
-
11
9
  def initialize
12
10
  super(Configs.templates + configs(:templates), configs(:layout))
13
11
 
12
+ # include all Helpers
13
+ Helper.constants
14
+ .map { |c| Helper.const_get c }
15
+ .each { |mod| extend mod if mod.is_a? Module }
16
+
14
17
  # Set Global Context to Dom's root node
15
18
  @_context = Dom.root
16
19
  end
@@ -32,19 +35,22 @@ module Tasks
32
35
  configs(:description)
33
36
  end
34
37
 
38
+ # not neccesarily needed, because all Helpers are included by default
35
39
  def self.use(helper_module)
36
40
  include helper_module
37
- end
41
+ end
38
42
 
39
43
  def self.all
40
- Tasks.constants
41
- .map { |c| Tasks.const_get c }
42
- .select { |klass| klass.class == Class and klass.superclass == Tasks::RenderTask }
44
+ # Otherwise we don't get the global Generator-Module
45
+ gen_module = Object.const_get(:Generator)
46
+ gen_module.constants
47
+ .map { |c| gen_module.const_get c }
48
+ .select { |klass| klass.class == Class and klass.superclass == self }
43
49
  end
44
50
 
45
51
  protected
46
52
 
47
- # @group Task-Specification methods
53
+ # @group Generator-Specification methods
48
54
 
49
55
  def self.describe(desc)
50
56
  self.set_config(:description, desc.to_s)
@@ -4,12 +4,12 @@ require 'rdiscount'
4
4
 
5
5
  require_relative 'linker'
6
6
 
7
- # The Helpers are 'mixed' into your {Tasks::RenderTask} and therefore can be used in all
7
+ # The Helpers are 'mixed' into your {Generator::Generator generator} and therefore can be used in all
8
8
  # template-views.
9
9
  # If you are searching for a method and don't know, where it may be implemented i suggest the
10
10
  # following inheritence chain as your search-strategy:
11
11
  #
12
- # Helper::IncludedHelpers → Tasks::YourTaskTasks::RenderTask → Renderer
12
+ # Helper::IncludedHelpers → Generator::YourGeneratorGenerator::Generator → Renderer
13
13
  #
14
14
  # Somewhere at that chain you will find your desired function.
15
15
  module Helper
@@ -29,8 +29,7 @@ module Helper
29
29
  elsif target.is_a? CodeObject::Base
30
30
 
31
31
  if text.nil? and target.parent == context and context != Dom.root
32
- text = ".#{target.name}"
33
- text += "()" if target.is_a? CodeObject::Function
32
+ text = target.display_name
34
33
  elsif text.nil?
35
34
  text = target.qualified_name
36
35
  end
@@ -56,7 +55,11 @@ module Helper
56
55
  else
57
56
  # use context dependent resolving functionality as specified in {Tasks::RenderTask}
58
57
  obj = resolve target
59
- to_relative path_to obj unless obj.nil?
58
+ unless obj.nil?
59
+ to_relative path_to obj
60
+ else
61
+ nil
62
+ end
60
63
  end
61
64
 
62
65
  text ||= target
@@ -120,14 +123,5 @@ module Helper
120
123
  link_to(name, title)
121
124
  end
122
125
  end
123
-
124
- def link_on_page(object)
125
- if object.is_a? CodeObject::Function
126
- link_to "#method-#{object.name}", ".#{object.name}()"
127
- else
128
- link_to "#object-#{object.name}", ".#{object.name}"
129
- end
130
- end
131
- end
132
-
126
+ end
133
127
  end