docjs 0.1.2 → 0.1.3

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 (39) hide show
  1. data/README.md +7 -5
  2. data/bin/docjs +33 -8
  3. data/bin/docjs.rb +239 -0
  4. data/docjs.gemspec +2 -2
  5. data/lib/boot.rb +5 -3
  6. data/lib/code_object/base.rb +1 -0
  7. data/lib/code_object/function.rb +21 -37
  8. data/lib/code_object/object.rb +1 -1
  9. data/lib/helper/helper.rb +16 -3
  10. data/lib/helper/linker.rb +5 -2
  11. data/lib/parser/parser.rb +20 -6
  12. data/lib/token/container.rb +0 -1
  13. data/lib/token/handler.rb +46 -6
  14. data/lib/token/token.rb +3 -2
  15. data/templates/helpers/template.rb +15 -5
  16. data/templates/resources/css/application.css +65 -14
  17. data/templates/resources/js/application.js +33 -11
  18. data/templates/resources/js/regexpx.js +652 -0
  19. data/templates/resources/js/shBrushJScript.js +55 -0
  20. data/templates/resources/js/shCore.js +1596 -0
  21. data/templates/resources/scss/_header.scss +2 -1
  22. data/templates/resources/scss/_helpers.scss +6 -6
  23. data/templates/resources/scss/_highlighter.scss +70 -0
  24. data/templates/resources/scss/application.scss +8 -8
  25. data/templates/tokens/tokens.rb +55 -4
  26. data/templates/views/function/_detail.html.erb +1 -1
  27. data/templates/views/function/index.html.erb +16 -4
  28. data/templates/views/layout/application.html.erb +5 -5
  29. data/templates/views/layout/json.html.erb +3 -3
  30. data/templates/views/object/index.html.erb +3 -3
  31. data/templates/views/tokens/_default.html.erb +4 -2
  32. data/templates/views/tokens/_default_token.html.erb +2 -1
  33. data/templates/views/tokens/_example.html.erb +1 -1
  34. data/templates/views/tokens/_overload.html.erb +12 -0
  35. data/test/interactive.rb +5 -2
  36. data/test/js-files/core-doc.js +20 -12
  37. data/test/parser/intelligent_skip_until.rb +1 -1
  38. data/test/parser/parser.rb +3 -6
  39. metadata +8 -2
data/README.md CHANGED
@@ -1,12 +1,13 @@
1
1
  Doc.js
2
2
  ======
3
- Just a note: After total dataloss i have to rewrite the Readme's and Test's, so
4
- please be patient.
3
+ Bad news first: **You still have to write documentation**
4
+
5
+ Good news: **It will look awesome!!**
5
6
 
6
7
 
7
8
  Supported Ruby-Version
8
9
  ======================
9
- Currently **only > 1.9** is supported. I am working on 1.8.x, though this is not
10
+ Currently **only ruby > 1.9** is supported. I am working on supporting > 1.8.7, though this is not
10
11
  my target platform.
11
12
 
12
13
 
@@ -77,6 +78,7 @@ You will find the docs in the output-directory you have specified in your
77
78
  config-file.
78
79
 
79
80
 
80
- License
81
- =======
81
+ Legal Notice
82
+ ============
82
83
  docjs is released under MIT-License. See LICENSE.md for more information.
