docjs 0.1.3 → 0.1.4

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/bin/docjs CHANGED
@@ -23,9 +23,7 @@ Configs.set :root => Pathname.new(__FILE__).realpath + '../..'
23
23
  # 4. turn into objects and save to dom
24
24
  # 5. render templates
25
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
26
+ # @note options declared in a docjs.yml will override command-line ones
29
27
  class DocJs < Thor
30
28
 
31
29
  include Thor::Actions
@@ -51,118 +49,45 @@ class DocJs < Thor
51
49
 
52
50
  :loglevel =>
53
51
  { :type => :string, :aliases => '-ll', :default => 'info' }
54
-
55
52
  def docjs(config_file = nil)
53
+
54
+ # Process the given command-line and yml-options
56
55
  # @see Thor#merge_options
57
56
  configs = config_file ? merge_options(options, config_file) : options
58
57
 
59
58
  begin
59
+ # Setup Logger and Configs
60
60
  setup_application configs
61
61
 
62
- # load application specific files
63
- Logger.debug "Loading application-templates: #{Configs.templates + '/application.rb'}"
64
- require Configs.templates + '/application.rb'
62
+ # Load application specific files
63
+ Logger.info "Loading Application-Templates"
64
+ load_templates
65
65
 
66
- # Config Thor settings
66
+ # Config Thor path-settings
67
67
  DocJs.source_root(Configs.templates)
68
68
  self.destination_root = Configs.output
69
69
 
70
+ # Process specified docs and add them to dom-tree
70
71
  Processor.prepare_documents
71
- # let's check our Documents tree
72
- Dom.docs.print_tree
73
72
 
74
- # the configs are now available through our Configs-module
73
+ # Kickoff js-file-processing and template-rendering!
75
74
  Processor.process_and_render
76
75
 
76
+ # Finally copy all
77
77
  Logger.info "Copying template resources to output"
78
78
  directory 'resources/img', './img' # copy resources
79
79
  directory 'resources/css', './css'
80
80
  directory 'resources/js', './js'
81
-
81
+
82
82
  rescue Exception => error
83
83
  Logger.error error.message + "\n" + error.backtrace.map{|l| " #{l}" }.join("\n")
84
84
  end
85
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
86
 
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
87
+
163
88
 
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 = {})
89
+ desc "configure [NEW_CONFIGFILE]", "Helps you creating your docjs.yml to start off with doc.js"
90
+ def configure(output_file = "docjs.yml", preconfigured = {})
166
91
 
