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,164 @@
|
|
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
|
+
class String
|
23
|
+
# XXX: markdown escaping
|
24
|
+
def to_md(c=nil)
|
25
|
+
to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
# " andrea censi " => [" andrea ", "censi "]
|
29
|
+
def mysplit
|
30
|
+
split.map{|x| x+" "}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
module MaRuKu; module Out; module Markdown
|
36
|
+
|
37
|
+
DefaultLineLength = 40
|
38
|
+
|
39
|
+
def to_md(context={})
|
40
|
+
children_to_md(context)
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_md_paragraph(context)
|
44
|
+
line_length = context[:line_length] || DefaultLineLength
|
45
|
+
wrap(@children, line_length, context)+"\n"
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_md_li_span(context)
|
49
|
+
len = (context[:line_length] || DefaultLineLength) - 2
|
50
|
+
s = add_tabs(wrap(@children, len-2, context), 1, ' ')
|
51
|
+
s[0] = ?*
|
52
|
+
s + "\n"
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_md_abbr_def(context)
|
56
|
+
"*[#{self.abbr}]: #{self.text}\n"
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_md_ol(context)
|
60
|
+
len = (context[:line_length] || DefaultLineLength) - 2
|
61
|
+
md = ""
|
62
|
+
self.children.each_with_index do |li, i|
|
63
|
+
s = add_tabs(w=wrap(li.children, len-2, context), 1, ' ')+"\n"
|
64
|
+
s[0,4] = "#{i+1}. "[0,4]
|
65
|
+
# puts w.inspect
|
66
|
+
md += s
|
67
|
+
end
|
68
|
+
md + "\n"
|
69
|
+
end
|
70
|
+
|
71
|
+
def to_md_ul(context)
|
72
|
+
len = (context[:line_length] || DefaultLineLength) - 2
|
73
|
+
md = ""
|
74
|
+
self.children.each_with_index do |li, i|
|
75
|
+
w = wrap(li.children, len-2, context)
|
76
|
+
# puts "W: "+ w.inspect
|
77
|
+
s = add_indent(w)
|
78
|
+
# puts "S: " +s.inspect
|
79
|
+
s[0,1] = "-"
|
80
|
+
md += s
|
81
|
+
end
|
82
|
+
md + "\n"
|
83
|
+
end
|
84
|
+
|
85
|
+
def add_indent(s,char=" ")
|
86
|
+
t = s.split("\n").map{|x| char+x }.join("\n")
|
87
|
+
s << ?\n if t[-1] == ?\n
|
88
|
+
s
|
89
|
+
end
|
90
|
+
|
91
|
+
# Convert each child to html
|
92
|
+
def children_to_md(context)
|
93
|
+
array_to_md(@children, context)
|
94
|
+
end
|
95
|
+
|
96
|
+
def wrap(array, line_length, context)
|
97
|
+
out = ""
|
98
|
+
line = ""
|
99
|
+
array.each do |c|
|
100
|
+
if c.kind_of?(MDElement) && c.node_type == :linebreak
|
101
|
+
out << line.strip << " \n"; line="";
|
102
|
+
next
|
103
|
+
end
|
104
|
+
|
105
|
+
pieces =
|
106
|
+
if c.kind_of? String
|
107
|
+
c.to_md.mysplit
|
108
|
+
else
|
109
|
+
[c.to_md(context)].flatten
|
110
|
+
end
|
111
|
+
|
112
|
+
# puts "Pieces: #{pieces.inspect}"
|
113
|
+
pieces.each do |p|
|
114
|
+
if p.size + line.size > line_length
|
115
|
+
out << line.strip << "\n";
|
116
|
+
line = ""
|
117
|
+
end
|
118
|
+
line << p
|
119
|
+
end
|
120
|
+
end
|
121
|
+
out << line.strip << "\n" if line.size > 0
|
122
|
+
out << ?\n if not out[-1] == ?\n
|
123
|
+
out
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
def array_to_md(array, context, join_char='')
|
128
|
+
e = []
|
129
|
+
array.each do |c|
|
130
|
+
method = c.kind_of?(MDElement) ?
|
131
|
+
"to_md_#{c.node_type}" : "to_md"
|
132
|
+
|
133
|
+
if not c.respond_to?(method)
|
134
|
+
#raise "Object does not answer to #{method}: #{c.class} #{c.inspect[0,100]}"
|
135
|
+
# tell_user "Using default for #{c.node_type}"
|
136
|
+
method = 'to_md'
|
137
|
+
end
|
138
|
+
|
139
|
+
# puts "#{c.inspect} created with method #{method}"
|
140
|
+
h = c.send(method, context)
|
141
|
+
|
142
|
+
if h.nil?
|
143
|
+
raise "Nil md for #{c.inspect} created with method #{method}"
|
144
|
+
end
|
145
|
+
|
146
|
+
if h.kind_of?Array
|
147
|
+
e = e + h
|
148
|
+
else
|
149
|
+
e << h
|
150
|
+
end
|
151
|
+
end
|
152
|
+
e.join(join_char)
|
153
|
+
end
|
154
|
+
|
155
|
+
end end end
|
156
|
+
|
157
|
+
module MaRuKu; class MDDocument
|
158
|
+
alias old_md to_md
|
159
|
+
def to_md(context={})
|
160
|
+
s = old_md(context)
|
161
|
+
# puts s
|
162
|
+
s
|
163
|
+
end
|
164
|
+
end end
|
@@ -0,0 +1,56 @@
|
|
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
|
+
# Strips all formatting from the string
|
27
|
+
def to_s
|
28
|
+
children_to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
def children_to_s
|
32
|
+
@children.join
|
33
|
+
end
|
34
|
+
|
35
|
+
# Generate an id for headers. Assumes @children is set.
|
36
|
+
def generate_id
|
37
|
+
|
38
|
+
title = children_to_s
|
39
|
+
title.gsub!(/ /,'_')
|
40
|
+
title.downcase!
|
41
|
+
title.gsub!(/[^\w_]/,'')
|
42
|
+
title.strip!
|
43
|
+
|
44
|
+
if title.size == 0
|
45
|
+
$uid ||= 0
|
46
|
+
$uid += 1
|
47
|
+
title = "id#{$uid}"
|
48
|
+
end
|
49
|
+
|
50
|
+
# random is a very bad idea
|
51
|
+
# title << "_" + rand(10000).to_s
|
52
|
+
title
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,191 @@
|
|
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
|
+
# Boring stuff with strings.
|
23
|
+
module MaRuKu; module Strings
|
24
|
+
|
25
|
+
def add_tabs(s,n=1,char="\t")
|
26
|
+
s.split("\n").map{|x| char*n+x }.join("\n")
|
27
|
+
end
|
28
|
+
|
29
|
+
TabSize = 4;
|
30
|
+
|
31
|
+
def split_lines(s)
|
32
|
+
s.gsub("\r","").split("\n")
|
33
|
+
end
|
34
|
+
|
35
|
+
# This parses email headers. Returns an hash.
|
36
|
+
#
|
37
|
+
# +hash['data']+ is the message.
|
38
|
+
#
|
39
|
+
# Keys are downcased, space becomes underscore, converted to symbols.
|
40
|
+
#
|
41
|
+
# My key: true
|
42
|
+
#
|
43
|
+
# becomes:
|
44
|
+
#
|
45
|
+
# {:my_key => true}
|
46
|
+
#
|
47
|
+
def parse_email_headers(s)
|
48
|
+
keys={}
|
49
|
+
match = (s =~ /\A((\w[\w\s\_\-]+: .*\n)+)\s*\n/)
|
50
|
+
if match != 0
|
51
|
+
keys[:data] = s
|
52
|
+
else
|
53
|
+
keys[:data] = $'
|
54
|
+
headers = $1
|
55
|
+
headers.split("\n").each do |l|
|
56
|
+
# Fails if there are other ':' characters.
|
57
|
+
# k, v = l.split(':')
|
58
|
+
k, v = l.split(':', 2)
|
59
|
+
k, v = normalize_key_and_value(k, v)
|
60
|
+
k = k.to_sym
|
61
|
+
# puts "K = #{k}, V=#{v}"
|
62
|
+
keys[k] = v
|
63
|
+
end
|
64
|
+
end
|
65
|
+
keys
|
66
|
+
end
|
67
|
+
|
68
|
+
# Keys are downcased, space becomes underscore, converted to symbols.
|
69
|
+
def normalize_key_and_value(k,v)
|
70
|
+
v = v ? v.strip : true # no value defaults to true
|
71
|
+
k = k.strip
|
72
|
+
|
73
|
+
# check synonyms
|
74
|
+
v = true if ['yes','true'].include?(v.to_s.downcase)
|
75
|
+
v = false if ['no','false'].include?(v.to_s.downcase)
|
76
|
+
|
77
|
+
k = k.downcase.gsub(' ','_')
|
78
|
+
return k, v
|
79
|
+
end
|
80
|
+
|
81
|
+
# Returns the number of leading spaces, considering that
|
82
|
+
# a tab counts as `TabSize` spaces.
|
83
|
+
def number_of_leading_spaces(s)
|
84
|
+
n=0; i=0;
|
85
|
+
while i < s.size
|
86
|
+
c = s[i,1]
|
87
|
+
if c == ' '
|
88
|
+
i+=1; n+=1;
|
89
|
+
elsif c == "\t"
|
90
|
+
i+=1; n+=TabSize;
|
91
|
+
else
|
92
|
+
break
|
93
|
+
end
|
94
|
+
end
|
95
|
+
n
|
96
|
+
end
|
97
|
+
|
98
|
+
# This returns the position of the first real char in a list item
|
99
|
+
#
|
100
|
+
# For example:
|
101
|
+
# '*Hello' # => 1
|
102
|
+
# '* Hello' # => 2
|
103
|
+
# ' * Hello' # => 3
|
104
|
+
# ' * Hello' # => 5
|
105
|
+
# '1.Hello' # => 2
|
106
|
+
# ' 1. Hello' # => 5
|
107
|
+
|
108
|
+
def spaces_before_first_char(s)
|
109
|
+
case s.md_type
|
110
|
+
when :ulist
|
111
|
+
i=0;
|
112
|
+
# skip whitespace if present
|
113
|
+
while s[i,1] =~ /\s/; i+=1 end
|
114
|
+
# skip indicator (+, -, *)
|
115
|
+
i+=1
|
116
|
+
# skip optional whitespace
|
117
|
+
while s[i,1] =~ /\s/; i+=1 end
|
118
|
+
return i
|
119
|
+
when :olist
|
120
|
+
i=0;
|
121
|
+
# skip whitespace
|
122
|
+
while s[i,1] =~ /\s/; i+=1 end
|
123
|
+
# skip digits
|
124
|
+
while s[i,1] =~ /\d/; i+=1 end
|
125
|
+
# skip dot
|
126
|
+
i+=1
|
127
|
+
# skip whitespace
|
128
|
+
while s[i,1] =~ /\s/; i+=1 end
|
129
|
+
return i
|
130
|
+
else
|
131
|
+
tell_user "BUG (my bad): '#{s}' is not a list"
|
132
|
+
0
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
# Counts the number of leading '#' in the string
|
137
|
+
def num_leading_hashes(s)
|
138
|
+
i=0;
|
139
|
+
while i<(s.size-1) && (s[i,1]=='#'); i+=1 end
|
140
|
+
i
|
141
|
+
end
|
142
|
+
|
143
|
+
# Strips initial and final hashes
|
144
|
+
def strip_hashes(s)
|
145
|
+
s = s[num_leading_hashes(s), s.size]
|
146
|
+
i = s.size-1
|
147
|
+
while i > 0 && (s[i,1] =~ /(#|\s)/); i-=1; end
|
148
|
+
s[0, i+1].strip
|
149
|
+
end
|
150
|
+
|
151
|
+
# change space to "_" and remove any non-word character
|
152
|
+
def sanitize_ref_id(x)
|
153
|
+
x.strip.downcase.gsub(' ','_').gsub(/[^\w]/,'')
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
# removes initial quote
|
158
|
+
def unquote(s)
|
159
|
+
s.gsub(/^>\s?/,'')
|
160
|
+
end
|
161
|
+
|
162
|
+
# toglie al massimo n caratteri
|
163
|
+
def strip_indent(s, n)
|
164
|
+
i = 0
|
165
|
+
while i < s.size && n>0
|
166
|
+
c = s[i,1]
|
167
|
+
if c == ' '
|
168
|
+
n-=1;
|
169
|
+
elsif c == "\t"
|
170
|
+
n-=TabSize;
|
171
|
+
else
|
172
|
+
break
|
173
|
+
end
|
174
|
+
i+=1
|
175
|
+
end
|
176
|
+
s[i, s.size]
|
177
|
+
end
|
178
|
+
|
179
|
+
def dbg_describe_ary(a, prefix='')
|
180
|
+
i = 0
|
181
|
+
a.each do |l|
|
182
|
+
puts "#{prefix} (#{i+=1})# #{l.inspect}"
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def force_linebreak?(l)
|
187
|
+
l =~ / $/
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
end
|
@@ -0,0 +1,167 @@
|
|
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 Module
|
24
|
+
def safe_attr_accessor1(symbol, klass)
|
25
|
+
attr_reader symbol
|
26
|
+
code = <<-EOF
|
27
|
+
def #{symbol}=(val)
|
28
|
+
if not val.kind_of? #{klass}
|
29
|
+
s = "\nCould not assign an object of type \#{val.class} to #{symbol}.\n\n"
|
30
|
+
s += "Tried to assign object of class \#{val.class}:\n"+
|
31
|
+
"\#{val.inspect}\n"+
|
32
|
+
"to \#{self.class}::#{symbol} constrained to be of class #{klass}.\n"
|
33
|
+
raise s
|
34
|
+
end
|
35
|
+
@#{symbol} = val
|
36
|
+
end
|
37
|
+
|
38
|
+
EOF
|
39
|
+
module_eval code
|
40
|
+
end
|
41
|
+
|
42
|
+
def safe_attr_accessor2(symbol, klass)
|
43
|
+
attr_accessor symbol
|
44
|
+
end
|
45
|
+
|
46
|
+
alias safe_attr_accessor safe_attr_accessor2
|
47
|
+
end
|
48
|
+
|
49
|
+
module MaRuKu
|
50
|
+
|
51
|
+
# I did not want to have a class for each possible element.
|
52
|
+
# Instead I opted to have only the class "MDElement"
|
53
|
+
# that represents eveything in the document (paragraphs, headers, etc).
|
54
|
+
#
|
55
|
+
# You can tell what it is by the variable `node_type`.
|
56
|
+
#
|
57
|
+
# In the instance-variable `children` there are the children. These
|
58
|
+
# can be of class 1) String or 2) MDElement.
|
59
|
+
#
|
60
|
+
# The @doc variable points to the document to which the MDElement
|
61
|
+
# belongs (which is an instance of Maruku, subclass of MDElement).
|
62
|
+
#
|
63
|
+
# Attributes are contained in the hash `attributes`.
|
64
|
+
# Keys are symbols (downcased, with spaces substituted by underscores)
|
65
|
+
#
|
66
|
+
# For example, if you write in the source document.
|
67
|
+
#
|
68
|
+
# Title: test document
|
69
|
+
# My property: value
|
70
|
+
#
|
71
|
+
# content content
|
72
|
+
#
|
73
|
+
# You can access `value` by writing:
|
74
|
+
#
|
75
|
+
# @doc.attributes[:my_property] # => 'value'
|
76
|
+
#
|
77
|
+
# from whichever MDElement in the hierarchy.
|
78
|
+
#
|
79
|
+
class MDElement
|
80
|
+
# See helpers.rb for the list of allowed #node_type values
|
81
|
+
safe_attr_accessor :node_type, Symbol
|
82
|
+
|
83
|
+
# Children are either Strings or MDElement
|
84
|
+
safe_attr_accessor :children, Array
|
85
|
+
|
86
|
+
# An attribute list, may not be nil
|
87
|
+
safe_attr_accessor :al, Array #Maruku::AttributeList
|
88
|
+
|
89
|
+
# These are the processed attributes
|
90
|
+
safe_attr_accessor :attributes, Hash
|
91
|
+
|
92
|
+
# Reference of the document (which is of class Maruku)
|
93
|
+
attr_accessor :doc
|
94
|
+
|
95
|
+
def initialize(node_type=:unset, children=[], meta={},
|
96
|
+
al=MaRuKu::AttributeList.new )
|
97
|
+
super();
|
98
|
+
self.children = children
|
99
|
+
self.node_type = node_type
|
100
|
+
|
101
|
+
@attributes = {}
|
102
|
+
|
103
|
+
meta.each do |symbol, value|
|
104
|
+
self.instance_eval "
|
105
|
+
def #{symbol}; @#{symbol}; end
|
106
|
+
def #{symbol}=(val); @#{symbol}=val; end"
|
107
|
+
self.send "#{symbol}=", value
|
108
|
+
end
|
109
|
+
|
110
|
+
self.al = al || AttributeList.new
|
111
|
+
|
112
|
+
self.meta_priv = meta
|
113
|
+
end
|
114
|
+
|
115
|
+
attr_accessor :meta_priv
|
116
|
+
|
117
|
+
def ==(o)
|
118
|
+
ok = o.kind_of?(MDElement) &&
|
119
|
+
(self.node_type == o.node_type) &&
|
120
|
+
(self.meta_priv == o.meta_priv) &&
|
121
|
+
(self.children == o.children)
|
122
|
+
|
123
|
+
if not ok
|
124
|
+
# puts "This:\n"+self.inspect+"\nis different from\n"+o.inspect+"\n\n"
|
125
|
+
end
|
126
|
+
ok
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# This represents the whole document and holds global data.
|
131
|
+
|
132
|
+
class MDDocument
|
133
|
+
|
134
|
+
safe_attr_accessor :refs, Hash
|
135
|
+
safe_attr_accessor :footnotes, Hash
|
136
|
+
|
137
|
+
# This is an hash. The key might be nil.
|
138
|
+
safe_attr_accessor :abbreviations, Hash
|
139
|
+
|
140
|
+
# Attribute lists definition
|
141
|
+
safe_attr_accessor :ald, Hash
|
142
|
+
|
143
|
+
# The order in which footnotes are used. Contains the id.
|
144
|
+
safe_attr_accessor :footnotes_order, Array
|
145
|
+
|
146
|
+
safe_attr_accessor :latex_required_packages, Array
|
147
|
+
|
148
|
+
safe_attr_accessor :refid2ref, Hash
|
149
|
+
|
150
|
+
def initialize(s=nil)
|
151
|
+
super(:document)
|
152
|
+
@doc = self
|
153
|
+
|
154
|
+
self.refs = {}
|
155
|
+
self.footnotes = {}
|
156
|
+
self.footnotes_order = []
|
157
|
+
self.abbreviations = {}
|
158
|
+
self.ald = {}
|
159
|
+
self.latex_required_packages = []
|
160
|
+
|
161
|
+
parse_doc(s) if s
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
end # MaRuKu
|
167
|
+
|