jsduck 4.0.1 → 4.1.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/Rakefile +14 -0
- data/esprima/esprima.js +210 -85
- data/jsduck.gemspec +3 -3
- data/lib/jsduck/accessors.rb +10 -8
- data/lib/jsduck/aggregator.rb +7 -7
- data/lib/jsduck/app.rb +24 -164
- data/lib/jsduck/app_data.rb +2 -4
- data/lib/jsduck/assets.rb +5 -2
- data/lib/jsduck/ast.rb +9 -4
- data/lib/jsduck/batch_formatter.rb +54 -0
- data/lib/jsduck/batch_parser.rb +106 -0
- data/lib/jsduck/categories.rb +5 -6
- data/lib/jsduck/class.rb +77 -239
- data/lib/jsduck/class_doc_expander.rb +0 -5
- data/lib/jsduck/class_formatter.rb +14 -10
- data/lib/jsduck/class_name.rb +23 -0
- data/lib/jsduck/class_writer.rb +9 -8
- data/lib/jsduck/doc_ast.rb +5 -6
- data/lib/jsduck/doc_formatter.rb +61 -272
- data/lib/jsduck/enum.rb +4 -4
- data/lib/jsduck/esprima.rb +10 -4
- data/lib/jsduck/examples.rb +5 -5
- data/lib/jsduck/export_writer.rb +62 -0
- data/lib/jsduck/exporter/app.rb +62 -0
- data/lib/jsduck/exporter/examples.rb +58 -0
- data/lib/jsduck/exporter/full.rb +60 -0
- data/lib/jsduck/file_categories.rb +7 -4
- data/lib/jsduck/function_ast.rb +99 -0
- data/lib/jsduck/grouped_asset.rb +27 -16
- data/lib/jsduck/guide_writer.rb +8 -7
- data/lib/jsduck/guides.rb +31 -29
- data/lib/jsduck/icons.rb +12 -1
- data/lib/jsduck/images.rb +3 -3
- data/lib/jsduck/importer.rb +7 -7
- data/lib/jsduck/index_html.rb +20 -6
- data/lib/jsduck/inherit_doc.rb +9 -12
- data/lib/jsduck/inline/example.rb +42 -0
- data/lib/jsduck/inline/img.rb +55 -0
- data/lib/jsduck/inline/link.rb +227 -0
- data/lib/jsduck/inline/video.rb +67 -0
- data/lib/jsduck/inline_examples.rb +7 -7
- data/lib/jsduck/js_parser.rb +5 -4
- data/lib/jsduck/lint.rb +14 -2
- data/lib/jsduck/logger.rb +5 -6
- data/lib/jsduck/members_index.rb +132 -0
- data/lib/jsduck/merger.rb +3 -9
- data/lib/jsduck/options.rb +39 -41
- data/lib/jsduck/override.rb +3 -7
- data/lib/jsduck/relations.rb +9 -9
- data/lib/jsduck/renderer.rb +3 -3
- data/lib/jsduck/return_values.rb +72 -0
- data/lib/jsduck/search_data.rb +16 -20
- data/lib/jsduck/shortener.rb +58 -0
- data/lib/jsduck/signature_renderer.rb +1 -2
- data/lib/jsduck/source/file.rb +98 -0
- data/lib/jsduck/source/file_parser.rb +72 -0
- data/lib/jsduck/source/writer.rb +89 -0
- data/lib/jsduck/tag/aside.rb +1 -1
- data/lib/jsduck/tag/since.rb +1 -1
- data/lib/jsduck/template_dir.rb +2 -2
- data/lib/jsduck/util/html.rb +27 -0
- data/lib/jsduck/util/io.rb +32 -0
- data/lib/jsduck/util/json.rb +60 -0
- data/lib/jsduck/util/null_object.rb +23 -0
- data/lib/jsduck/util/os.rb +14 -0
- data/lib/jsduck/util/parallel.rb +34 -0
- data/lib/jsduck/util/singleton.rb +35 -0
- data/lib/jsduck/util/stdout.rb +33 -0
- data/lib/jsduck/videos.rb +5 -5
- data/lib/jsduck/web_writer.rb +79 -0
- data/lib/jsduck/welcome.rb +6 -6
- data/spec/class_factory.rb +20 -0
- metadata +32 -20
- data/lib/jsduck/api_exporter.rb +0 -48
- data/lib/jsduck/app_exporter.rb +0 -60
- data/lib/jsduck/examples_exporter.rb +0 -56
- data/lib/jsduck/full_exporter.rb +0 -35
- data/lib/jsduck/html.rb +0 -25
- data/lib/jsduck/inline_img.rb +0 -53
- data/lib/jsduck/inline_video.rb +0 -58
- data/lib/jsduck/io.rb +0 -30
- data/lib/jsduck/json_duck.rb +0 -52
- data/lib/jsduck/lexer.rb +0 -251
- data/lib/jsduck/null_object.rb +0 -19
- data/lib/jsduck/os.rb +0 -11
- data/lib/jsduck/parallel_wrap.rb +0 -32
- data/lib/jsduck/source_file.rb +0 -97
- data/lib/jsduck/source_file_parser.rb +0 -70
- data/lib/jsduck/source_writer.rb +0 -87
- data/lib/jsduck/stats.rb +0 -103
- data/lib/jsduck/stdout.rb +0 -31
data/lib/jsduck/welcome.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require 'jsduck/null_object'
|
2
|
-
require 'jsduck/io'
|
1
|
+
require 'jsduck/util/null_object'
|
2
|
+
require 'jsduck/util/io'
|
3
3
|
|
4
4
|
module JsDuck
|
5
5
|
|
@@ -9,18 +9,18 @@ module JsDuck
|
|
9
9
|
if filename
|
10
10
|
Welcome.new(filename)
|
11
11
|
else
|
12
|
-
NullObject.new(:to_html => "")
|
12
|
+
Util::NullObject.new(:to_html => "")
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
# Parses welcome HTML file with content for welcome page.
|
17
17
|
def initialize(filename)
|
18
|
-
@html =
|
18
|
+
@html = Util::IO.read(filename)
|
19
19
|
end
|
20
20
|
|
21
21
|
# Returns the HTML
|
22
|
-
def to_html
|
23
|
-
"<div id='welcome-content' style='
|
22
|
+
def to_html(style="")
|
23
|
+
"<div id='welcome-content' style='#{style}'>#{@html}</div>"
|
24
24
|
end
|
25
25
|
|
26
26
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "jsduck/class"
|
2
|
+
|
3
|
+
# A helper for easy creation of classes in tests
|
4
|
+
#
|
5
|
+
# Allows simplified members hashes to be used.
|
6
|
+
module Helper
|
7
|
+
class ClassFactory
|
8
|
+
def self.create(cfg)
|
9
|
+
cfg[:members].each do |m|
|
10
|
+
m[:tagname] = :property unless m[:tagname]
|
11
|
+
m[:owner] = cfg[:name]
|
12
|
+
m[:meta] = {} unless m[:meta]
|
13
|
+
m[:meta][:static] = true if m[:static]
|
14
|
+
m[:id] = JsDuck::Class.member_id(m)
|
15
|
+
end
|
16
|
+
|
17
|
+
JsDuck::Class.new(cfg)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsduck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-09-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rdiscount
|
@@ -150,17 +150,18 @@ files:
|
|
150
150
|
- jsduck.gemspec
|
151
151
|
- lib/jsduck/accessors.rb
|
152
152
|
- lib/jsduck/aggregator.rb
|
153
|
-
- lib/jsduck/api_exporter.rb
|
154
153
|
- lib/jsduck/app.rb
|
155
154
|
- lib/jsduck/app_data.rb
|
156
|
-
- lib/jsduck/app_exporter.rb
|
157
155
|
- lib/jsduck/assets.rb
|
158
156
|
- lib/jsduck/ast.rb
|
159
157
|
- lib/jsduck/auto_categories.rb
|
158
|
+
- lib/jsduck/batch_formatter.rb
|
159
|
+
- lib/jsduck/batch_parser.rb
|
160
160
|
- lib/jsduck/categories.rb
|
161
161
|
- lib/jsduck/class.rb
|
162
162
|
- lib/jsduck/class_doc_expander.rb
|
163
163
|
- lib/jsduck/class_formatter.rb
|
164
|
+
- lib/jsduck/class_name.rb
|
164
165
|
- lib/jsduck/class_writer.rb
|
165
166
|
- lib/jsduck/css_lexer.rb
|
166
167
|
- lib/jsduck/css_parser.rb
|
@@ -172,48 +173,47 @@ files:
|
|
172
173
|
- lib/jsduck/esprima.rb
|
173
174
|
- lib/jsduck/evaluator.rb
|
174
175
|
- lib/jsduck/examples.rb
|
175
|
-
- lib/jsduck/
|
176
|
+
- lib/jsduck/export_writer.rb
|
177
|
+
- lib/jsduck/exporter/app.rb
|
178
|
+
- lib/jsduck/exporter/examples.rb
|
179
|
+
- lib/jsduck/exporter/full.rb
|
176
180
|
- lib/jsduck/file_categories.rb
|
177
|
-
- lib/jsduck/
|
181
|
+
- lib/jsduck/function_ast.rb
|
178
182
|
- lib/jsduck/grouped_asset.rb
|
179
183
|
- lib/jsduck/guide_writer.rb
|
180
184
|
- lib/jsduck/guides.rb
|
181
|
-
- lib/jsduck/html.rb
|
182
185
|
- lib/jsduck/icons.rb
|
183
186
|
- lib/jsduck/images.rb
|
184
187
|
- lib/jsduck/importer.rb
|
185
188
|
- lib/jsduck/index_html.rb
|
186
189
|
- lib/jsduck/inherit_doc.rb
|
190
|
+
- lib/jsduck/inline/example.rb
|
191
|
+
- lib/jsduck/inline/img.rb
|
192
|
+
- lib/jsduck/inline/link.rb
|
193
|
+
- lib/jsduck/inline/video.rb
|
187
194
|
- lib/jsduck/inline_examples.rb
|
188
|
-
- lib/jsduck/inline_img.rb
|
189
|
-
- lib/jsduck/inline_video.rb
|
190
|
-
- lib/jsduck/io.rb
|
191
195
|
- lib/jsduck/js_parser.rb
|
192
|
-
- lib/jsduck/json_duck.rb
|
193
|
-
- lib/jsduck/lexer.rb
|
194
196
|
- lib/jsduck/lint.rb
|
195
197
|
- lib/jsduck/logger.rb
|
198
|
+
- lib/jsduck/members_index.rb
|
196
199
|
- lib/jsduck/merger.rb
|
197
200
|
- lib/jsduck/meta_tag.rb
|
198
201
|
- lib/jsduck/meta_tag_loader.rb
|
199
202
|
- lib/jsduck/meta_tag_registry.rb
|
200
203
|
- lib/jsduck/meta_tag_renderer.rb
|
201
|
-
- lib/jsduck/null_object.rb
|
202
204
|
- lib/jsduck/option_parser.rb
|
203
205
|
- lib/jsduck/options.rb
|
204
|
-
- lib/jsduck/os.rb
|
205
206
|
- lib/jsduck/override.rb
|
206
|
-
- lib/jsduck/parallel_wrap.rb
|
207
207
|
- lib/jsduck/relations.rb
|
208
208
|
- lib/jsduck/renderer.rb
|
209
|
+
- lib/jsduck/return_values.rb
|
209
210
|
- lib/jsduck/search_data.rb
|
210
211
|
- lib/jsduck/serializer.rb
|
212
|
+
- lib/jsduck/shortener.rb
|
211
213
|
- lib/jsduck/signature_renderer.rb
|
212
|
-
- lib/jsduck/
|
213
|
-
- lib/jsduck/
|
214
|
-
- lib/jsduck/
|
215
|
-
- lib/jsduck/stats.rb
|
216
|
-
- lib/jsduck/stdout.rb
|
214
|
+
- lib/jsduck/source/file.rb
|
215
|
+
- lib/jsduck/source/file_parser.rb
|
216
|
+
- lib/jsduck/source/writer.rb
|
217
217
|
- lib/jsduck/tag/abstract.rb
|
218
218
|
- lib/jsduck/tag/aside.rb
|
219
219
|
- lib/jsduck/tag/author.rb
|
@@ -235,10 +235,22 @@ files:
|
|
235
235
|
- lib/jsduck/tag/template.rb
|
236
236
|
- lib/jsduck/template_dir.rb
|
237
237
|
- lib/jsduck/type_parser.rb
|
238
|
+
- lib/jsduck/util/html.rb
|
239
|
+
- lib/jsduck/util/io.rb
|
240
|
+
- lib/jsduck/util/json.rb
|
241
|
+
- lib/jsduck/util/null_object.rb
|
242
|
+
- lib/jsduck/util/os.rb
|
243
|
+
- lib/jsduck/util/parallel.rb
|
244
|
+
- lib/jsduck/util/singleton.rb
|
245
|
+
- lib/jsduck/util/stdout.rb
|
238
246
|
- lib/jsduck/videos.rb
|
247
|
+
- lib/jsduck/web_writer.rb
|
239
248
|
- lib/jsduck/welcome.rb
|
249
|
+
- spec/class_factory.rb
|
240
250
|
- template-min/README.md
|
251
|
+
- template-min/Mobile_Detect.php
|
241
252
|
- template-min/template.html
|
253
|
+
- template-min/index-template.html
|
242
254
|
- template-min/eg-iframe.html
|
243
255
|
- template-min/resources/images/component-m.png
|
244
256
|
- template-min/resources/images/expandcollapse.png
|
data/lib/jsduck/api_exporter.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'jsduck/json_duck'
|
2
|
-
require 'jsduck/class'
|
3
|
-
|
4
|
-
module JsDuck
|
5
|
-
|
6
|
-
# Exporter for simple JSON format listing only class name and names
|
7
|
-
# of all of its members.
|
8
|
-
#
|
9
|
-
# It produces the following structure:
|
10
|
-
#
|
11
|
-
# {
|
12
|
-
# :name => "Panel",
|
13
|
-
# :members => {
|
14
|
-
# :cfg => ["width", "height", "title"],
|
15
|
-
# :method => ["getWidth", "setWidth"],
|
16
|
-
# ...
|
17
|
-
# },
|
18
|
-
# :statics => { ... }
|
19
|
-
# }
|
20
|
-
#
|
21
|
-
class ApiExporter
|
22
|
-
def initialize(relations, opts)
|
23
|
-
# All params ignored, they're present to be compatible with
|
24
|
-
# other exporters.
|
25
|
-
end
|
26
|
-
|
27
|
-
# Returns hash of class name and member names
|
28
|
-
def export(cls)
|
29
|
-
{
|
30
|
-
:name => cls[:name],
|
31
|
-
:members => export_members(cls, :members),
|
32
|
-
:statics => export_members(cls, :statics),
|
33
|
-
}
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def export_members(cls, context)
|
39
|
-
h = {}
|
40
|
-
Class.default_members_hash.each_key do |type|
|
41
|
-
h[type] = cls.members(type, context).map {|m| m[:name] }
|
42
|
-
end
|
43
|
-
h
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
data/lib/jsduck/app_exporter.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'jsduck/full_exporter'
|
2
|
-
require 'jsduck/renderer'
|
3
|
-
require 'jsduck/doc_formatter'
|
4
|
-
|
5
|
-
module JsDuck
|
6
|
-
|
7
|
-
# Exports data for Docs app.
|
8
|
-
class AppExporter < FullExporter
|
9
|
-
def initialize(relations, opts)
|
10
|
-
super(relations, opts)
|
11
|
-
@renderer = Renderer.new(opts)
|
12
|
-
end
|
13
|
-
|
14
|
-
# Returns compacted class data hash which contains an additional
|
15
|
-
# :html field with full HTML to show on class overview page.
|
16
|
-
def export(cls)
|
17
|
-
data = super(cls)
|
18
|
-
data[:html] = @renderer.render(data)
|
19
|
-
return compact(data)
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
# removes extra data from export
|
25
|
-
def compact(cls)
|
26
|
-
cls.delete(:doc)
|
27
|
-
cls[:members] = compact_members_group(cls[:members])
|
28
|
-
cls[:statics] = compact_members_group(cls[:statics])
|
29
|
-
cls[:files] = compact_files(cls[:files])
|
30
|
-
cls
|
31
|
-
end
|
32
|
-
|
33
|
-
def compact_members_group(group)
|
34
|
-
c_group = {}
|
35
|
-
group.each_pair do |type, members|
|
36
|
-
c_group[type] = members.map {|m| compact_member(m) }
|
37
|
-
end
|
38
|
-
c_group
|
39
|
-
end
|
40
|
-
|
41
|
-
def compact_member(m)
|
42
|
-
m_copy = {}
|
43
|
-
[:name, :tagname, :owner, :meta, :id].each do |key|
|
44
|
-
m_copy[key] = m[key]
|
45
|
-
end
|
46
|
-
m_copy
|
47
|
-
end
|
48
|
-
|
49
|
-
# Remove full path from filename for privacy considerations as the
|
50
|
-
# path can reveal information about the system where JSDuck was
|
51
|
-
# run. The docs app doesn't need to have this information.
|
52
|
-
def compact_files(files)
|
53
|
-
files.map do |f|
|
54
|
-
{:filename => File.basename(f[:filename]), :href => f[:href]}
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'jsduck/inline_examples'
|
2
|
-
|
3
|
-
module JsDuck
|
4
|
-
|
5
|
-
# Exporter for inline examples.
|
6
|
-
#
|
7
|
-
# It produces the following structure:
|
8
|
-
#
|
9
|
-
# {
|
10
|
-
# :type => :class, # can also be :guide
|
11
|
-
# :name => "Panel",
|
12
|
-
# :examples => [
|
13
|
-
# {:code => "bla bla", :options => {}},
|
14
|
-
# {:code => "bla bla", :options => {"raw" => true}},
|
15
|
-
# ...
|
16
|
-
# ]
|
17
|
-
# }
|
18
|
-
#
|
19
|
-
class ExamplesExporter
|
20
|
-
def initialize(relations, opts)
|
21
|
-
# All params ignored, they're present to be compatible with
|
22
|
-
# other exporters.
|
23
|
-
@inline_examples = InlineExamples.new
|
24
|
-
end
|
25
|
-
|
26
|
-
# Returns hash of class name and inline examples
|
27
|
-
def export(cls)
|
28
|
-
examples = @inline_examples.extract(cls[:doc])
|
29
|
-
if examples.length > 0
|
30
|
-
{
|
31
|
-
:type => :class,
|
32
|
-
:name => cls[:name],
|
33
|
-
:examples => examples,
|
34
|
-
}
|
35
|
-
else
|
36
|
-
nil
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
# Returns hash of guide name and inline examples
|
41
|
-
def export_guide(guide)
|
42
|
-
examples = @inline_examples.extract(guide[:html] || "")
|
43
|
-
if examples.length > 0
|
44
|
-
{
|
45
|
-
:type => :guide,
|
46
|
-
:name => guide["name"],
|
47
|
-
:examples => examples,
|
48
|
-
}
|
49
|
-
else
|
50
|
-
nil
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
data/lib/jsduck/full_exporter.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'jsduck/class'
|
2
|
-
|
3
|
-
module JsDuck
|
4
|
-
|
5
|
-
# Exporter for all the class docs.
|
6
|
-
class FullExporter
|
7
|
-
def initialize(relations, opts)
|
8
|
-
@relations = relations
|
9
|
-
# opts parameter is here just for compatibility with other exporters
|
10
|
-
end
|
11
|
-
|
12
|
-
# Returns all data in Class object as hash.
|
13
|
-
def export(cls)
|
14
|
-
h = cls.to_hash
|
15
|
-
h[:members] = {}
|
16
|
-
Class.default_members_hash.each_key do |key|
|
17
|
-
h[:members][key] = cls.members(key)
|
18
|
-
h[:statics][key] = cls.members(key, :statics)
|
19
|
-
end
|
20
|
-
h[:component] = cls.inherits_from?("Ext.Component")
|
21
|
-
h[:superclasses] = cls.superclasses.collect {|c| c.full_name }
|
22
|
-
h[:subclasses] = @relations.subclasses(cls).collect {|c| c.full_name }
|
23
|
-
h[:mixedInto] = @relations.mixed_into(cls).collect {|c| c.full_name }
|
24
|
-
|
25
|
-
h[:mixins] = cls.deps(:mixins).collect {|c| c.full_name }
|
26
|
-
h[:parentMixins] = cls.parent_deps(:mixins).collect {|c| c.full_name }
|
27
|
-
h[:requires] = cls.deps(:requires).collect {|c| c.full_name }
|
28
|
-
h[:uses] = cls.deps(:uses).collect {|c| c.full_name }
|
29
|
-
|
30
|
-
h
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
data/lib/jsduck/html.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'cgi'
|
2
|
-
|
3
|
-
module JsDuck
|
4
|
-
|
5
|
-
# Helpers for dealing with HTML
|
6
|
-
class HTML
|
7
|
-
|
8
|
-
# Strips tags from HTML text
|
9
|
-
def self.strip_tags(html)
|
10
|
-
html.gsub(/<.*?>/, "")
|
11
|
-
end
|
12
|
-
|
13
|
-
# Escapes HTML, replacing < with < ...
|
14
|
-
def self.escape(html)
|
15
|
-
CGI.escapeHTML(html)
|
16
|
-
end
|
17
|
-
|
18
|
-
# Unescapes HTML, replacing < with < ...
|
19
|
-
def self.unescape(html)
|
20
|
-
CGI.unescapeHTML(html)
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
data/lib/jsduck/inline_img.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'jsduck/html'
|
2
|
-
require 'jsduck/logger'
|
3
|
-
|
4
|
-
module JsDuck
|
5
|
-
|
6
|
-
# Implementation of inline tag {@img}
|
7
|
-
class InlineImg
|
8
|
-
# Base path to prefix images from {@img} tags.
|
9
|
-
# Defaults to no prefix.
|
10
|
-
attr_accessor :base_path
|
11
|
-
|
12
|
-
# This will hold list of all image paths gathered from {@img} tags.
|
13
|
-
attr_accessor :images
|
14
|
-
|
15
|
-
def initialize(opts={})
|
16
|
-
@tpl = opts[:img_tpl] || '<img src="%u" alt="%a"/>'
|
17
|
-
|
18
|
-
@re = /\{@img\s+(\S*?)(?:\s+(.+?))?\}/m
|
19
|
-
|
20
|
-
@base_path = nil
|
21
|
-
@images = []
|
22
|
-
end
|
23
|
-
|
24
|
-
# Takes StringScanner instance.
|
25
|
-
#
|
26
|
-
# Looks for inline tag at the current scan pointer position, when
|
27
|
-
# found, moves scan pointer forward and performs the apporpriate
|
28
|
-
# replacement.
|
29
|
-
def replace(input)
|
30
|
-
if input.check(@re)
|
31
|
-
input.scan(@re).sub(@re) { apply_tpl($1, $2) }
|
32
|
-
else
|
33
|
-
false
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# applies the image template
|
38
|
-
def apply_tpl(url, alt_text)
|
39
|
-
@images << url
|
40
|
-
@tpl.gsub(/(%\w)/) do
|
41
|
-
case $1
|
42
|
-
when '%u'
|
43
|
-
@base_path ? (@base_path + "/" + url) : url
|
44
|
-
when '%a'
|
45
|
-
HTML.escape(alt_text||"")
|
46
|
-
else
|
47
|
-
$1
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|