amp 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (232) hide show
  1. data/.gitignore +12 -0
  2. data/.hgignore +3 -0
  3. data/AUTHORS +1 -1
  4. data/Manifest.txt +99 -38
  5. data/README.md +3 -3
  6. data/Rakefile +53 -18
  7. data/SCHEDULE.markdown +5 -1
  8. data/TODO.markdown +120 -149
  9. data/ampfile.rb +3 -1
  10. data/bin/amp +4 -1
  11. data/ext/amp/bz2/extconf.rb +1 -1
  12. data/ext/amp/mercurial_patch/extconf.rb +1 -1
  13. data/ext/amp/mercurial_patch/mpatch.c +4 -3
  14. data/ext/amp/priority_queue/extconf.rb +1 -1
  15. data/ext/amp/support/extconf.rb +1 -1
  16. data/ext/amp/support/support.c +1 -1
  17. data/lib/amp.rb +125 -67
  18. data/lib/amp/commands/command.rb +12 -10
  19. data/lib/amp/commands/command_support.rb +8 -1
  20. data/lib/amp/commands/commands/help.rb +2 -20
  21. data/lib/amp/commands/commands/init.rb +14 -2
  22. data/lib/amp/commands/commands/templates.rb +6 -4
  23. data/lib/amp/commands/commands/version.rb +15 -1
  24. data/lib/amp/commands/commands/workflow.rb +3 -3
  25. data/lib/amp/commands/commands/workflows/git/add.rb +3 -3
  26. data/lib/amp/commands/commands/workflows/git/copy.rb +1 -1
  27. data/lib/amp/commands/commands/workflows/git/rm.rb +4 -2
  28. data/lib/amp/commands/commands/workflows/hg/add.rb +1 -1
  29. data/lib/amp/commands/commands/workflows/hg/addremove.rb +2 -2
  30. data/lib/amp/commands/commands/workflows/hg/annotate.rb +8 -2
  31. data/lib/amp/commands/commands/workflows/hg/bisect.rb +253 -0
  32. data/lib/amp/commands/commands/workflows/hg/branch.rb +1 -1
  33. data/lib/amp/commands/commands/workflows/hg/branches.rb +3 -3
  34. data/lib/amp/commands/commands/workflows/hg/bundle.rb +3 -3
  35. data/lib/amp/commands/commands/workflows/hg/clone.rb +4 -5
  36. data/lib/amp/commands/commands/workflows/hg/commit.rb +37 -1
  37. data/lib/amp/commands/commands/workflows/hg/copy.rb +2 -1
  38. data/lib/amp/commands/commands/workflows/hg/debug/index.rb +1 -1
  39. data/lib/amp/commands/commands/workflows/hg/diff.rb +3 -8
  40. data/lib/amp/commands/commands/workflows/hg/forget.rb +5 -4
  41. data/lib/amp/commands/commands/workflows/hg/identify.rb +6 -6
  42. data/lib/amp/commands/commands/workflows/hg/import.rb +1 -1
  43. data/lib/amp/commands/commands/workflows/hg/incoming.rb +2 -2
  44. data/lib/amp/commands/commands/workflows/hg/log.rb +5 -4
  45. data/lib/amp/commands/commands/workflows/hg/merge.rb +1 -1
  46. data/lib/amp/commands/commands/workflows/hg/move.rb +5 -3
  47. data/lib/amp/commands/commands/workflows/hg/outgoing.rb +1 -1
  48. data/lib/amp/commands/commands/workflows/hg/push.rb +6 -7
  49. data/lib/amp/commands/commands/workflows/hg/remove.rb +2 -2
  50. data/lib/amp/commands/commands/workflows/hg/resolve.rb +6 -23
  51. data/lib/amp/commands/commands/workflows/hg/root.rb +1 -2
  52. data/lib/amp/commands/commands/workflows/hg/status.rb +21 -12
  53. data/lib/amp/commands/commands/workflows/hg/tag.rb +2 -2
  54. data/lib/amp/commands/commands/workflows/hg/untrack.rb +12 -0
  55. data/lib/amp/commands/commands/workflows/hg/verify.rb +13 -3
  56. data/lib/amp/commands/commands/workflows/hg/what_changed.rb +18 -0
  57. data/lib/amp/commands/dispatch.rb +12 -13
  58. data/lib/amp/dependencies/amp_support.rb +1 -1
  59. data/lib/amp/dependencies/amp_support/ruby_amp_support.rb +1 -0
  60. data/lib/amp/dependencies/maruku.rb +136 -0
  61. data/lib/amp/dependencies/maruku/attributes.rb +227 -0
  62. data/lib/amp/dependencies/maruku/defaults.rb +71 -0
  63. data/lib/amp/dependencies/maruku/errors_management.rb +92 -0
  64. data/lib/amp/dependencies/maruku/helpers.rb +260 -0
  65. data/lib/amp/dependencies/maruku/input/charsource.rb +326 -0
  66. data/lib/amp/dependencies/maruku/input/extensions.rb +69 -0
  67. data/lib/amp/dependencies/maruku/input/html_helper.rb +189 -0
  68. data/lib/amp/dependencies/maruku/input/linesource.rb +111 -0
  69. data/lib/amp/dependencies/maruku/input/parse_block.rb +615 -0
  70. data/lib/amp/dependencies/maruku/input/parse_doc.rb +234 -0
  71. data/lib/amp/dependencies/maruku/input/parse_span_better.rb +746 -0
  72. data/lib/amp/dependencies/maruku/input/rubypants.rb +225 -0
  73. data/lib/amp/dependencies/maruku/input/type_detection.rb +147 -0
  74. data/lib/amp/dependencies/maruku/input_textile2/t2_parser.rb +163 -0
  75. data/lib/amp/dependencies/maruku/maruku.rb +33 -0
  76. data/lib/amp/dependencies/maruku/output/to_ansi.rb +223 -0
  77. data/lib/amp/dependencies/maruku/output/to_html.rb +991 -0
  78. data/lib/amp/dependencies/maruku/output/to_markdown.rb +164 -0
  79. data/lib/amp/dependencies/maruku/output/to_s.rb +56 -0
  80. data/lib/amp/dependencies/maruku/string_utils.rb +191 -0
  81. data/lib/amp/dependencies/maruku/structures.rb +167 -0
  82. data/lib/amp/dependencies/maruku/structures_inspect.rb +87 -0
  83. data/lib/amp/dependencies/maruku/structures_iterators.rb +61 -0
  84. data/lib/amp/dependencies/maruku/textile2.rb +1 -0
  85. data/lib/amp/dependencies/maruku/toc.rb +199 -0
  86. data/lib/amp/dependencies/maruku/usage/example1.rb +33 -0
  87. data/lib/amp/dependencies/maruku/version.rb +40 -0
  88. data/lib/amp/dependencies/priority_queue.rb +2 -1
  89. data/lib/amp/dependencies/python_config.rb +2 -1
  90. data/lib/amp/graphs/ancestor.rb +2 -1
  91. data/lib/amp/graphs/copies.rb +236 -233
  92. data/lib/amp/help/entries/__default__.erb +31 -0
  93. data/lib/amp/help/entries/commands.erb +6 -0
  94. data/lib/amp/help/entries/mdtest.md +35 -0
  95. data/lib/amp/help/entries/silly +3 -0
  96. data/lib/amp/help/help.rb +288 -0
  97. data/lib/amp/profiling_hacks.rb +5 -3
  98. data/lib/amp/repository/abstract/abstract_changeset.rb +97 -0
  99. data/lib/amp/repository/abstract/abstract_local_repo.rb +181 -0
  100. data/lib/amp/repository/abstract/abstract_staging_area.rb +180 -0
  101. data/lib/amp/repository/abstract/abstract_versioned_file.rb +100 -0
  102. data/lib/amp/repository/abstract/common_methods/changeset.rb +75 -0
  103. data/lib/amp/repository/abstract/common_methods/local_repo.rb +277 -0
  104. data/lib/amp/repository/abstract/common_methods/staging_area.rb +233 -0
  105. data/lib/amp/repository/abstract/common_methods/versioned_file.rb +71 -0
  106. data/lib/amp/repository/generic_repo_picker.rb +78 -0
  107. data/lib/amp/repository/git/repo_format/changeset.rb +336 -0
  108. data/lib/amp/repository/git/repo_format/staging_area.rb +192 -0
  109. data/lib/amp/repository/git/repo_format/versioned_file.rb +119 -0
  110. data/lib/amp/repository/git/repositories/local_repository.rb +164 -0
  111. data/lib/amp/repository/git/repository.rb +41 -0
  112. data/lib/amp/repository/mercurial/encoding/mercurial_diff.rb +382 -0
  113. data/lib/amp/repository/mercurial/encoding/mercurial_patch.rb +1 -0
  114. data/lib/amp/repository/mercurial/encoding/patch.rb +294 -0
  115. data/lib/amp/repository/mercurial/encoding/pure_ruby/ruby_mercurial_patch.rb +124 -0
  116. data/lib/amp/repository/mercurial/merging/merge_ui.rb +327 -0
  117. data/lib/amp/repository/mercurial/merging/simple_merge.rb +452 -0
  118. data/lib/amp/repository/mercurial/repo_format/branch_manager.rb +266 -0
  119. data/lib/amp/repository/mercurial/repo_format/changeset.rb +768 -0
  120. data/lib/amp/repository/mercurial/repo_format/dir_state.rb +716 -0
  121. data/lib/amp/repository/mercurial/repo_format/journal.rb +218 -0
  122. data/lib/amp/repository/mercurial/repo_format/lock.rb +210 -0
  123. data/lib/amp/repository/mercurial/repo_format/merge_state.rb +228 -0
  124. data/lib/amp/repository/mercurial/repo_format/staging_area.rb +367 -0
  125. data/lib/amp/repository/mercurial/repo_format/store.rb +487 -0
  126. data/lib/amp/repository/mercurial/repo_format/tag_manager.rb +322 -0
  127. data/lib/amp/repository/mercurial/repo_format/updatable.rb +543 -0
  128. data/lib/amp/repository/mercurial/repo_format/updater.rb +848 -0
  129. data/lib/amp/repository/mercurial/repo_format/verification.rb +433 -0
  130. data/lib/amp/repository/mercurial/repositories/bundle_repository.rb +216 -0
  131. data/lib/amp/repository/mercurial/repositories/http_repository.rb +386 -0
  132. data/lib/amp/repository/mercurial/repositories/local_repository.rb +2034 -0
  133. data/lib/amp/repository/mercurial/repository.rb +119 -0
  134. data/lib/amp/repository/mercurial/revlogs/bundle_revlogs.rb +249 -0
  135. data/lib/amp/repository/mercurial/revlogs/changegroup.rb +217 -0
  136. data/lib/amp/repository/mercurial/revlogs/changelog.rb +339 -0
  137. data/lib/amp/repository/mercurial/revlogs/file_log.rb +152 -0
  138. data/lib/amp/repository/mercurial/revlogs/index.rb +500 -0
  139. data/lib/amp/repository/mercurial/revlogs/manifest.rb +201 -0
  140. data/lib/amp/repository/mercurial/revlogs/node.rb +20 -0
  141. data/lib/amp/repository/mercurial/revlogs/revlog.rb +1026 -0
  142. data/lib/amp/repository/mercurial/revlogs/revlog_support.rb +129 -0
  143. data/lib/amp/repository/mercurial/revlogs/versioned_file.rb +597 -0
  144. data/lib/amp/repository/repository.rb +11 -88
  145. data/lib/amp/server/extension/amp_extension.rb +3 -3
  146. data/lib/amp/server/fancy_http_server.rb +1 -1
  147. data/lib/amp/server/fancy_views/_browser.haml +1 -1
  148. data/lib/amp/server/fancy_views/_diff_file.haml +1 -8
  149. data/lib/amp/server/fancy_views/changeset.haml +2 -2
  150. data/lib/amp/server/fancy_views/file.haml +1 -1
  151. data/lib/amp/server/fancy_views/file_diff.haml +1 -1
  152. data/lib/amp/support/amp_ui.rb +13 -29
  153. data/lib/amp/support/generator.rb +1 -1
  154. data/lib/amp/support/loaders.rb +1 -2
  155. data/lib/amp/support/logger.rb +10 -16
  156. data/lib/amp/support/match.rb +18 -4
  157. data/lib/amp/support/mercurial/ignore.rb +151 -0
  158. data/lib/amp/support/openers.rb +8 -3
  159. data/lib/amp/support/support.rb +91 -46
  160. data/lib/amp/templates/{blank.commit.erb → mercurial/blank.commit.erb} +0 -0
  161. data/lib/amp/templates/{blank.log.erb → mercurial/blank.log.erb} +0 -0
  162. data/lib/amp/templates/{default.commit.erb → mercurial/default.commit.erb} +0 -0
  163. data/lib/amp/templates/{default.log.erb → mercurial/default.log.erb} +0 -0
  164. data/lib/amp/templates/template.rb +18 -18
  165. data/man/amp.1 +51 -0
  166. data/site/src/about/commands.haml +1 -1
  167. data/site/src/css/amp.css +1 -1
  168. data/site/src/index.haml +3 -3
  169. data/tasks/man.rake +39 -0
  170. data/tasks/stats.rake +1 -10
  171. data/tasks/yard.rake +1 -50
  172. data/test/dirstate_tests/test_dir_state.rb +10 -8
  173. data/test/functional_tests/annotate.out +31 -0
  174. data/test/functional_tests/test_functional.rb +155 -63
  175. data/test/localrepo_tests/ampfile.rb +12 -0
  176. data/test/localrepo_tests/test_local_repo.rb +56 -57
  177. data/test/manifest_tests/test_manifest.rb +3 -5
  178. data/test/merge_tests/test_merge.rb +3 -3
  179. data/test/revlog_tests/test_revlog.rb +14 -6
  180. data/test/store_tests/test_fncache_store.rb +19 -19
  181. data/test/test_19_compatibility.rb +46 -0
  182. data/test/test_base85.rb +2 -2
  183. data/test/test_bdiff.rb +2 -2
  184. data/test/test_changegroup.rb +59 -0
  185. data/test/test_commands.rb +2 -2
  186. data/test/test_difflib.rb +2 -2
  187. data/test/test_generator.rb +34 -0
  188. data/test/test_ignore.rb +203 -0
  189. data/test/test_journal.rb +18 -13
  190. data/test/test_match.rb +2 -2
  191. data/test/test_mdiff.rb +3 -3
  192. data/test/test_mpatch.rb +3 -3
  193. data/test/test_multi_io.rb +40 -0
  194. data/test/test_support.rb +18 -2
  195. data/test/test_templates.rb +38 -0
  196. data/test/test_ui.rb +79 -0
  197. data/test/testutilities.rb +56 -0
  198. metadata +168 -49
  199. data/ext/amp/bz2/mkmf.log +0 -38
  200. data/lib/amp/encoding/mercurial_diff.rb +0 -378
  201. data/lib/amp/encoding/mercurial_patch.rb +0 -1
  202. data/lib/amp/encoding/patch.rb +0 -292
  203. data/lib/amp/encoding/pure_ruby/ruby_mercurial_patch.rb +0 -123
  204. data/lib/amp/merges/merge_state.rb +0 -164
  205. data/lib/amp/merges/merge_ui.rb +0 -322
  206. data/lib/amp/merges/simple_merge.rb +0 -450
  207. data/lib/amp/repository/branch_manager.rb +0 -234
  208. data/lib/amp/repository/dir_state.rb +0 -950
  209. data/lib/amp/repository/journal.rb +0 -203
  210. data/lib/amp/repository/lock.rb +0 -207
  211. data/lib/amp/repository/repositories/bundle_repository.rb +0 -214
  212. data/lib/amp/repository/repositories/http_repository.rb +0 -377
  213. data/lib/amp/repository/repositories/local_repository.rb +0 -2661
  214. data/lib/amp/repository/store.rb +0 -485
  215. data/lib/amp/repository/tag_manager.rb +0 -319
  216. data/lib/amp/repository/updatable.rb +0 -532
  217. data/lib/amp/repository/verification.rb +0 -431
  218. data/lib/amp/repository/versioned_file.rb +0 -475
  219. data/lib/amp/revlogs/bundle_revlogs.rb +0 -246
  220. data/lib/amp/revlogs/changegroup.rb +0 -217
  221. data/lib/amp/revlogs/changelog.rb +0 -338
  222. data/lib/amp/revlogs/changeset.rb +0 -521
  223. data/lib/amp/revlogs/file_log.rb +0 -165
  224. data/lib/amp/revlogs/index.rb +0 -493
  225. data/lib/amp/revlogs/manifest.rb +0 -195
  226. data/lib/amp/revlogs/node.rb +0 -18
  227. data/lib/amp/revlogs/revlog.rb +0 -1045
  228. data/lib/amp/revlogs/revlog_support.rb +0 -126
  229. data/lib/amp/support/ignore.rb +0 -144
  230. data/site/Rakefile +0 -38
  231. data/test/test_amp.rb +0 -9
  232. data/test/test_helper.rb +0 -15