84
+ The used icons, are part of the legendary famfamfam-silk-iconset. (http://www.famfamfam.com/lab/icons/silk/)
data/bin/docjs CHANGED
@@ -47,7 +47,7 @@ class DocJs < Thor
47
47
  { :type => :string, :aliases => '-n', :default => "MyAppName" },
48
48
 
49
49
  :logfile =>
50
- { :type => :string, :aliases => '-lf', :default => 'docjs.log' },
50
+ { :type => :string, :aliases => '-lf' },
51
51
 
52
52
  :loglevel =>
53
53
  { :type => :string, :aliases => '-ll', :default => 'info' }
@@ -60,6 +60,7 @@ class DocJs < Thor
60
60
  setup_application configs
61
61
 
62
62
  # load application specific files
63
+ Logger.debug "Loading application-templates: #{Configs.templates + '/application.rb'}"
63
64
  require Configs.templates + '/application.rb'
64
65
 
65
66
  # Config Thor settings
@@ -85,16 +86,36 @@ class DocJs < Thor
85
86
 
86
87
 
87
88
 
88
- desc "tokens", "Lists all supported tokens"
89
- def tokens
90
- say "Supported tokens:"
91
- say Token::Handler.handlers.map{|k,v| " @#{k}" }.sort.join "\n"
89
+ desc "tokens TEMPLATE_PATH?", "Lists all supported tokens\nNeeds your TEMPLATE_PATH to include your own custom tokens. If TEMPLATE_PATH is ommitted, only the default-tokens will be shown"
90
+ set_options :details =>
91
+ { :type => :boolean, :default => false }
92
+ def tokens(template_path = nil)
93
+
94
+ unless template_path.nil?
95
+ require File.absolute_path(template_path) + '/application.rb'
96
+ else
97
+ require Configs.root + 'templates/application.rb'
98
+ end
99
+
100
+ say "Supported tokens:\n\n"
101
+ if options.details?
102
+ table = [%w(TOKEN AREA TEMPLATE DESCRIPTION)] + Token::Handler.handlers.map{|k,v| [":#{k}",v.area, v.template, v.description] }.sort
103
+ else
104
+ table = Token::Handler.handlers.map{|k,v| [":#{k}","# #{v.description}"] }.sort
105
+ end
106
+ print_table table, :ident => 2, :colwidth => 20
92
107
  end
93
108
 
94
109
 
95
110
 
96
- desc "tasks", "Lists all registered render-tasks"
97
- def tasks
111
+ desc "tasks TEMPLATE_PATH?", "Lists all registered render-tasks\nNeeds your TEMPLATE_PATH to include your own custom tokens. If TEMPLATE_PATH is ommitted, only the default-tokens will be shown"
112
+ def tasks(template_path = nil)
113
+ unless template_path.nil?
114
+ require File.absolute_path(template_path) + '/application.rb'
115
+ else
116
+ require Configs.root + 'templates/application.rb'
117
+ end
118
+
98
119
  say "Registered render-tasks:"
99
120
 
100
121
  task_table = Processor.render_tasks.map{|k,v| [":#{k}","# #{v.description}"] }.sort
@@ -104,7 +125,6 @@ class DocJs < Thor
104
125
 
105
126
 
106
127
 
107
- # @todo implement!
108
128
  desc "scaffold OUTPUT_DIR", "You can use scaffolding to get the templates and some basic ruby-files, that you will need to create your own templates"
109
129
  set_options :logfile =>
110
130
  { :type => :string, :aliases => '-lf', :default => 'jsdoc.log' },
@@ -177,6 +197,11 @@ class DocJs < Thor
177
197
  build['templates'] = ask ">"
178
198
  end
179
199
 
200
+ if not build['output']
201
+ say "\nWhere do you wan't your documentation generated to? Please enter a path", :bold
202
+ build['output'] = ask ">"
203
+ end
204
+
180
205
  if not build['loglevel']
181
206
  say "\nPlease specify the loglevel of your output: (error|warn|info|debug)", :bold
182
207
 
@@ -0,0 +1,239 @@
1
+ #!/usr/bin/ruby1.9
2
+ # We need pathname to make it work with sym-links
3
+ require 'pathname'
4
+ require Pathname.new(__FILE__).realpath + '../../lib/boot'
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
+ # configure approot
17
+ Configs.set :root => Pathname.new(__FILE__).realpath + '../..'
18
+
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
25
+ #
26
+ # @note options declared in a build.yml will override command-line ones
27
+ # @todo command line option to copy all templates to specified directory like
28
+ # jsdoc dump_templates ../templates/original
29
+ class DocJs < Thor
30
+
31
+ include Thor::Actions
32
+
33
+ desc "CONFIG_FILE", "Starts documentation process"
34
+ set_options :files =>
35
+ { :type => :array, :aliases => '-f', :default => [], :required => true },
36
+
37
+ :docs =>
38
+ { :type => :array, :aliases => '-d', :default => ['README.md'], :required => true },
39
+
40
+ :output =>
41
+ { :type => :string, :aliases => '-o', :default => 'out' },
42
+
43
+ :templates =>
44
+ { :type => :string, :aliases => '-t', :default => Configs.root + 'templates' },
45
+
46
+ :appname =>
47
+ { :type => :string, :aliases => '-n', :default => "MyAppName" },
48
+
49
+ :logfile =>
50
+ { :type => :string, :aliases => '-lf' },
51
+
52
+ :loglevel =>
53
+ { :type => :string, :aliases => '-ll', :default => 'info' }
54
+
55
+ def docjs(config_file = nil)
56
+ # @see Thor#merge_options
57
+ configs = config_file ? merge_options(options, config_file) : options
58
+
59
+ begin
60
+ setup_application configs
61
+
62
+ # load application specific files
63
+ Logger.debug "Loading application-templates: #{Configs.templates + '/application.rb'}"
64
+ require Configs.templates + '/application.rb'
65
+
66
+ # Config Thor settings
67
+ DocJs.source_root(Configs.templates)
68
+ self.destination_root = Configs.output
69
+
70
+ Processor.prepare_documents
71
+ # let's check our Documents tree
72
+ Dom.docs.print_tree
73
+
74
+ # the configs are now available through our Configs-module
75
+ Processor.process_and_render
76
+
77
+ Logger.info "Copying template resources to output"
78
+ directory 'resources/img', './img' # copy resources
79
+ directory 'resources/css', './css'
80
+ directory 'resources/js', './js'
81
+
82
+ rescue Exception => error
83
+ Logger.error error.message + "\n" + error.backtrace.map{|l| " #{l}" }.join("\n")
84
+ end
85
+ end
86
+
87
+
88
+
89
+ desc "tokens TEMPLATE_PATH?", "Lists all supported tokens\nNeeds your TEMPLATE_PATH to include your own custom tokens. If TEMPLATE_PATH is ommitted, only the default-tokens will be shown"
90
+ set_options :details =>
91
+ { :type => :boolean, :default => false }
92
+ def tokens(template_path = nil)
93
+
94
+ unless template_path.nil?
95
+ require File.absolute_path(template_path) + '/application.rb'
96
+ else
97
+ require Configs.root + 'templates/application.rb'
98
+ end
99
+
100
+ say "Supported tokens:\n\n"
101
+ if options.details?
102
+ table = [%w(TOKEN AREA TEMPLATE DESCRIPTION)] + Token::Handler.handlers.map{|k,v| [":#{k}",v.area, v.template, v.description] }.sort
103
+ else
104
+ table = Token::Handler.handlers.map{|k,v| [":#{k}","# #{v.description}"] }.sort
105
+ end
106
+ print_table table, :ident => 2, :colwidth => 20
107
+ end
108
+
109
+
110
+
111
+ desc "tasks TEMPLATE_PATH?", "Lists all registered render-tasks\nNeeds your TEMPLATE_PATH to include your own custom tokens. If TEMPLATE_PATH is ommitted, only the default-tokens will be shown"
112
+ def tasks(template_path = nil)
113
+ unless template_path.nil?
114
+ require File.absolute_path(template_path) + '/application.rb'
115
+ else
116
+ require Configs.root + 'templates/application.rb'
117
+ end
118
+
119
+ say "Registered render-tasks:"
120
+
121
+ task_table = Processor.render_tasks.map{|k,v| [":#{k}","# #{v.description}"] }.sort
122
+
123
+ print_table task_table, :ident => 2, :colwidth => 20
124
+ end
125
+
126
+
127
+
128
+ desc "scaffold OUTPUT_DIR", "You can use scaffolding to get the templates and some basic ruby-files, that you will need to create your own templates"
129
+ set_options :logfile =>
130
+ { :type => :string, :aliases => '-lf', :default => 'jsdoc.log' },
131
+
132
+ :loglevel =>
133
+ { :type => :string, :aliases => '-ll', :default => 'info' }
134
+ def scaffold(output_dir)
135
+
136
+ setup_application options.merge({
137
+ :output => output_dir,
138
+ :templates => output_dir
139
+ })
140
+
141
+ # Setup Thor paths
142
+ DocJs.source_root(Configs.root)
143
+ self.destination_root = Configs.output
144
+
145
+ yes_no = "(y|n)"
146
+
147
+ Logger.info "We need some information from you, to customize the scaffolding process to your needs."
148
+ if yes? "Do you wan't to generate a build.yml? #{yes_no}"
149
+ configure(Configs.wdir + '/build.yml', {
150
+ 'templates' => output_dir,
151
+ 'output' => 'docs',
152
+ 'logfile' => 'logfile.log',
153
+ 'loglevel' => 'info'
154
+ })
155
+ end
156
+
157
+ # Work with the answers
158
+ Logger.info "Copying the template files to #{Configs.templates}"
159
+ directory 'templates', Configs.templates # copy templates and resources
160
+
161
+ Logger.info "Copying the included *.rb files to #{Configs.includes}"
162
+ end
163
+
164
+ desc "configure [NEW_CONFIGFILE]", "Helps you creating your build.yml to start off with doc.js"
165
+ def configure(output_file = "build.yml", preconfigured = {})
166
+
167
+ build = {
168
+ 'files' => [],
169
+ 'docs' => []
170
+ }
171
+
172
+ build.merge! preconfigured
173
+
174
+ say "\nPlease enter the name of your App", :bold
175
+ build['appname'] = ask ">"
176
+
177
+ say "\nPlease enter the javascript-files you want to integrate into your documentation", :bold
178
+ say "(You will be asked multiple times, unless your answer is empty) You also can specify a file-matching pattern, foo/**/*.js"
179
+
180
+ while true do
181
+ answer = ask ">"
182
+ break if answer == ""
183
+ build['files'] << answer
184
+ end
185
+
186
+ say "\nPlease enter the markdown-documentation-files you want to integrate into your documentation", :bold
187
+ say "(You will be asked multiple times, unless your answer is empty) You also can specify a file-matching pattern, like docs/*.md"
188
+
189
+ while true do
190
+ answer = ask ">"
191
+ break if answer == ""
192
+ build['docs'] << answer
193
+ end
194
+
195
+ if not build['templates'] and yes? "Are you using your own templates?"
196
+ say "\nPlease enter the path to your templates", :bold
197
+ build['templates'] = ask ">"
198
+ end
199
+
200
+ if not build['output']
201
+ say "\nWhere do you wan't your documentation generated to? Please enter a path", :bold
202
+ build['output'] = ask ">"
203
+ end
204
+
205
+ if not build['loglevel']
206
+ say "\nPlease specify the loglevel of your output: (error|warn|info|debug)", :bold
207
+
208
+ while true do
209
+ answer = ask ">"
210
+ if %w(error warn info debug).include? answer
211
+ build['loglevel'] = answer
212
+ break
213
+ end
214
+ say "\nThe answer you've given is not one of (error|warn|info|debug). Please try again", :bold
215
+ end
216
+ end
217
+
218
+ if not build['logfile'] and yes? "Do you wan't to save your logs to a file?"
219
+ say "\nPlease enter the path to your logfile", :bold
220
+ build['logfile'] = ask ">"
221
+ end
222
+
223
+ # answers[:scss_build] = yes? "Do you wan't to integrate SCSS into your build-process? #{yes_no}"
224
+
225
+ # maybe ask some more information to generate build.yml
226
+ create_file output_file, build.to_yaml
227
+ end
228
+
229
+
230
+ end
231
+
232
+ if ARGV.size == 0
233
+ ARGV.unshift 'help'
234
+
235
+ elsif not (ARGV.size > 0 and DocJs.method_defined?(ARGV.first))
236
+ ARGV.unshift 'docjs'
237
+ end
238
+
239
+ DocJs.start(ARGV)
@@ -4,8 +4,8 @@ Gem::Specification.new do |s|
4
4
 
5
5
 
6
6
  s.name = 'docjs'
7
- s.version = '0.1.2'
8
- s.date = '2011-06-07'
7
+ s.version = '0.1.3'
8
+ s.date = '2011-06-16'
9
9
  s.summary = "Javascript Documentation Generator"
10
10
  s.description = "Create beautyful 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"
@@ -6,6 +6,7 @@ require_relative 'thor'
6
6
  require_relative 'logger'
7
7
  require_relative 'configs'
8
8
  require_relative 'parser/parser'
9
+ require_relative 'token/handler'
9
10
  require_relative 'code_object/function'
10
11
  require_relative 'dom/dom'
11
12
  require_relative 'processor'
@@ -13,8 +14,8 @@ require_relative 'processor'
13
14
  def setup_application(options = {})
14
15
 
15
16
  # initialize Logger
16
- Logger.setup :logfile => File.expand_path(options[:logfile], Dir.pwd),
17
- :level => (options[:loglevel]).to_sym
17
+ Logger.setup :logfile => (options[:logfile] && File.expand_path(options[:logfile], Dir.pwd)),
18
+ :level => (options[:loglevel] || :info).to_sym
18
19
 
19
20
  Logger.info "Setting up Application"
20
21
 
@@ -31,4 +32,5 @@ def setup_application(options = {})
31
32
  Logger.debug "App Root: #{Configs.root}"
32
33
  Logger.debug "Working Dir: #{Configs.wdir}"
33
34
  Logger.debug "Output Dir: #{Configs.output}"
34
- end
35
+ Logger.debug "Template Dir: #{Configs.templates}"
36
+ end
@@ -1,5 +1,6 @@
1
1
  # ../data.img#1787927:1
2
2
  require_relative '../token/container'
3
+ require_relative '../token/handler'
3
4
  require_relative '../dom/dom'
4
5
  require_relative '../parser/meta_container'
5
6
 
@@ -15,64 +15,48 @@ module CodeObject
15
15
  # @todo i need a @prototype token in object
16
16
  def prototype
17
17
  children[:prototype]
18
- end
18
+ end
19
19
 
20
20
  end
21
21
 
22
22
  end
23
23
 
24
24
  CodeObject::Type.register :function, CodeObject::Function
25
- Token::Handler.register :function, :handler => :noop, :area => :none
26
25
 
27
- # @todo rewrite as default-handler, because this looks a little distracting
28
26
  module Token::Handler
29
27
 
30
- # @todo maybe allow multipled nested layers of params by parsing them recursivly
31
- register :param, :area => :body do |tokenklass, content|
28
+ register :function,
29
+ :handler => :noop,
30
+ :area => :none,
31
+ :description => "Type-Token to categorize all kind of JavaScript-Functions"
32
+
33
+
34
+ # We want to support either named-typed-tokens like
35
+ # @param [Foo] barname some description
36
+ #
37
+ # or multiline tokens like:
38
+ # @param configs
39
+ # Some configuration Object with following properties:
40
+ # [String] foo some string
41
+ # [Bar] bar and another one
42
+ #
43
+ # @note this can also be utilized for JavaScript-Event-Triggers or Callbacks with Parameters
44
+ register :param, :area => :none, :description => "Token for Function-Parameters like '@param [String] name your name'" do |tokenklass, content|
32
45
 
33
- # We want to support either named-typed-tokens like
34
- # @param [Foo] barname some description
35
- #
36
- # or multiline tokens like:
37
- # @param configs
38
- # [String] foo some string
39
- # [Bar] bar and another one
40
- #
41
- #
42
- # if out content matches something with `[` at the beginning, it seems to be
43
- # a normal named-typed-token
44
- # it's a little tricky because we still want to allow multiline descriptions of each param
45
- def parse_token(content)
46
- typestring, name, content = TOKEN_W_TYPE_NAME.match(content).captures
47
- types = typestring.split /,\s*/
48
- Token::Token::ParamToken.new(:name => name, :types => types, :content => content)
49
- end
50
-
51
46
  # it's @param [String] name some content
52
47
  if content.lines.first.match TOKEN_W_TYPE_NAME
53
- self.add_token parse_token(content)
48
+ self.add_token Token::Handler.apply(:typed_with_name, Token::Token::ParamToken, content)
54
49
 
55
50
  # it maybe a multiline
56
51
  else
57
- lines = content.split(/\n/)
58
- name = lines.shift.strip
59
- types = ['PropertyObject']
60
-
61
- # now split line at opening bracket, not at line-break to enable multiline properties
62
- children = lines.join("\n").strip.gsub(/\s+\[/, "<--SPLIT_HERE-->[").split("<--SPLIT_HERE-->")
63
-
64
- children.map! do |child|
65
- parse_token(child)
66
- end
67
-
68
- self.add_token tokenklass.new(:name => name, :types => types, :children => children)
52
+ self.add_token Token::Handler.apply(:named_nested_shorthand, Token::Token::ParamToken, content)
69
53
  end
70
54
  end
71
55
 
72
56
 
73
57
  end
74
58
 
75
- Token::Handler.register :return, :handler => :typed
59
+ Token::Handler.register :return, :handler => :typed, :area => :none, :description => "Returnvalue of a Function"
76
60
  Token::Handler.register :throws, :handler => :typed
77
61
 
78
62
  # MethodAlias