amp 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/.hgignore +3 -0
- data/AUTHORS +1 -1
- data/Manifest.txt +99 -38
- data/README.md +3 -3
- data/Rakefile +53 -18
- data/SCHEDULE.markdown +5 -1
- data/TODO.markdown +120 -149
- data/ampfile.rb +3 -1
- data/bin/amp +4 -1
- data/ext/amp/bz2/extconf.rb +1 -1
- data/ext/amp/mercurial_patch/extconf.rb +1 -1
- data/ext/amp/mercurial_patch/mpatch.c +4 -3
- data/ext/amp/priority_queue/extconf.rb +1 -1
- data/ext/amp/support/extconf.rb +1 -1
- data/ext/amp/support/support.c +1 -1
- data/lib/amp.rb +125 -67
- data/lib/amp/commands/command.rb +12 -10
- data/lib/amp/commands/command_support.rb +8 -1
- data/lib/amp/commands/commands/help.rb +2 -20
- data/lib/amp/commands/commands/init.rb +14 -2
- data/lib/amp/commands/commands/templates.rb +6 -4
- data/lib/amp/commands/commands/version.rb +15 -1
- data/lib/amp/commands/commands/workflow.rb +3 -3
- data/lib/amp/commands/commands/workflows/git/add.rb +3 -3
- data/lib/amp/commands/commands/workflows/git/copy.rb +1 -1
- data/lib/amp/commands/commands/workflows/git/rm.rb +4 -2
- data/lib/amp/commands/commands/workflows/hg/add.rb +1 -1
- data/lib/amp/commands/commands/workflows/hg/addremove.rb +2 -2
- data/lib/amp/commands/commands/workflows/hg/annotate.rb +8 -2
- data/lib/amp/commands/commands/workflows/hg/bisect.rb +253 -0
- data/lib/amp/commands/commands/workflows/hg/branch.rb +1 -1
- data/lib/amp/commands/commands/workflows/hg/branches.rb +3 -3
- data/lib/amp/commands/commands/workflows/hg/bundle.rb +3 -3
- data/lib/amp/commands/commands/workflows/hg/clone.rb +4 -5
- data/lib/amp/commands/commands/workflows/hg/commit.rb +37 -1
- data/lib/amp/commands/commands/workflows/hg/copy.rb +2 -1
- data/lib/amp/commands/commands/workflows/hg/debug/index.rb +1 -1
- data/lib/amp/commands/commands/workflows/hg/diff.rb +3 -8
- data/lib/amp/commands/commands/workflows/hg/forget.rb +5 -4
- data/lib/amp/commands/commands/workflows/hg/identify.rb +6 -6
- data/lib/amp/commands/commands/workflows/hg/import.rb +1 -1
- data/lib/amp/commands/commands/workflows/hg/incoming.rb +2 -2
- data/lib/amp/commands/commands/workflows/hg/log.rb +5 -4
- data/lib/amp/commands/commands/workflows/hg/merge.rb +1 -1
- data/lib/amp/commands/commands/workflows/hg/move.rb +5 -3
- data/lib/amp/commands/commands/workflows/hg/outgoing.rb +1 -1
- data/lib/amp/commands/commands/workflows/hg/push.rb +6 -7
- data/lib/amp/commands/commands/workflows/hg/remove.rb +2 -2
- data/lib/amp/commands/commands/workflows/hg/resolve.rb +6 -23
- data/lib/amp/commands/commands/workflows/hg/root.rb +1 -2
- data/lib/amp/commands/commands/workflows/hg/status.rb +21 -12
- data/lib/amp/commands/commands/workflows/hg/tag.rb +2 -2
- data/lib/amp/commands/commands/workflows/hg/untrack.rb +12 -0
- data/lib/amp/commands/commands/workflows/hg/verify.rb +13 -3
- data/lib/amp/commands/commands/workflows/hg/what_changed.rb +18 -0
- data/lib/amp/commands/dispatch.rb +12 -13
- data/lib/amp/dependencies/amp_support.rb +1 -1
- data/lib/amp/dependencies/amp_support/ruby_amp_support.rb +1 -0
- data/lib/amp/dependencies/maruku.rb +136 -0
- data/lib/amp/dependencies/maruku/attributes.rb +227 -0
- data/lib/amp/dependencies/maruku/defaults.rb +71 -0
- data/lib/amp/dependencies/maruku/errors_management.rb +92 -0
- data/lib/amp/dependencies/maruku/helpers.rb +260 -0
- data/lib/amp/dependencies/maruku/input/charsource.rb +326 -0
- data/lib/amp/dependencies/maruku/input/extensions.rb +69 -0
- data/lib/amp/dependencies/maruku/input/html_helper.rb +189 -0
- data/lib/amp/dependencies/maruku/input/linesource.rb +111 -0
- data/lib/amp/dependencies/maruku/input/parse_block.rb +615 -0
- data/lib/amp/dependencies/maruku/input/parse_doc.rb +234 -0
- data/lib/amp/dependencies/maruku/input/parse_span_better.rb +746 -0
- data/lib/amp/dependencies/maruku/input/rubypants.rb +225 -0
- data/lib/amp/dependencies/maruku/input/type_detection.rb +147 -0
- data/lib/amp/dependencies/maruku/input_textile2/t2_parser.rb +163 -0
- data/lib/amp/dependencies/maruku/maruku.rb +33 -0
- data/lib/amp/dependencies/maruku/output/to_ansi.rb +223 -0
- data/lib/amp/dependencies/maruku/output/to_html.rb +991 -0
- data/lib/amp/dependencies/maruku/output/to_markdown.rb +164 -0
- data/lib/amp/dependencies/maruku/output/to_s.rb +56 -0
- data/lib/amp/dependencies/maruku/string_utils.rb +191 -0
- data/lib/amp/dependencies/maruku/structures.rb +167 -0
- data/lib/amp/dependencies/maruku/structures_inspect.rb +87 -0
- data/lib/amp/dependencies/maruku/structures_iterators.rb +61 -0
- data/lib/amp/dependencies/maruku/textile2.rb +1 -0
- data/lib/amp/dependencies/maruku/toc.rb +199 -0
- data/lib/amp/dependencies/maruku/usage/example1.rb +33 -0
- data/lib/amp/dependencies/maruku/version.rb +40 -0
- data/lib/amp/dependencies/priority_queue.rb +2 -1
- data/lib/amp/dependencies/python_config.rb +2 -1
- data/lib/amp/graphs/ancestor.rb +2 -1
- data/lib/amp/graphs/copies.rb +236 -233
- data/lib/amp/help/entries/__default__.erb +31 -0
- data/lib/amp/help/entries/commands.erb +6 -0
- data/lib/amp/help/entries/mdtest.md +35 -0
- data/lib/amp/help/entries/silly +3 -0
- data/lib/amp/help/help.rb +288 -0
- data/lib/amp/profiling_hacks.rb +5 -3
- data/lib/amp/repository/abstract/abstract_changeset.rb +97 -0
- data/lib/amp/repository/abstract/abstract_local_repo.rb +181 -0
- data/lib/amp/repository/abstract/abstract_staging_area.rb +180 -0
- data/lib/amp/repository/abstract/abstract_versioned_file.rb +100 -0
- data/lib/amp/repository/abstract/common_methods/changeset.rb +75 -0
- data/lib/amp/repository/abstract/common_methods/local_repo.rb +277 -0
- data/lib/amp/repository/abstract/common_methods/staging_area.rb +233 -0
- data/lib/amp/repository/abstract/common_methods/versioned_file.rb +71 -0
- data/lib/amp/repository/generic_repo_picker.rb +78 -0
- data/lib/amp/repository/git/repo_format/changeset.rb +336 -0
- data/lib/amp/repository/git/repo_format/staging_area.rb +192 -0
- data/lib/amp/repository/git/repo_format/versioned_file.rb +119 -0
- data/lib/amp/repository/git/repositories/local_repository.rb +164 -0
- data/lib/amp/repository/git/repository.rb +41 -0
- data/lib/amp/repository/mercurial/encoding/mercurial_diff.rb +382 -0
- data/lib/amp/repository/mercurial/encoding/mercurial_patch.rb +1 -0
- data/lib/amp/repository/mercurial/encoding/patch.rb +294 -0
- data/lib/amp/repository/mercurial/encoding/pure_ruby/ruby_mercurial_patch.rb +124 -0
- data/lib/amp/repository/mercurial/merging/merge_ui.rb +327 -0
- data/lib/amp/repository/mercurial/merging/simple_merge.rb +452 -0
- data/lib/amp/repository/mercurial/repo_format/branch_manager.rb +266 -0
- data/lib/amp/repository/mercurial/repo_format/changeset.rb +768 -0
- data/lib/amp/repository/mercurial/repo_format/dir_state.rb +716 -0
- data/lib/amp/repository/mercurial/repo_format/journal.rb +218 -0
- data/lib/amp/repository/mercurial/repo_format/lock.rb +210 -0
- data/lib/amp/repository/mercurial/repo_format/merge_state.rb +228 -0
- data/lib/amp/repository/mercurial/repo_format/staging_area.rb +367 -0
- data/lib/amp/repository/mercurial/repo_format/store.rb +487 -0
- data/lib/amp/repository/mercurial/repo_format/tag_manager.rb +322 -0
- data/lib/amp/repository/mercurial/repo_format/updatable.rb +543 -0
- data/lib/amp/repository/mercurial/repo_format/updater.rb +848 -0
- data/lib/amp/repository/mercurial/repo_format/verification.rb +433 -0
- data/lib/amp/repository/mercurial/repositories/bundle_repository.rb +216 -0
- data/lib/amp/repository/mercurial/repositories/http_repository.rb +386 -0
- data/lib/amp/repository/mercurial/repositories/local_repository.rb +2034 -0
- data/lib/amp/repository/mercurial/repository.rb +119 -0
- data/lib/amp/repository/mercurial/revlogs/bundle_revlogs.rb +249 -0
- data/lib/amp/repository/mercurial/revlogs/changegroup.rb +217 -0
- data/lib/amp/repository/mercurial/revlogs/changelog.rb +339 -0
- data/lib/amp/repository/mercurial/revlogs/file_log.rb +152 -0
- data/lib/amp/repository/mercurial/revlogs/index.rb +500 -0
- data/lib/amp/repository/mercurial/revlogs/manifest.rb +201 -0
- data/lib/amp/repository/mercurial/revlogs/node.rb +20 -0
- data/lib/amp/repository/mercurial/revlogs/revlog.rb +1026 -0
- data/lib/amp/repository/mercurial/revlogs/revlog_support.rb +129 -0
- data/lib/amp/repository/mercurial/revlogs/versioned_file.rb +597 -0
- data/lib/amp/repository/repository.rb +11 -88
- data/lib/amp/server/extension/amp_extension.rb +3 -3
- data/lib/amp/server/fancy_http_server.rb +1 -1
- data/lib/amp/server/fancy_views/_browser.haml +1 -1
- data/lib/amp/server/fancy_views/_diff_file.haml +1 -8
- data/lib/amp/server/fancy_views/changeset.haml +2 -2
- data/lib/amp/server/fancy_views/file.haml +1 -1
- data/lib/amp/server/fancy_views/file_diff.haml +1 -1
- data/lib/amp/support/amp_ui.rb +13 -29
- data/lib/amp/support/generator.rb +1 -1
- data/lib/amp/support/loaders.rb +1 -2
- data/lib/amp/support/logger.rb +10 -16
- data/lib/amp/support/match.rb +18 -4
- data/lib/amp/support/mercurial/ignore.rb +151 -0
- data/lib/amp/support/openers.rb +8 -3
- data/lib/amp/support/support.rb +91 -46
- data/lib/amp/templates/{blank.commit.erb → mercurial/blank.commit.erb} +0 -0
- data/lib/amp/templates/{blank.log.erb → mercurial/blank.log.erb} +0 -0
- data/lib/amp/templates/{default.commit.erb → mercurial/default.commit.erb} +0 -0
- data/lib/amp/templates/{default.log.erb → mercurial/default.log.erb} +0 -0
- data/lib/amp/templates/template.rb +18 -18
- data/man/amp.1 +51 -0
- data/site/src/about/commands.haml +1 -1
- data/site/src/css/amp.css +1 -1
- data/site/src/index.haml +3 -3
- data/tasks/man.rake +39 -0
- data/tasks/stats.rake +1 -10
- data/tasks/yard.rake +1 -50
- data/test/dirstate_tests/test_dir_state.rb +10 -8
- data/test/functional_tests/annotate.out +31 -0
- data/test/functional_tests/test_functional.rb +155 -63
- data/test/localrepo_tests/ampfile.rb +12 -0
- data/test/localrepo_tests/test_local_repo.rb +56 -57
- data/test/manifest_tests/test_manifest.rb +3 -5
- data/test/merge_tests/test_merge.rb +3 -3
- data/test/revlog_tests/test_revlog.rb +14 -6
- data/test/store_tests/test_fncache_store.rb +19 -19
- data/test/test_19_compatibility.rb +46 -0
- data/test/test_base85.rb +2 -2
- data/test/test_bdiff.rb +2 -2
- data/test/test_changegroup.rb +59 -0
- data/test/test_commands.rb +2 -2
- data/test/test_difflib.rb +2 -2
- data/test/test_generator.rb +34 -0
- data/test/test_ignore.rb +203 -0
- data/test/test_journal.rb +18 -13
- data/test/test_match.rb +2 -2
- data/test/test_mdiff.rb +3 -3
- data/test/test_mpatch.rb +3 -3
- data/test/test_multi_io.rb +40 -0
- data/test/test_support.rb +18 -2
- data/test/test_templates.rb +38 -0
- data/test/test_ui.rb +79 -0
- data/test/testutilities.rb +56 -0
- metadata +168 -49
- data/ext/amp/bz2/mkmf.log +0 -38
- data/lib/amp/encoding/mercurial_diff.rb +0 -378
- data/lib/amp/encoding/mercurial_patch.rb +0 -1
- data/lib/amp/encoding/patch.rb +0 -292
- data/lib/amp/encoding/pure_ruby/ruby_mercurial_patch.rb +0 -123
- data/lib/amp/merges/merge_state.rb +0 -164
- data/lib/amp/merges/merge_ui.rb +0 -322
- data/lib/amp/merges/simple_merge.rb +0 -450
- data/lib/amp/repository/branch_manager.rb +0 -234
- data/lib/amp/repository/dir_state.rb +0 -950
- data/lib/amp/repository/journal.rb +0 -203
- data/lib/amp/repository/lock.rb +0 -207
- data/lib/amp/repository/repositories/bundle_repository.rb +0 -214
- data/lib/amp/repository/repositories/http_repository.rb +0 -377
- data/lib/amp/repository/repositories/local_repository.rb +0 -2661
- data/lib/amp/repository/store.rb +0 -485
- data/lib/amp/repository/tag_manager.rb +0 -319
- data/lib/amp/repository/updatable.rb +0 -532
- data/lib/amp/repository/verification.rb +0 -431
- data/lib/amp/repository/versioned_file.rb +0 -475
- data/lib/amp/revlogs/bundle_revlogs.rb +0 -246
- data/lib/amp/revlogs/changegroup.rb +0 -217
- data/lib/amp/revlogs/changelog.rb +0 -338
- data/lib/amp/revlogs/changeset.rb +0 -521
- data/lib/amp/revlogs/file_log.rb +0 -165
- data/lib/amp/revlogs/index.rb +0 -493
- data/lib/amp/revlogs/manifest.rb +0 -195
- data/lib/amp/revlogs/node.rb +0 -18
- data/lib/amp/revlogs/revlog.rb +0 -1045
- data/lib/amp/revlogs/revlog_support.rb +0 -126
- data/lib/amp/support/ignore.rb +0 -144
- data/site/Rakefile +0 -38
- data/test/test_amp.rb +0 -9
- data/test/test_helper.rb +0 -15
@@ -0,0 +1,87 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
|
3
|
+
#
|
4
|
+
# This file is part of Maruku.
|
5
|
+
#
|
6
|
+
# Maruku is free software; you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation; either version 2 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Maruku is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Maruku; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
#++
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
class String
|
24
|
+
def inspect_more(a=nil,b=nil)
|
25
|
+
inspect
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Object
|
30
|
+
def inspect_more(a=nil,b=nil)
|
31
|
+
inspect
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class Array
|
36
|
+
def inspect_more(compact, join_string, add_brackets=true)
|
37
|
+
s = map {|x|
|
38
|
+
x.kind_of?(String) ? x.inspect :
|
39
|
+
x.kind_of?(MaRuKu::MDElement) ? x.inspect(compact) :
|
40
|
+
(raise "WTF #{x.class} #{x.inspect}")
|
41
|
+
}.join(join_string)
|
42
|
+
|
43
|
+
add_brackets ? "[#{s}]" : s
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class Hash
|
48
|
+
def inspect_ordered(a=nil,b=nil)
|
49
|
+
"{"+keys.map{|x|x.to_s}.sort.map{|x|x.to_sym}.
|
50
|
+
map{|k| k.inspect + "=>"+self[k].inspect}.join(',')+"}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
module MaRuKu
|
55
|
+
class MDElement
|
56
|
+
def inspect(compact=true)
|
57
|
+
if compact
|
58
|
+
i2 = inspect2
|
59
|
+
return i2 if i2
|
60
|
+
end
|
61
|
+
|
62
|
+
"md_el(:%s,%s,%s,%s)" %
|
63
|
+
[
|
64
|
+
self.node_type,
|
65
|
+
children_inspect(compact),
|
66
|
+
@meta_priv.inspect_ordered,
|
67
|
+
self.al.inspect
|
68
|
+
]
|
69
|
+
end
|
70
|
+
|
71
|
+
def children_inspect(compact=true)
|
72
|
+
s = @children.inspect_more(compact,', ')
|
73
|
+
if @children.empty?
|
74
|
+
"[]"
|
75
|
+
elsif s.size < 70
|
76
|
+
s
|
77
|
+
else
|
78
|
+
"[\n"+
|
79
|
+
add_tabs(@children.inspect_more(compact,",\n",false))+
|
80
|
+
"\n]"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
|
3
|
+
#
|
4
|
+
# This file is part of Maruku.
|
5
|
+
#
|
6
|
+
# Maruku is free software; you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation; either version 2 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Maruku is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Maruku; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
#++
|
20
|
+
|
21
|
+
|
22
|
+
module MaRuKu
|
23
|
+
|
24
|
+
class MDElement
|
25
|
+
|
26
|
+
# Yields to each element of specified node_type
|
27
|
+
# All elements if e_node_type is nil.
|
28
|
+
def each_element(e_node_type=nil, &block)
|
29
|
+
@children.each do |c|
|
30
|
+
if c.kind_of? MDElement
|
31
|
+
if (not e_node_type) || (e_node_type == c.node_type)
|
32
|
+
block.call c
|
33
|
+
end
|
34
|
+
c.each_element(e_node_type, &block)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Apply passed block to each String in the hierarchy.
|
40
|
+
def replace_each_string(&block)
|
41
|
+
for c in @children
|
42
|
+
if c.kind_of? MDElement
|
43
|
+
c.replace_each_string(&block)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
processed = []
|
48
|
+
until @children.empty?
|
49
|
+
c = @children.shift
|
50
|
+
if c.kind_of? String
|
51
|
+
result = block.call(c)
|
52
|
+
[*result].each do |e| processed << e end
|
53
|
+
else
|
54
|
+
processed << c
|
55
|
+
end
|
56
|
+
end
|
57
|
+
@children = processed
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'maruku/input_textile2/t2_parser'
|
@@ -0,0 +1,199 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
|
3
|
+
#
|
4
|
+
# This file is part of Maruku.
|
5
|
+
#
|
6
|
+
# Maruku is free software; you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation; either version 2 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Maruku is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Maruku; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
#++
|
20
|
+
|
21
|
+
|
22
|
+
module MaRuKu
|
23
|
+
|
24
|
+
class MDDocument
|
25
|
+
# an instance of Section (see below)
|
26
|
+
attr_accessor :toc
|
27
|
+
end
|
28
|
+
|
29
|
+
# This represents a section in the TOC.
|
30
|
+
class Section
|
31
|
+
# a Fixnum, is == header_element.level
|
32
|
+
attr_accessor :section_level
|
33
|
+
|
34
|
+
# An array of fixnum, like [1,2,5] for Section 1.2.5
|
35
|
+
attr_accessor :section_number
|
36
|
+
|
37
|
+
# reference to header (header has h.meta[:section] to self)
|
38
|
+
attr_accessor :header_element
|
39
|
+
|
40
|
+
# Array of immediate children of this element
|
41
|
+
attr_accessor :immediate_children
|
42
|
+
|
43
|
+
# Array of Section inside this section
|
44
|
+
attr_accessor :section_children
|
45
|
+
|
46
|
+
def initialize
|
47
|
+
@immediate_children = []
|
48
|
+
@section_children = []
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class Section
|
53
|
+
def inspect(indent=1)
|
54
|
+
s = ""
|
55
|
+
if @header_element
|
56
|
+
s += "\_"*indent + "(#{@section_level})>\t #{@section_number.join('.')} : "
|
57
|
+
s += @header_element.children_to_s +
|
58
|
+
" (id: '#{@header_element.attributes[:id]}')\n"
|
59
|
+
else
|
60
|
+
s += "Master\n"
|
61
|
+
end
|
62
|
+
|
63
|
+
@section_children.each do |c|
|
64
|
+
s+=c.inspect(indent+1)
|
65
|
+
end
|
66
|
+
s
|
67
|
+
end
|
68
|
+
|
69
|
+
# Numerate this section and its children
|
70
|
+
def numerate(a=[])
|
71
|
+
self.section_number = a
|
72
|
+
section_children.each_with_index do |c,i|
|
73
|
+
c.numerate(a.clone.push(i+1))
|
74
|
+
end
|
75
|
+
if h = self.header_element
|
76
|
+
h.attributes[:section_number] = self.section_number
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
include REXML
|
81
|
+
# Creates an HTML toc.
|
82
|
+
# Call this on the root
|
83
|
+
def to_html
|
84
|
+
div = Element.new 'div'
|
85
|
+
div.attributes['class'] = 'maruku_toc'
|
86
|
+
div << create_toc
|
87
|
+
div
|
88
|
+
end
|
89
|
+
|
90
|
+
def create_toc
|
91
|
+
ul = Element.new 'ul'
|
92
|
+
# let's remove the bullets
|
93
|
+
ul.attributes['style'] = 'list-style: none;'
|
94
|
+
@section_children.each do |c|
|
95
|
+
li = Element.new 'li'
|
96
|
+
if span = c.header_element.render_section_number
|
97
|
+
li << span
|
98
|
+
end
|
99
|
+
a = c.header_element.wrap_as_element('a')
|
100
|
+
a.delete_attribute 'id'
|
101
|
+
a.attributes['href'] = "##{c.header_element.attributes[:id]}"
|
102
|
+
li << a
|
103
|
+
li << c.create_toc if c.section_children.size>0
|
104
|
+
ul << li
|
105
|
+
end
|
106
|
+
ul
|
107
|
+
end
|
108
|
+
|
109
|
+
# Creates a latex toc.
|
110
|
+
# Call this on the root
|
111
|
+
def to_latex
|
112
|
+
to_latex_rec + "\n\n"
|
113
|
+
end
|
114
|
+
|
115
|
+
def to_latex_rec
|
116
|
+
s = ""
|
117
|
+
@section_children.each do |c|
|
118
|
+
s += "\\noindent"
|
119
|
+
number = c.header_element.section_number
|
120
|
+
s += number if number
|
121
|
+
text = c.header_element.children_to_latex
|
122
|
+
id = c.header_element.attributes[:id]
|
123
|
+
s += "\\hyperlink{#{id}}{#{text}}"
|
124
|
+
s += "\\dotfill \\pageref*{#{id}} \\linebreak\n"
|
125
|
+
s += c.to_latex_rec if c.section_children.size>0
|
126
|
+
|
127
|
+
end
|
128
|
+
s
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
class MDDocument
|
134
|
+
|
135
|
+
def create_toc
|
136
|
+
each_element(:header) do |h|
|
137
|
+
h.attributes[:id] ||= h.generate_id
|
138
|
+
end
|
139
|
+
|
140
|
+
stack = []
|
141
|
+
|
142
|
+
# the ancestor section
|
143
|
+
s = Section.new
|
144
|
+
s.section_level = 0
|
145
|
+
|
146
|
+
stack.push s
|
147
|
+
|
148
|
+
i = 0;
|
149
|
+
while i < @children.size
|
150
|
+
while i < @children.size
|
151
|
+
if @children[i].node_type == :header
|
152
|
+
level = @children[i].level
|
153
|
+
break if level <= stack.last.section_level+1
|
154
|
+
end
|
155
|
+
|
156
|
+
stack.last.immediate_children.push @children[i]
|
157
|
+
i += 1
|
158
|
+
end
|
159
|
+
|
160
|
+
break if i>=@children.size
|
161
|
+
|
162
|
+
header = @children[i]
|
163
|
+
level = header.level
|
164
|
+
|
165
|
+
if level > stack.last.section_level
|
166
|
+
# this level is inside
|
167
|
+
|
168
|
+
s2 = Section.new
|
169
|
+
s2.section_level = level
|
170
|
+
s2.header_element = header
|
171
|
+
header.instance_variable_set :@section, s2
|
172
|
+
|
173
|
+
stack.last.section_children.push s2
|
174
|
+
stack.push s2
|
175
|
+
|
176
|
+
i+=1
|
177
|
+
elsif level == stack.last.section_level
|
178
|
+
# this level is a sibling
|
179
|
+
stack.pop
|
180
|
+
else
|
181
|
+
# this level is a parent
|
182
|
+
stack.pop
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
# If there is only one big header, then assume
|
188
|
+
# it is the master
|
189
|
+
if s.section_children.size == 1
|
190
|
+
s = s.section_children.first
|
191
|
+
end
|
192
|
+
|
193
|
+
# Assign section numbers
|
194
|
+
s.numerate
|
195
|
+
|
196
|
+
s
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'maruku'
|
2
|
+
|
3
|
+
text = <<EOF
|
4
|
+
Chapter 1
|
5
|
+
=========
|
6
|
+
|
7
|
+
It was a stormy and rainy night.
|
8
|
+
|
9
|
+
EOF
|
10
|
+
|
11
|
+
invalid = <<EOF
|
12
|
+
|
13
|
+
This is a [bad link.
|
14
|
+
|
15
|
+
EOF
|
16
|
+
|
17
|
+
Maruku.new(text).to_html
|
18
|
+
|
19
|
+
s = ""
|
20
|
+
|
21
|
+
begin
|
22
|
+
Maruku.new(invalid, {:on_error => :raise, :error_stream => s})
|
23
|
+
puts "Error! It should have thrown an exception."
|
24
|
+
rescue
|
25
|
+
# puts "ok, got error"
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
Maruku.new(invalid, {:on_error => :warning, :error_stream => s})
|
30
|
+
rescue
|
31
|
+
puts "Error! It should not have thrown an exception."
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
|
3
|
+
#
|
4
|
+
# This file is part of Maruku.
|
5
|
+
#
|
6
|
+
# Maruku is free software; you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation; either version 2 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Maruku is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Maruku; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
#++
|
20
|
+
|
21
|
+
module MaRuKu
|
22
|
+
Version = '0.6.0'
|
23
|
+
|
24
|
+
MarukuURL = 'http://maruku.rubyforge.org/'
|
25
|
+
|
26
|
+
# If true, use also PHP Markdown extra syntax
|
27
|
+
#
|
28
|
+
# Note: it is not guaranteed that if it's false
|
29
|
+
# then no special features will be used.
|
30
|
+
#
|
31
|
+
# So please, ignore it for now.
|
32
|
+
def markdown_extra?
|
33
|
+
true
|
34
|
+
end
|
35
|
+
|
36
|
+
def new_meta_data?
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -6,10 +6,11 @@
|
|
6
6
|
# See CPriorityQueue and RubyPriorityQueue for more information.
|
7
7
|
unless $USE_RUBY
|
8
8
|
begin
|
9
|
-
|
9
|
+
require 'amp/priority_queue/CPriorityQueue'
|
10
10
|
PriorityQueue = CPriorityQueue
|
11
11
|
rescue LoadError # C Version could not be found, try ruby version
|
12
12
|
need { 'priority_queue/ruby_priority_queue' }
|
13
|
+
Amp::UI.debug "Loading alternative ruby: PriorityQueue"
|
13
14
|
PriorityQueue = RubyPriorityQueue
|
14
15
|
end
|
15
16
|
else
|
@@ -59,6 +59,7 @@ module PythonConfig
|
|
59
59
|
# through this class. See the README for tons of examples.
|
60
60
|
class ConfigParser
|
61
61
|
attr_reader :sections
|
62
|
+
COMMENT_REGEX = /^[;#]/
|
62
63
|
SECTION_REGEXP = /\[([^\[\]]*)\]/
|
63
64
|
ASSIGNMENT_REGEXP = /([^:=\s]+)\s*[:=]\s*([^\n]*?)$/
|
64
65
|
LONG_HEADER_REGEXP = /^([ \t]+)([^\n]+)$/
|
@@ -81,7 +82,7 @@ module PythonConfig
|
|
81
82
|
alias_method :dup, :clone
|
82
83
|
|
83
84
|
def parse_line(line) #:nodoc:
|
84
|
-
|
85
|
+
return if line =~ COMMENT_REGEX
|
85
86
|
if line =~ SECTION_REGEXP
|
86
87
|
section_name = $1
|
87
88
|
@cursection = add_section section_name
|