@@ -42,7 +42,7 @@ command :tag do |c|
42
42
  raise abort("tag #{name} is not a #{expected_type} tag")
43
43
  end
44
44
  end
45
- rev = Amp::RevlogSupport::Node::NULL_ID
45
+ rev = Amp::Mercurial::RevlogSupport::Node::NULL_ID
46
46
  message ||= "Removed tag #{names.join(", ")}"
47
47
  elsif !opts[:force]
48
48
  names.each do |name|
@@ -53,7 +53,7 @@ command :tag do |c|
53
53
  end
54
54
  end
55
55
 
56
- if !rev && repo.dirstate.parents[1] != Amp::RevlogSupport::Node::NULL_ID
56
+ if !rev && repo.dirstate.parents[1] != Amp::Mercurial::RevlogSupport::Node::NULL_ID
57
57
  raise abort("uncommited merge - please provide" +
58
58
  " a specific revision")
59
59
  end
@@ -0,0 +1,12 @@
1
+ command :untrack do |c|
2
+ c.workflow :hg
3
+ c.desc "Stop tracking the file"
4
+
5
+ c.on_run do |opts, args|
6
+ opts[:"no-unlink"] = true
7
+ opts[:quiet] = true
8
+
9
+ puts "Forgetting #{args.size} file#{args.size == 1 ? '' : 's'}"
10
+ Amp::Command['remove'].run opts, args
11
+ end
12
+ end
@@ -1,9 +1,19 @@
1
1
  command :verify do |c|