167
92
  build = {
168
93
  'files' => [],
@@ -225,8 +150,76 @@ class DocJs < Thor
225
150
  # maybe ask some more information to generate build.yml
226
151
  create_file output_file, build.to_yaml
227
152
  end
153
+
154
+
155
+
156
+ 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"
157
+ set_options :logfile =>
158
+ { :type => :string, :aliases => '-lf', :default => 'jsdoc.log' },
159
+
160
+ :loglevel =>
161
+ { :type => :string, :aliases => '-ll', :default => 'info' }
162
+ def scaffold(output_dir)
163
+
164
+ setup_application options.merge({
165
+ :output => output_dir,
166
+ :templates => output_dir
167
+ })
168
+
169
+ # Setup Thor paths
170
+ DocJs.source_root(Configs.root)
171
+ self.destination_root = Configs.output
172
+
173
+ yes_no = "(y|n)"
174
+
175
+ Logger.info "We need some information from you, to customize the scaffolding process to your needs."
176
+ if yes? "Do you wan't to generate a docjs.yml? #{yes_no}"
177
+ configure(Configs.wdir + '/docjs.yml', {
178
+ 'templates' => output_dir,
179
+ 'output' => 'docs',
180
+ 'logfile' => 'logfile.log',
181
+ 'loglevel' => 'info'
182
+ })
183
+ end
184
+
185
+ # Work with the answers
186
+ Logger.info "Copying the template files to #{Configs.templates}"
187
+ directory 'templates', Configs.templates # copy templates and resources
188
+
189
+ Logger.info "Copying the included *.rb files to #{Configs.includes}"
190
+ end
228
191
 
229
192
 
193
+
194
+ 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"
195
+ set_options :details =>
196
+ { :type => :boolean, :default => false }
197
+ def tokens(template_path = nil)
198
+
199
+ load_templates template_path
200
+
201
+ say "Supported tokens:\n\n"
202
+ if options.details?
203
+ table = [%w(TOKEN AREA TEMPLATE DESCRIPTION)] + Token::Handler.handlers.map{|k,v| [":#{k}",v.area, v.template, v.description] }.sort
204
+ else
205
+ table = Token::Handler.handlers.map{|k,v| [":#{k}","# #{v.description}"] }.sort
206
+ end
207
+ print_table table, :ident => 2, :colwidth => 20
208
+ end
209
+
210
+
211
+
212
+ 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"
213
+ def tasks(template_path = nil)
214
+
215
+ load_templates template_path
216
+
217
+ say "Registered render-tasks:"
218
+
219
+ task_table = Tasks::RenderTask.all.map{|task| ["#{task.name}","# #{task.description}"] }.sort
220
+
221
+ print_table task_table, :ident => 2, :colwidth => 20
222
+ end
230
223
  end
231
224
 
232
225
  if ARGV.size == 0
@@ -236,4 +229,4 @@ elsif not (ARGV.size > 0 and DocJs.method_defined?(ARGV.first))
236
229
  ARGV.unshift 'docjs'
237
230
  end
238
231
 
239
- DocJs.start(ARGV)
232
+ DocJs.start(ARGV)
@@ -23,9 +23,7 @@ Configs.set :root => Pathname.new(__FILE__).realpath + '../..'
23
23
  # 4. turn into objects and save to dom
24
24
  # 5. render templates
25
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
26
+ # @note options declared in a docjs.yml will override command-line ones
29
27
  class DocJs < Thor
30
28
 
31
29
  include Thor::Actions
@@ -51,118 +49,45 @@ class DocJs < Thor
51
49
 
52
50
  :loglevel =>
53
51
  { :type => :string, :aliases => '-ll', :default => 'info' }
54
-
55
52
  def docjs(config_file = nil)
53
+
54
+ # Process the given command-line and yml-options
56
55
  # @see Thor#merge_options
57
56
  configs = config_file ? merge_options(options, config_file) : options
58
57
 
59
58
  begin
59
+ # Setup Logger and Configs
60
60
  setup_application configs
61
61
 
62
- # load application specific files
63
- Logger.debug "Loading application-templates: #{Configs.templates + '/application.rb'}"
64
- require Configs.templates + '/application.rb'
62
+ # Load application specific files
63
+ Logger.info "Loading Application-Templates"
64
+ load_templates
65
65
 
66
- # Config Thor settings
66
+ # Config Thor path-settings
67
67
  DocJs.source_root(Configs.templates)
68
68
  self.destination_root = Configs.output
69
69
 
70
+ # Process specified docs and add them to dom-tree
70
71
  Processor.prepare_documents
71
- # let's check our Documents tree
72
- Dom.docs.print_tree
73
72
 
74
- # the configs are now available through our Configs-module
73
+ # Kickoff js-file-processing and template-rendering!
75
74
  Processor.process_and_render
76
75
 
76
+ # Finally copy all
77
77
  Logger.info "Copying template resources to output"
78
78
  directory 'resources/img', './img' # copy resources
79
79
  directory 'resources/css', './css'
80
80
  directory 'resources/js', './js'
81
-
81
+
82
82
  rescue Exception => error
83
83
  Logger.error error.message + "\n" + error.backtrace.map{|l| " #{l}" }.join("\n")
84
84
  end
85
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
86
 
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
87
+
163
88
 
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 = {})
89
+ desc "configure [NEW_CONFIGFILE]", "Helps you creating your docjs.yml to start off with doc.js"
90
+ def configure(output_file = "docjs.yml", preconfigured = {})
166
91
 