2
- c.desc "Verifies the mercurial repository, checking for integrity errors"
3
2
  c.workflow :hg
3
+
4
+ c.desc "Verifies the mercurial repository, checking for integrity errors"
4
5
  c.on_run do |opts, args|
5
6
  results = opts[:repository].verify
6
- puts "#{results.files} files, #{results.changesets} changesets, #{results.revisions} revisions"
7
- puts "#{results.errors} integrity errors, #{results.warnings} warnings." if results.errors > 0 || results.warnings > 0
7
+
8
+ Amp::UI.tell "#{results.files} file#{results.files == 1 ? '' : 's' }, "
9
+ Amp::UI.tell "#{results.changesets} changeset#{results.changesets == 1 ? '' : 's' }, "
10
+ Amp::UI.tell "#{results.revisions} revision#{results.revisions == 1 ? '' : 's' }"
11
+
12
+ if results.errors > 0 || results.warnings > 0
13
+ Amp::UI.tell ", #{results.errors} integrity error#{results.errors == 1 ? '' : 's' }, "
14
+ Amp::UI.tell "#{results.warnings} warning#{results.warnings == 1 ? '' : 's' }."
15
+ end
16
+
17
+ Amp::UI.say
8
18
  end
9
19
  end
@@ -0,0 +1,18 @@
1
+ command :"what-changed" do |c|
2
+ c.workflow :hg
3
+
4
+ c.desc "Which commits have touched this file?"
5
+ c.opt :limit, "Limit how many revisions to show", :short => "-l", :type => :integer, :default => -1
6
+ c.opt :template, "Which template to use while printing", :short => "-t", :type => :string, :default => "default"
7
+
8
+ c.on_run do |opts, args|
9
+ repo = opts[:repository]
10
+ file = repo.versioned_file args.shift
11
+ revs = file.map {|vf| vf.link_rev }
12
+ revs = revs[-opts[:limit]..-1] unless opts[:limit] <= 0
13
+
14
+ revs.reverse.each do |rev|
15
+ Amp::UI.say repo[rev].to_templated_s(opts)
16
+ end
17
+ end
18
+ end
@@ -21,7 +21,7 @@ module Amp
21
21
  global_opts = Trollop::options do
22
22
  banner "Amp - some more crystal, sir?"
23
23
  version "Amp version #{Amp::VERSION} (#{Amp::VERSION_TITLE})"
24
- opt :debug_opts, "Debug the command-line options", :short => "-d", :default => false, :type => :boolean
24
+ opt :"debug-opts", "Debug the command-line options", :short => "-d"
25
25
  opt :verbose, "Verbose output"
26
26
  opt :profile, "Profile the command being run, running it the given number of times"
27
27
  opt :repository, "The path to the repository to use", :short => "-R", :type => :string, :default => Dir.pwd
@@ -41,14 +41,12 @@ module Amp
41
41
  $USE_RUBY = true
42
42
  end
43
43
 
44
- global_config = Amp::AmpConfig.new
44
+ global_config = Amp::AmpConfig.new
45
45
  Amp::UI.config = global_config
46
- cmd = ARGV.shift # get the subcommand
47
- cmd ||= "default"
46
+ cmd = ARGV.shift || "default" # get the subcommand
47
+ opts_as_arr = ARGV.dup
48
48
 
49
- opts_as_arr = ARGV.dup
50
-
51
- if global_opts[:debug_opts]
49
+ if global_opts[:"debug-opts"]
52
50
  global_config["debug", "messages"] = true
53
51
  end