167
92
  build = {
168
93
  'files' => [],
@@ -225,8 +150,76 @@ class DocJs < Thor
225
150
  # maybe ask some more information to generate build.yml
226
151
  create_file output_file, build.to_yaml
227
152
  end
153
+
154
+
155
+
156
+ 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"
157
+ set_options :logfile =>
158
+ { :type => :string, :aliases => '-lf', :default => 'jsdoc.log' },
159
+
160
+ :loglevel =>
161
+ { :type => :string, :aliases => '-ll', :default => 'info' }
162
+ def scaffold(output_dir)
163
+
164
+ setup_application options.merge({
165
+ :output => output_dir,
166
+ :templates => output_dir
167
+ })
168
+
169
+ # Setup Thor paths
170
+ DocJs.source_root(Configs.root)
171
+ self.destination_root = Configs.output
172
+
173
+ yes_no = "(y|n)"
174
+
175
+ Logger.info "We need some information from you, to customize the scaffolding process to your needs."
176
+ if yes? "Do you wan't to generate a docjs.yml? #{yes_no}"
177
+ configure(Configs.wdir + '/docjs.yml', {
178
+ 'templates' => output_dir,
179
+ 'output' => 'docs',
180
+ 'logfile' => 'logfile.log',
181
+ 'loglevel' => 'info'
182
+ })
183
+ end
184
+
185
+ # Work with the answers
186
+ Logger.info "Copying the template files to #{Configs.templates}"
187
+ directory 'templates', Configs.templates # copy templates and resources
188
+
189
+ Logger.info "Copying the included *.rb files to #{Configs.includes}"
190
+ end
228
191
 
229
192
 
193
+
194
+ 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"
195
+ set_options :details =>
196
+ { :type => :boolean, :default => false }
197
+ def tokens(template_path = nil)
198
+
199
+ load_templates template_path
200
+
201
+ say "Supported tokens:\n\n"
202
+ if options.details?
203
+ table = [%w(TOKEN AREA TEMPLATE DESCRIPTION)] + Token::Handler.handlers.map{|k,v| [":#{k}",v.area, v.template, v.description] }.sort
204
+ else
205
+ table = Token::Handler.handlers.map{|k,v| [":#{k}","# #{v.description}"] }.sort
206
+ end
207
+ print_table table, :ident => 2, :colwidth => 20
208
+ end
209
+
210
+
211
+
212
+ 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"
213
+ def tasks(template_path = nil)
214
+
215
+ load_templates template_path
216
+
217
+ say "Registered render-tasks:"
218
+
219
+ task_table = Tasks::RenderTask.all.map{|task| ["#{task.name}","# #{task.description}"] }.sort
220
+
221
+ print_table task_table, :ident => 2, :colwidth => 20
222
+ end
230
223
  end
231
224
 
232
225
  if ARGV.size == 0
@@ -236,4 +229,4 @@ elsif not (ARGV.size > 0 and DocJs.method_defined?(ARGV.first))
236
229
  ARGV.unshift 'docjs'
237
230
  end
238
231
 
239
- DocJs.start(ARGV)
232
+ 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.3'
8
- s.date = '2011-06-16'
7
+ s.version = '0.1.4'
8
+ s.date = '2011-06-17'
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"
@@ -33,4 +33,23 @@ def setup_application(options = {})
33
33
  Logger.debug "Working Dir: #{Configs.wdir}"
34
34
  Logger.debug "Output Dir: #{Configs.output}"
35
35
  Logger.debug "Template Dir: #{Configs.templates}"
36
+ end
37
+
38
+ def load_templates(template_path = nil)
39
+
40
+ if template_path.nil? and Configs.templates
41
+ template_path = Configs.templates
42
+
43
+ elsif template_path.nil?
44
+ template_path =( Configs.root + 'templates').to_path
45
+
46
+ else
47
+ template_path = File.absolute_path(template_path)
48
+ end
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
+
36
55
  end
@@ -1,4 +1,3 @@
1
- # ../data.img#1787927:1
2
1
  require_relative '../token/container'
3
2
  require_relative '../token/handler'
4
3
  require_relative '../dom/dom'
@@ -10,6 +9,16 @@ require_relative '../parser/meta_container'
10
9
  #
11
10
  module CodeObject
12
11
 
12
+ # Find all CodeObject-Types, that inherit from Base
13
+ # @return [Hash] like {:object => CodeObject::Object, :function => CodeObject::Function }
14
+ def self.all_types
15
+ Hash[self.constants
16
+ .map { |c| [c.to_s.downcase.to_sym, self.const_get(c)] }
17
+ .select { |klass| klass[1].class == Class and klass[1].ancestors.include? Base }
18
+ ]
19
+ end
20
+
21
+
13
22
  class Base
14
23
 
15
24
  include Token::Container
@@ -34,7 +43,7 @@ module CodeObject
34
43
  def docs=(docstring)
35
44
  @docs = docstring.strip
36
45
  end
37
-
46
+
38
47
  protected
39
48
 
40
49
  # This is a Helpermethod, which can be used in subclasses like CodeObject::Function
@@ -1,12 +1,10 @@
1
- # ../data.img#1769990:1
2
- require_relative 'function'
3
1
  require_relative 'exceptions'
4
- require_relative 'type'
5
2
 
6
3
  module CodeObject
7
4
 
8
-
9
5
  # here the dependencies to {Dom::Node} and {Parser::Comment} should be described
6
+ #
7
+ # Converts a comment to a code_object and therefor is included in {Parser::Comment}
10
8
  module Converter
11
9
 
12
10
  attr_reader :code_object, :path
@@ -14,7 +12,7 @@ module CodeObject
14
12
  def to_code_object
15
13
 
16
14
  # 1. Create a new CodeObject from Type-Token
17
- @code_object = Type.create_matching_object(@tokenlines) or return nil
15
+ @code_object = find_type_for(@tokenlines) or return nil
18
16
 
19
17
  # join all documentation-contents
20
18
  @code_object.docs = @doclines.join ''
@@ -34,7 +32,6 @@ module CodeObject
34
32
  end
35
33
 
36
34
  protected
37
-
38
35
 
39
36
  # recursivly process all child-tokens
40
37
  def convert_children
@@ -43,6 +40,27 @@ module CodeObject
43
40
  yield(code_object) unless code_object.nil?
44
41
  end
45
42
  end
43
+
44
+
45
+ def find_type_for(tokenlines)
46
+
47
+ # all_types returns a hash like {:object => CodeObject::Object ...}
48
+ available_types = CodeObject.all_types
46
49
 
50
+ types = tokenlines.select {|t| available_types.has_key? t.token }
51
+
52
+ if types.size > 1
53
+ raise CodeObject::MultipleTypeDeclarations.new, "Wrong number of TypeDeclarations: #{types}"
54
+ elsif types.size == 0
55
+ # it's not possible to create instance
56
+ return nil
57
+ end
58
+
59
+ type = types.first
60
+
61
+ # Get Class and instantiate it with content
62
+ klass = available_types[type.token]
63
+ klass.new(type.content)
64
+ end
47
65
  end
48
- end
66
+ end
@@ -1,4 +1,3 @@
1
- # ../data.img#1858563:1
2
1
  require_relative 'object'
3
2
 
4
3
  module CodeObject
@@ -21,48 +20,42 @@ module CodeObject
21
20
 
22
21
  end
23
22
 
24
- CodeObject::Type.register :function, CodeObject::Function
25
-
26
- module Token::Handler
27
-
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|
45
-
46
- # it's @param [String] name some content
47
- if content.lines.first.match TOKEN_W_TYPE_NAME
48
- self.add_token Token::Handler.apply(:typed_with_name, Token::Token::ParamToken, content)
49
-
50
- # it maybe a multiline
51
- else
52
- self.add_token Token::Handler.apply(:named_nested_shorthand, Token::Token::ParamToken, content)
53
- end
54
- end
55
-
56
-
23
+ Token::Handler.register :function,
24
+ :handler => :noop,
25
+ :area => :none,
26
+ :description => "Type-Token to categorize all kind of JavaScript-Functions"
27
+
28
+
29
+ # We want to support either named-typed-tokens like
30
+ # @param [Foo] barname some description
31
+ #
32
+ # or multiline tokens like:
33
+ # @param configs
34
+ # Some configuration Object with following properties:
35
+ # [String] foo some string
36
+ # [Bar] bar and another one
37
+ #
38
+ # @note this can also be utilized for JavaScript-Event-Triggers or Callbacks with Parameters
39
+ Token::Handler.register :param, :area => :none, :description => "Token for Function-Parameters like '@param [String] name your name'" do |tokenklass, content|
40
+
41
+ # it's @param [String] name some content
42
+ if content.lines.first.match Token::Handler::TOKEN_W_TYPE_NAME
43
+ self.add_token Token::Handler.apply(:typed_with_name, Token::Token::ParamToken, content)
44
+
45
+ # it maybe a multiline
46
+ else
47
+ self.add_token Token::Handler.apply(:named_nested_shorthand, Token::Token::ParamToken, content)
48
+ end
57
49
  end
58
50
 
51
+
59
52
  Token::Handler.register :return, :handler => :typed, :area => :none, :description => "Returnvalue of a Function"
60
53
  Token::Handler.register :throws, :handler => :typed
61
54
 
62
55
  # MethodAlias
63
- CodeObject::Type.register :method, CodeObject::Function
56
+ class CodeObject::Method < CodeObject::Function; end
64
57
  Token::Handler.register :method, :handler => :noop, :area => :none
65
58
 
66
59
  # @constructor Foo.bar
67
- CodeObject::Type.register :constructor, CodeObject::Function
60
+ class CodeObject::Constructor < CodeObject::Function; end
68
61
  Token::Handler.register(:constructor) { |token, content| @constructor = true }
@@ -1,6 +1,4 @@
1
- # ../data.img#1858561:1
2
1
  require_relative 'base'
3
- require_relative 'type'
4
2
 
5
3
  module CodeObject
6
4
 
@@ -12,7 +10,5 @@ module CodeObject
12
10
 
13
11
  end
14
12
 
15
- CodeObject::Type.register :object, CodeObject::Object
16
13
  Token::Handler.register :object, :handler => :noop, :area => :none
17
-
18
14
  Token::Handler.register :prop, :handler => :typed_with_name
@@ -1,4 +1,3 @@
1
- # ../data.img#1811391:1 && #1811396:1
2
1
  require_relative 'no_doc'
3
2
  require_relative 'exceptions'
4
3
 
@@ -1,5 +1,5 @@
1
- # ../data.img#1811401:1
2
1
  require_relative 'node'
2
+
3
3
  module Dom
4
4
 
5
5
  # NoDoc is used by {Dom} and {Dom::Node} to preserve the correct hierachy of
@@ -1,4 +1,3 @@
1
- # ../data.img#1780307:3
2
1
  require_relative 'dom'
3
2
  require_relative 'exceptions'
4
3
 
@@ -1,7 +1,6 @@
1
- # ../data.img#1800236:1
2
1
  require 'pathname'
3
- require 'rdiscount'
4
2
  require 'cgi'
3
+ require 'rdiscount'
5
4
 
6
5
  require_relative 'linker'
7
6
 
@@ -1,4 +1,3 @@
1
- # ../data.img#1781829:1
2
1
  require_relative 'meta_container'
3
2
  require_relative '../code_object/converter'
4
3
 
@@ -1,4 +1,3 @@
1
- # ../data.img#1799299:1
2
1
  require_relative 'comment'
3
2
  require_relative 'exceptions'
4
3
 
@@ -1,4 +1,3 @@
1
- # ../data.img#1772248:1
2
1
  module Parser
3
2
 
4
3
  # is included by {CodeObject::Base} and {Parser::Comment}
@@ -1,4 +1,3 @@
1
- # ../data.img#1869414:2
2
1
  require 'strscan'
3
2
  require_relative 'comment_parser'
4
3
 
@@ -4,15 +4,7 @@ require_relative 'tasks/render_task'
4
4
  require_relative 'document/document'
5
5
 
6
6
  module Processor
7
-
8
- RenderTask = Struct.new :name, :description, :block
9
- @@render_tasks = {}
10
7
 
11
- # Accessor Method for RenderTasks
12
- def self.render_tasks
13
- @@render_tasks
14
- end
15
-
16
8
  # @group Combined Stages
17
9
 
18
10
  def self.process_and_render
@@ -71,22 +63,9 @@ module Processor
71
63
  # - files: converts specified markdown files and renders them
72
64
  #
73
65
  def self.perform_all_tasks
74
- perform_tasks @@render_tasks.keys
66
+ Tasks::RenderTask.all.each { |task| task.new.perform }
75
67
  end
76
68
 
77
- def self.perform_tasks(tasks)
78
-
79
- tasks = [tasks] unless tasks.is_a? Array
80
-
81
- tasks.each do |task|
82
- task = task.to_sym
83
- raise Exception, "No render-task registered with name '#{task}'" unless @@render_tasks.has_key? task
84
-
85
- Logger.debug "Rendering task '#{task}'"
86
- @@render_tasks[task].new.perform
87
- end
88
- end
89
-
90
69
  # @group Stage #4 - Document Processor
91
70
 
92
71
  def self.prepare_documents
@@ -105,19 +84,5 @@ module Processor
105
84
  # The docs can be accessed via Dom later on
106
85
  end
107
86
  end
108
-
109
-
110
-
111
- # @group RenderTask-Setup
112
-
113
- def self.register_render_task(name, klass)
114
- @@render_tasks[name.to_sym] = klass
115
- end
116
-
117
- def self.unregister_render_task(name)
118
- @@render_tasks.delete(name.to_sym)
119
- end
120
-
121
-
122
-
87
+
123
88
  end
@@ -1,4 +1,3 @@
1
- # ../data.img#1783836:1
2
1
  require 'erb'
3
2
  require 'fileutils'
4
3
 
@@ -9,10 +8,10 @@ class Renderer
9
8
  @_layout = layout
10
9
  end
11
10
 
12
- # Teilweise aus rails...
13
- # @todo better error-handling with partial and layout context information!!!
11
+ # Pretty much inspired by Ruby on Rails
14
12
  def render(opt = nil, extra_options = {})
15
13
 
14
+ # Prepare Options
16
15
  if opt.nil?
17
16
  opt = { :layout => @_layout }
18
17
 
@@ -27,41 +26,9 @@ class Renderer
27
26
  end
28
27
 
29
28
  if opt[:partial]
30
-
31
- # add underscore to last element of foo/bar/baz
32
- parts = opt[:partial].split('/')
33
- parts[-1] = "_"+parts.last
29
+ render_partial opt
34
30
 
35
- begin
36
- template_file = File.read path_to_template(parts.join('/'))
37
- rescue Exception
38
- raise "Could not find Partial '#{opt[:partial]}'"
39
- end
40
- if opt[:collection]
41
-
42
- partial_name = opt[:partial].split('/').last
43
-
44
- opt[:collection].map { |item|
45
- define_singleton_method(partial_name) { item }
46
- ERB.new(template_file).result(binding)
47
- }.join "\n"
48
- else
49
-
50
- # If there are locals we have to save our instance binding, otherwise we will store our
51
- # newly created local-variables in the blockcontext of each_pair
52
- # values has to be defined explicitly to be overridden by the block and still available inside of eval
53
- if opt[:locals]
54
- value = nil
55
- instance_context = binding
56
- opt[:locals].each_pair do |local, value|
57
- Logger.warn("Please change your partial-name or local binding, because #{local} is already set in this context.") if respond_to? local
58
- define_singleton_method(local) { value }
59
- end
60
- end
61
-
62
- ERB.new(template_file).result(binding)
63
- end
64
- else
31
+ else
65
32
  # bind @current_path correctly to use in helpers and views
66
33
  if opt[:to_file]
67
34
  # Make absolute
@@ -72,7 +39,13 @@ class Renderer
72
39
  end
73
40
 
74
41
  # render 'view_name', :option1 => 1, :option2 => 2
75
- view = ERB.new(File.read path_to_template opt[:template]).result(binding)
42
+ template = path_to_template opt[:template]
43
+ begin
44
+ view = ERB.new(File.read template).result(binding)
45
+ rescue Exception => e
46
+ raise "Error while rendering #{template}\n#{e.message}"
47
+ end
48
+
76
49
 
77
50
  # then render with layout
78
51
  if opt[:layout]
@@ -105,4 +78,55 @@ class Renderer
105
78
  File.expand_path "#{file}.html.erb", @_path
106
79
  end
107
80
 
81
+ def render_partial(opt)
82
+
83
+ # add underscore to last element of foo/bar/baz
84
+ parts = opt[:partial].split('/')
85
+ parts[-1] = "_"+parts.last
86
+
87
+ template = path_to_template(parts.join('/'))
88
+
89
+ begin
90
+ template_source = File.read(template)
91
+ rescue Exception
92
+ raise "Could not find Partial '#{template}'"
93
+ end
94
+
95
+ if opt[:collection]
96
+
97
+ partial_name = opt[:partial].split('/').last
98
+
99
+ # Render it!
100
+ begin
101
+ opt[:collection].map { |item|
102
+ define_singleton_method(partial_name) { item }
103
+ ERB.new(template_source).result(binding)
104
+ }.join "\n"
105
+ rescue Exception => e
106
+ raise "Error while rendering #{partial_name}\n#{e.message}"
107
+ end
108
+
109
+ # It's not a collection
110
+ else
111
+
112
+ # If there are locals we have to save our instance binding, otherwise we will store our
113
+ # newly created local-variables in the blockcontext of each_pair
114
+ # values has to be defined explicitly to be overridden by the block and still available inside of eval
115
+ if opt[:locals]
116
+ value = nil
117
+ instance_context = binding
118
+ opt[:locals].each_pair do |local, value|
119
+ Logger.warn("Please change your partial-name or local binding, because #{local} is already set in this context.") if respond_to? local
120
+ define_singleton_method(local) { value }
121
+ end
122
+ end
123
+
124
+ begin
125
+ ERB.new(template_source).result(binding)
126
+ rescue Exception => e
127
+ raise "Error while rendering #{template}\n#{e.message}"
128
+ end
129
+ end
130
+ end
131
+
108
132
  end
@@ -33,9 +33,15 @@ module Tasks
33
33
  end
34
34
 
35
35
  def self.use(helper_module)
36
- self.include helper_module
36
+ include helper_module
37
37
  end
38
38
 
39
+ def self.all
40
+ Tasks.constants
41
+ .map { |c| Tasks.const_get c }
42
+ .select { |klass| klass.class == Class and klass.superclass == Tasks::RenderTask }
43
+ end
44
+
39
45
  protected
40
46
 
41
47
  # @group Task-Specification methods
@@ -108,5 +114,6 @@ module Tasks
108
114
  def resolve(nodename)
109
115
  @_context.resolve nodename
110
116
  end
117
+
111
118
  end
112
119
  end
@@ -1,4 +1,3 @@
1
- # ../data.img#1811394:1
2
1
  require_relative 'exceptions'
3
2
 
4
3
  module Token
@@ -1,4 +1,3 @@
1
- # ../data.img#1799432:1 && #1858562:1
2
1
  require_relative 'token'
3
2
 
4
3
  # This module contains all required mixins and modules to register customized
@@ -4,11 +4,11 @@ require_relative 'types/prototype'
4
4
  # Load Default Tokens
5
5
  require_relative 'tokens/tokens'
6
6
 
7
- # Register Rendertasks
7
+ # Load Helpers
8
+ require_relative 'helpers/template'
9
+
10
+ # Load Rendertasks
8
11
  require_relative 'tasks/typed_task'
9
12
  require_relative 'tasks/docs_task'
10
13
  require_relative 'tasks/api_index_task'
11
- require_relative 'tasks/json_data_task'
12
-
13
- # Register Helpers
14
- require_relative 'helpers/template'
14
+ require_relative 'tasks/json_data_task'
@@ -1,76 +1,68 @@
1
- module Helper
1
+ # This Helper-methods are template-specific ones. If you are using your own template, you might not
2
+ # need them anymore
3
+ # They are included in the Typed-RenderTask
4
+ module Helper::Template
2
5
 
3
- # This Helper-methods are template-specific ones. If you are using your own template, you might not
4
- # need them anymore.
5
- module Template
6
+ def signature(method_or_token)
6
7
 
7
- def signature(method_or_token)
8
-
9
- if method_or_token.is_a? Token::Token
10
- params = method_or_token.children.select {|t| t.token == :param }
11
- returns = method_or_token.children.select {|t| t.token == :return }
12
- else
13
- params = method_or_token.params
14
- returns = method_or_token.returns
15
- end
16
-
17
-
18
- params = params.map { |p|
19
- "<span class=\"param\">#{p.name}</span>" +
20
- "<span class=\"tooltip\">(<span class=\"types\">#{p.types.map{|t| link_to(t) }.join(', ')}</span>) " +
21
- "#{replace_links p.content}</span>"
22
- }.join(', ') unless params.nil?
23
-
24
- return_types = returns.first.types.map{|type| link_to(type) }.join(', ') unless returns.nil? or returns.first.nil?
25
- "(#{return_types || 'Void'}) <span class='name'>#{method_or_token.name}</span>(<span class='params'>#{params}</span>)"
8
+ if method_or_token.is_a? Token::Token
9
+ params = method_or_token.children.select {|t| t.token == :param }
10
+ returns = method_or_token.children.select {|t| t.token == :return }
11
+ else
12
+ params = method_or_token.params
13
+ returns = method_or_token.returns
26
14
  end
15
+
16
+
17
+ params = params.map { |p|
18
+ "<span class=\"param\">#{p.name}</span>" +
19
+ "<span class=\"tooltip\">(<span class=\"types\">#{p.types.map{|t| link_to(t) }.join(', ')}</span>) " +
20
+ "#{replace_links p.content}</span>"
21
+ }.join(', ') unless params.nil?
27
22
 
28
- def subsection(id, opts = {})
29
- unless opts[:collection].nil? or opts[:collection].size == 0
30
- "<h3>#{opts[:title]}</h3><ul class=\"#{id} subsection\">" +
31
- render(:partial => opts[:partial], :collection => opts[:collection]) +
32
- "</ul>"
33
- end
23
+ return_types = returns.first.types.map{|type| link_to(type) }.join(', ') unless returns.nil? or returns.first.nil?
24
+ "(#{return_types || 'Void'}) <span class='name'>#{method_or_token.name}</span>(<span class='params'>#{params}</span>)"
25
+ end
26
+
27
+ def subsection(id, opts = {})
28
+ unless opts[:collection].nil? or opts[:collection].size == 0
29
+ "<h3>#{opts[:title]}</h3><ul class=\"#{id} subsection\">" +
30
+ render(:partial => opts[:partial], :collection => opts[:collection]) +
31
+ "</ul>"
34
32
  end
33
+ end
34
+
35
+ def hierarchy(object)
36
+
37
+ children = object.children.values.reject {|c| c.is_a? CodeObject::Function }
38
+ parents = object.parents
35
39
 
36
- def hierarchy(object)
37
-
38
- children = object.children.values.reject {|c| c.is_a? CodeObject::Function }
39
- parents = object.parents
40
-
41
- parents.map {|parent| "<ul><li>#{link_to parent, parent.name}" }.join('') +
42
- "<ul><li class=\"this\">#{link_to object, object.name}<ul class=\"children\">" +
43
- children.map {|child| "<li>#{link_to child}</li>" }.join('') +
44
- "</ul>" * (parents.size + 2)
40
+ parents.map {|parent| "<ul><li>#{link_to parent, parent.name}" }.join('') +
41
+ "<ul><li class=\"this\">#{link_to object, object.name}<ul class=\"children\">" +
42
+ children.map {|child| "<li>#{link_to child}</li>" }.join('') +
43
+ "</ul>" * (parents.size + 2)
44
+ end
45
+
46
+ def api_browser(root = Dom.root)
47
+ if root == Dom.root
48
+ output = ""
49
+ elsif root.is_a? Dom::NoDoc
50
+ output = "<li class=\"nodoc\"><span>#{root.name}</span>"
51
+ elsif root.is_a? CodeObject::Function
52
+ output = "<li class=\"function\">" + link_to(root, tag(:span, root.name))
53
+ else # Object
54
+ output = "<li class=\"object\">" + link_to(root, tag(:span, root.name))
45
55
  end
46
56
 
47
- def api_browser(root = Dom.root)
48
- if root == Dom.root
49
- output = ""
50
- elsif root.is_a? Dom::NoDoc
51
- output = "<li class=\"nodoc\"><span>#{root.name}</span>"
52
- elsif root.is_a? CodeObject::Function
53
- output = "<li class=\"function\">" + link_to(root, tag(:span, root.name))
54
- else # Object
55
- output = "<li class=\"object\">" + link_to(root, tag(:span, root.name))
57
+ if root.has_children?
58
+ output += "<ul>"
59
+ root.children.values.each do |child|
60
+ output += api_browser(child)
56
61
  end
57
-
58
- if root.has_children?
59
- output += "<ul>"
60
- root.children.values.each do |child|
61
- output += api_browser(child)
62
- end
63
- output += "</ul>"
64
- end
65
-
66
- return output
62
+ output += "</ul>"
67
63
  end
68
-
64
+
65
+ return output
69
66
  end
70
-
71
- end
72
67
 
73
- # @todo automatically load from application.rb
74
- class Tasks::RenderTask
75
- include Helper::Template
76
68
  end
@@ -21,6 +21,4 @@ module Tasks
21
21
  end
22
22
  end
23
23
  end
24
- end
25
-
26
- Processor.register_render_task :api_index, Tasks::ApiIndexTask
24
+ end
@@ -1,7 +1,7 @@
1
1
  module Tasks
2
2
 
3
3
  class DocsTask < RenderTask
4
-
4
+
5
5
  describe 'renders all specified Markdown files to static documentation'
6
6
  layout 'application'
7
7
 
@@ -28,6 +28,4 @@ module Tasks
28
28
  end
29
29
 
30
30
  end
31
- end
32
-
33
- Processor.register_render_task :docs, Tasks::DocsTask
31
+ end
@@ -50,6 +50,4 @@ module Tasks
50
50
  end
51
51
  end
52
52
  end
53
- end
54
-
55
- Processor.register_render_task :json_data, Tasks::JsonDataTask
53
+ end
@@ -2,7 +2,6 @@ module Tasks
2
2
 
3
3
  class TypedTask < RenderTask
4
4
 
5
-
6
5
  # @todo those methods and therefore all class-variables @@configs are shared with all inheriting
7
6
  # classes. i.e. The last change will be applied to all
8
7
  describe 'renders documented objects type-dependant (Functions and Objects)'
@@ -49,6 +48,4 @@ module Tasks
49
48
  end
50
49
  end
51
50
  end
52
- end
53
-
54
- Processor.register_render_task :typed, Tasks::TypedTask
51
+ end
@@ -1,20 +1,15 @@
1
- module CodeObject
2
-
3
- class Prototype < CodeObject::Object
4
-
5
- def initialize(*args)
6
- super(*args)
7
- @path += '.prototype'
8
- end
9
-
10
- # get the constructor, for which this prototype is used
11
- def constructor
12
- self.parent
13
- end
14
-
1
+ class CodeObject::Prototype < CodeObject::Object
2
+
3
+ def initialize(*args)
4
+ super(*args)
5
+ @path += '.prototype'
6
+ end
7
+
8
+ # get the constructor, for which this prototype is used
9
+ def constructor
10
+ self.parent
15
11
  end
16
-
12
+
17
13
  end
18
14
 
19
- CodeObject::Type.register :prototype, CodeObject::Prototype
20
- Token::Handler.register :prototype, :handler => :noop, :area => :none
15
+ Token::Handler.register :prototype, :handler => :noop, :area => :none
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: docjs
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.3
5
+ version: 0.1.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - "Jonathan Brachth\xC3\xA4user"
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-16 00:00:00 +02:00
13
+ date: 2011-06-17 00:00:00 +02:00
14
14
  default_executable: bin/docjs
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -58,7 +58,6 @@ files:
58
58
  - lib/code_object/exceptions.rb
59
59
  - lib/code_object/function.rb
60
60
  - lib/code_object/object.rb
61
- - lib/code_object/type.rb
62
61
  - lib/configs.rb
63
62
  - lib/document/document.rb
64
63
  - lib/dom/dom.rb
@@ -1,43 +0,0 @@
1
- require_relative 'exceptions'
2
-
3
- module CodeObject
4
-
5
- module Type
6
-
7
- @@types = {}
8
-
9
- def self.register(tokenid, klass)
10
- @@types[tokenid.to_sym] = klass
11
- end
12
-
13
- def self.create_matching_object(tokenlines)
14
- klass = self.find_klass(tokenlines) or return nil
15
- self[klass.token].new(klass.content)
16
- end
17
-
18
- protected
19
-
20
- def self.[](tokenid)
21
- @@types[tokenid.to_sym]
22
- end
23
-
24
- def self.include?(tokenid)
25
- @@types.has_key? tokenid.to_sym
26
- end
27
-
28
- def self.find_klass(tokenlines)
29
- klass = tokenlines.select {|t| self.include? t.token }
30
-
31
- if klass.size > 1
32
- raise CodeObject::MultipleTypeDeclarations.new, "Wrong number of TypeDeclarations: #{klass}"
33
- elsif klass.size == 0
34
- # it's not possible to create instance
35
- return nil
36
- end
37
-
38
- klass.first
39
- end
40
-
41
- end
42
-
43
- end