54
52
 
@@ -94,7 +92,7 @@ module Amp
94
92
 
95
93
  unless command
96
94
  puts "Invalid command! #{cmd}"
97
- exit(-1)
95
+ return false
98
96
  end
99
97
 
100
98
  # get the sub-command's options
@@ -102,7 +100,7 @@ module Amp
102
100
  cmd_opts.merge!(command.collect_options) {|k, v1, v2| v2 || v1 }
103
101
 
104
102
  cmd_opts[:global_config] = local_config
105
- if global_opts[:debug_opts]
103
+ if global_opts[:"debug-opts"]
106
104
  require 'yaml'
107
105
  puts "Current directory: #{Dir.pwd}"
108
106
  puts "Global options: \n#{global_opts.inspect.to_yaml}"
@@ -115,14 +113,16 @@ module Amp
115
113
  puts
116
114
  end
117
115
 
116
+ result = false
118
117
  # Run that fucker!!!
119
118
  begin
120
- full_backtrace_please do
121
- command.run cmd_opts, ARGV
122
- end
119
+ #full_backtrace_please do
120
+ result = command.run cmd_opts, ARGV
121
+ #end
123
122
  rescue AbortError => e
124
123
  puts e.to_s
125
124
  end
125
+ result
126
126
  end
127
127
 
128
128
  ##
@@ -164,7 +164,6 @@ module Amp
164
164
 
165
165
  if prefix_list.size > 1
166
166
  puts "Ambiguous command: #{cmd}. Could mean: #{prefix_list.join(", ")}"
167
- exit(-1)
168
167
  end
169
168
  nil
170
169
  end
@@ -1 +1 @@
1
- amp_c_extension '../../../ext/amp/support/Support', 'amp_support/ruby_amp_support'
1
+ amp_c_extension 'amp/support/CSupport', 'amp_support/ruby_amp_support'
@@ -1,3 +1,4 @@
1
+ p "LOADING RUBY AMP SUPPORT"
1
2
  ##
2
3
  # Ruby versions of slow functions we've implemented in C
3
4
  class Integer
@@ -0,0 +1,136 @@
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
+ require 'rexml/document'
22
+
23
+ dir_path = File.expand_path(File.dirname(__FILE__))
24
+ $:.unshift dir_path
25
+
26
+ # :include:MaRuKu.txt
27
+ module MaRuKu
28
+
29
+ module In
30
+ module Markdown
31
+ module SpanLevelParser; end
32
+ module BlockLevelParser; end
33
+ end
34
+ # more to come?
35
+ end
36
+
37
+ module Out
38
+ # Functions for exporting to MarkDown.
39
+ module Markdown; end
40
+ # Functions for exporting to HTML.
41
+ module HTML; end
42
+ # Functions for exporting to ANSI
43
+ module Ansi; end
44
+ end
45
+
46
+ # These are strings utilities.
47
+ module Strings; end
48
+
49
+ module Helpers; end
50
+
51
+ module Errors; end
52
+
53
+ class MDElement
54
+ include REXML
55
+ include MaRuKu
56
+ include Out::Markdown
57
+ include Out::HTML
58
+ include Out::Ansi
59
+ include Strings
60
+ include Helpers
61
+ include Errors
62
+ end
63
+
64
+
65
+ class MDDocument < MDElement
66
+ include In::Markdown
67
+ include In::Markdown::SpanLevelParser
68
+ include In::Markdown::BlockLevelParser
69
+ end
70
+ end
71
+
72
+ # This is the public interface
73
+ class Maruku < MaRuKu::MDDocument; end
74
+
75
+
76
+
77
+ require 'rexml/document'
78
+
79
+ # Structures definition
80
+ require 'maruku/structures'
81
+ require 'maruku/structures_inspect'
82
+
83
+ require 'maruku/defaults'
84
+ # Less typing
85
+ require 'maruku/helpers'
86
+
87
+ # Code for parsing whole Markdown documents
88
+ require 'maruku/input/parse_doc'
89
+
90
+ # Ugly things kept in a closet
91
+ require 'maruku/string_utils'
92
+ require 'maruku/input/linesource'
93
+ require 'maruku/input/type_detection'
94
+
95
+ # A class for reading and sanitizing inline HTML
96
+ require 'maruku/input/html_helper'
97
+
98
+ # Code for parsing Markdown block-level elements
99
+ require 'maruku/input/parse_block'
100
+
101
+ # Code for parsing Markdown span-level elements
102
+ require 'maruku/input/charsource'
103
+ require 'maruku/input/parse_span_better'
104
+ require 'maruku/input/rubypants'
105
+
106
+ require 'maruku/input/extensions'
107
+
108
+ require 'maruku/attributes'
109
+
110
+ require 'maruku/structures_iterators'
111
+
112
+ require 'maruku/errors_management'
113
+
114
+ # Code for creating a table of contents
115
+ require 'maruku/toc'
116
+
117
+ # Version and URL
118
+ require 'maruku/version'
119
+
120
+
121
+ # Exporting to html
122
+ require 'maruku/output/to_html'
123
+
124
+ # Exporting to ansi terminal output
125
+ require 'maruku/output/to_ansi'
126
+
127
+ # Pretty print
128
+ require 'maruku/output/to_markdown'
129
+
130
+ # Exporting to text: strips all formatting (not complete)
131
+ require 'maruku/output/to_s'
132
+
133
+ # class Maruku is the global interface
134
+ require 'maruku/maruku'
135
+
136
+ $:.delete dir_path
@@ -0,0 +1,227 @@
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
+ def quote_if_needed
24
+ if /[\s\'\"]/.match self
25
+ inspect
26
+ else
27
+ self
28
+ end
29
+ end
30
+ end
31
+
32
+ module MaRuKu;
33
+ MagicChar = ':'
34
+
35
+ class AttributeList < Array
36
+
37
+ # An attribute list becomes
38
+ # {#id .cl key="val" ref}
39
+ # [ [:id, 'id'], [:class, 'id'], ['key', 'val'], [ :ref, 'ref' ]]
40
+
41
+ private :push
42
+
43
+ def push_key_val(key, val);
44
+ raise "Bad #{key.inspect}=#{val.inspect}" if not key and val
45
+ push [key, val]
46
+ end
47
+ def push_ref(ref_id);
48
+
49
+ raise "Bad :ref #{ref_id.inspect}" if not ref_id
50
+ push [:ref, ref_id+""]
51
+
52
+ # p "Now ", self ########################################
53
+ end
54
+ def push_class(val);
55
+ raise "Bad :id #{val.inspect}" if not val
56
+ push [:class, val]
57
+ end
58
+ def push_id(val);
59
+ raise "Bad :id #{val.inspect}" if not val
60
+ push [:id, val]
61
+ end
62
+
63
+ def to_s
64
+ map do |k,v|
65
+ case k
66
+ when :id; "#" + v.quote_if_needed
67
+ when :class; "." + v.quote_if_needed
68
+ when :ref; v.quote_if_needed
69
+ else k.quote_if_needed + "=" + v.quote_if_needed
70
+ end
71
+ end . join(' ')
72
+ end
73
+ alias to_md to_s
74
+ end
75
+
76
+ end
77
+
78
+ module MaRuKu; module In; module Markdown; module SpanLevelParser
79
+
80
+ def unit_tests_for_attribute_lists
81
+ [
82
+ [ "", [], "Empty lists are allowed" ],
83
+ [ "=", :throw, "Bad char to begin a list with." ],
84
+ [ "a =b", :throw, "No whitespace before `=`." ],
85
+ [ "a= b", :throw, "No whitespace after `=`." ],
86
+
87
+ [ "a b", [[:ref, 'a'],[:ref, 'b']], "More than one ref" ],
88
+ [ "a b c", [[:ref, 'a'],[:ref, 'b'],[:ref, 'c']], "More than one ref" ],
89
+ [ "hello notfound", [[:ref, 'hello'],[:ref, 'notfound']]],
90
+
91
+ [ "'a'", [[:ref, 'a']], "Quoted value." ],
92
+ [ '"a"' ],
93
+
94
+ [ "a=b", [['a','b']], "Simple key/val" ],
95
+ [ "'a'=b" ],
96
+ [ "'a'='b'" ],
97
+ [ "a='b'" ],
98
+
99
+ [ 'a="b\'"', [['a',"b\'"]], "Key/val with quotes" ],
100
+ [ 'a=b\''],
101
+ [ 'a="\\\'b\'"', [['a',"\'b\'"]], "Key/val with quotes" ],
102
+
103
+ ['"', :throw, "Unclosed quotes"],
104
+ ["'"],
105
+ ["'a "],
106
+ ['"a '],
107
+
108
+ [ "#a", [[:id, 'a']], "Simple ID" ],
109
+ [ "#'a'" ],
110
+ [ '#"a"' ],
111
+
112
+ [ "#", :throw, "Unfinished '#'." ],
113
+ [ ".", :throw, "Unfinished '.'." ],
114
+ [ "# a", :throw, "No white-space after '#'." ],
115
+ [ ". a", :throw, "No white-space after '.' ." ],
116
+
117
+ [ "a=b c=d", [['a','b'],['c','d']], "Tabbing" ],
118
+ [ " \ta=b \tc='d' "],
119
+ [ "\t a=b\t c='d'\t\t"],
120
+
121
+ [ ".\"a'", :throw, "Mixing quotes is bad." ],
122
+
123
+ ].map { |s, expected, comment|
124
+ @expected = (expected ||= @expected)
125
+ @comment = (comment ||= (last=@comment) )
126
+ (comment == last && (comment += (@count+=1).to_s)) || @count = 1
127
+ expected = [md_ial(expected)] if expected.kind_of? Array
128
+ ["{#{MagicChar}#{s}}", expected, "Attributes: #{comment}"]
129
+ }
130
+ end
131
+
132
+ def md_al(s=[]); AttributeList.new(s) end
133
+
134
+ # returns nil or an AttributeList
135
+ def read_attribute_list(src, con, break_on_chars)
136
+
137
+ separators = break_on_chars + [?=,?\ ,?\t]
138
+ escaped = Maruku::EscapedCharInQuotes
139
+
140
+ al = AttributeList.new
141
+ while true
142
+ src.consume_whitespace
143
+ break if break_on_chars.include? src.cur_char
144
+
145
+ case src.cur_char
146
+ when nil
147
+ maruku_error "Attribute list terminated by EOF:\n "+
148
+ "#{al.inspect}" , src, con
149
+ tell_user "I try to continue and return partial attribute list:\n"+
150
+ al.inspect
151
+ break
152
+ when ?= # error
153
+ maruku_error "In attribute lists, cannot start identifier with `=`."
154
+ tell_user "I try to continue"
155
+ src.ignore_char
156
+ when ?# # id definition
157
+ src.ignore_char
158
+ if id = read_quoted_or_unquoted(src, con, escaped, separators)
159
+ al.push_id id
160
+ else
161
+ maruku_error 'Could not read `id` attribute.', src, con
162
+ tell_user 'Trying to ignore bad `id` attribute.'
163
+ end
164
+ when ?. # class definition
165
+ src.ignore_char
166
+ if klass = read_quoted_or_unquoted(src, con, escaped, separators)
167
+ al.push_class klass
168
+ else
169
+ maruku_error 'Could not read `class` attribute.', src, con
170
+ tell_user 'Trying to ignore bad `class` attribute.'
171
+ end
172
+ else
173
+ if key = read_quoted_or_unquoted(src, con, escaped, separators)
174
+ if src.cur_char == ?=
175
+ src.ignore_char # skip the =
176
+ if val = read_quoted_or_unquoted(src, con, escaped, separators)
177
+ al.push_key_val(key, val)
178
+ else
179
+ maruku_error "Could not read value for key #{key.inspect}.",
180
+ src, con
181
+ tell_user "Ignoring key #{key.inspect}."
182
+ end
183
+ else
184
+ al.push_ref key
185
+ end
186
+ else
187
+ maruku_error 'Could not read key or reference.'
188
+ end
189
+ end # case
190
+ end # while true
191
+ al
192
+ end
193
+
194
+
195
+ # We need a helper
196
+ def is_ial(e); e.kind_of? MDElement and e.node_type == :ial end
197
+
198
+ def merge_ial(elements, src, con)
199
+
200
+ # Apply each IAL to the element before
201
+ elements.each_with_index do |e, i|
202
+ if is_ial(e) && i>= 1 then
203
+ before = elements[i-1]
204
+ after = elements[i+1]
205
+ if before.kind_of? MDElement
206
+ before.al = e.ial
207
+ elsif after.kind_of? MDElement
208
+ after.al = e.ial
209
+ else
210
+ maruku_error "It is not clear to me what element this IAL {:#{e.ial.to_md}} \n"+
211
+ "is referring to. The element before is a #{before.class.to_s}, \n"+
212
+ "the element after is a #{after.class.to_s}.\n"+
213
+ "\n before: #{before.inspect}"+
214
+ "\n after: #{after.inspect}",
215
+ src, con
216
+ # xxx dire se c'è empty vicino
217
+ end
218
+ end
219
+ end
220
+
221
+ if not Globals[:debug_keep_ials]
222
+ elements.delete_if {|x| is_ial(x) unless x == elements.first}
223
+ end
224
+ end
225
+
226
+ end end end end
227
+ #module MaRuKu; module In; module Markdown; module SpanLevelParser