mediacloth 0.0.3 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/README.md +36 -0
  2. data/lib/mediacloth/mediawikiast.rb +58 -1
  3. data/lib/mediacloth/mediawikihtmlgenerator.rb +229 -73
  4. data/lib/mediacloth/mediawikilexer.rb +1030 -656
  5. data/lib/mediacloth/mediawikilinkhandler.rb +89 -0
  6. data/lib/mediacloth/mediawikiparams.rb +1 -10
  7. data/lib/mediacloth/mediawikiparser.rb +939 -409
  8. data/lib/mediacloth/mediawikiparser.tab.rb +1357 -0
  9. data/lib/mediacloth/mediawikiparser.y +256 -52
  10. data/lib/mediacloth/mediawikisignedwikigenerator.rb +42 -0
  11. data/lib/mediacloth/mediawikitemplatehandler.rb +8 -0
  12. data/lib/mediacloth/mediawikiwalker.rb +72 -1
  13. data/lib/mediacloth.rb +33 -10
  14. data/test/data/ast1 +68 -0
  15. data/test/data/ast10 +196 -0
  16. data/test/data/ast11 +34 -0
  17. data/test/data/ast12 +39 -0
  18. data/test/data/ast13 +25 -0
  19. data/test/data/ast14 +13 -0
  20. data/test/data/ast15 +25 -0
  21. data/test/data/ast16 +17 -0
  22. data/test/data/ast17 +9 -0
  23. data/test/data/ast18 +21 -0
  24. data/test/data/ast19 +32 -0
  25. data/test/data/ast2 +4 -0
  26. data/test/data/ast20 +10 -0
  27. data/test/data/ast21 +27 -0
  28. data/test/data/ast22 +22 -0
  29. data/test/data/ast23 +5 -0
  30. data/test/data/ast3 +6 -0
  31. data/test/data/ast4 +122 -0
  32. data/test/data/ast5 +122 -0
  33. data/test/data/ast6 +22 -0
  34. data/test/data/ast7 +143 -0
  35. data/test/data/ast8 +3 -0
  36. data/test/data/ast9 +11 -0
  37. data/test/data/html1 +33 -5
  38. data/test/data/html10 +31 -27
  39. data/test/data/html11 +19 -0
  40. data/test/data/html12 +32 -0
  41. data/test/data/html13 +29 -0
  42. data/test/data/html14 +4 -0
  43. data/test/data/html15 +29 -0
  44. data/test/data/html16 +28 -0
  45. data/test/data/html17 +10 -0
  46. data/test/data/html18 +8 -0
  47. data/test/data/html19 +27 -0
  48. data/test/data/html2 +1 -1
  49. data/test/data/html20 +7 -0
  50. data/test/data/html21 +5 -0
  51. data/test/data/html22 +24 -0
  52. data/test/data/html23 +7 -0
  53. data/test/data/html3 +1 -1
  54. data/test/data/html4 +60 -11
  55. data/test/data/html5 +45 -6
  56. data/test/data/html6 +5 -5
  57. data/test/data/html7 +59 -1
  58. data/test/data/html8 +1 -1
  59. data/test/data/html9 +10 -2
  60. data/test/data/input1 +4 -0
  61. data/test/data/input11 +19 -0
  62. data/test/data/input12 +32 -0
  63. data/test/data/input13 +10 -0
  64. data/test/data/input14 +8 -0
  65. data/test/data/input15 +10 -0
  66. data/test/data/input16 +28 -0
  67. data/test/data/input17 +10 -0
  68. data/test/data/input18 +16 -0
  69. data/test/data/input19 +29 -0
  70. data/test/data/input20 +8 -0
  71. data/test/data/input21 +18 -0
  72. data/test/data/input22 +20 -0
  73. data/test/data/input23 +8 -0
  74. data/test/data/input4 +13 -1
  75. data/test/data/input5 +45 -4
  76. data/test/data/input7 +25 -1
  77. data/test/data/lex1 +17 -18
  78. data/test/data/lex10 +57 -87
  79. data/test/data/lex11 +18 -0
  80. data/test/data/lex12 +32 -0
  81. data/test/data/lex13 +3 -0
  82. data/test/data/lex14 +1 -0
  83. data/test/data/lex15 +3 -0
  84. data/test/data/lex16 +27 -0
  85. data/test/data/lex17 +9 -0
  86. data/test/data/lex18 +4 -0
  87. data/test/data/lex19 +27 -0
  88. data/test/data/lex2 +2 -2
  89. data/test/data/lex20 +7 -0
  90. data/test/data/lex21 +4 -0
  91. data/test/data/lex22 +3 -0
  92. data/test/data/lex23 +7 -0
  93. data/test/data/lex3 +1 -1
  94. data/test/data/lex4 +35 -29
  95. data/test/data/lex5 +57 -18
  96. data/test/data/lex6 +7 -7
  97. data/test/data/lex7 +42 -18
  98. data/test/data/lex8 +1 -1
  99. data/test/data/lex9 +6 -6
  100. data/test/dataproducers/ast.rb +24 -0
  101. data/test/dataproducers/html.rb +11 -12
  102. data/test/dataproducers/lex.rb +9 -4
  103. data/test/debugwalker.rb +25 -11
  104. data/test/htmlgenerator.rb +170 -13
  105. data/test/lexer.rb +626 -83
  106. data/test/linkhandler.rb +39 -0
  107. data/test/parser.rb +176 -9
  108. data/test/signedwikigenerator.rb +113 -0
  109. metadata +158 -79
  110. data/README +0 -37
  111. data/lib/mediacloth/mediawikilexer.rb~ +0 -491
  112. data/lib/mediacloth/mediawikiparser.y~ +0 -210
  113. data/test/data/result1 +0 -48
  114. data/test/dataproducers/html.rb~ +0 -24
  115. data/test/dataproducers/lex.rb~ +0 -15
@@ -0,0 +1,89 @@
1
+ require 'rubygems'
2
+ require 'builder'
3
+
4
+ # A link handler is responsible for resolving the URL and generating the HTML
5
+ # code linking to pages and other resources (images and media, for example)
6
+ # based on a wiki short name.
7
+ #
8
+ # This is the default link handler. A custom link handler will usually extend
9
+ # this class and provide the needed functionality by overriding some of the
10
+ # methods. The custom handler can be injected into an HTML generator via the
11
+ # link_handler= method. See MediaWikiHTMLGenerator for details.
12
+ class MediaWikiLinkHandler
13
+
14
+ #Method invoked to resolve references to wiki pages when they occur in an
15
+ #internal link. In all the following internal links, the page name is
16
+ #<tt>My Page</tt>:
17
+ #* <tt>[[My Page]]</tt>
18
+ #* <tt>[[My Page|Click here to view my page]]</tt>
19
+ #* <tt>[[My Page|Click ''here'' to view my page]]</tt>
20
+ #The return value should be an URL that references the page resource
21
+ def url_for(page)
22
+ "javascript:void(0)"
23
+ end
24
+
25
+ #Provides a hash with the attributes for page links. The options provided
26
+ #here will be added to the 'a' tag attributes and overwrite any options
27
+ #provided by the url_for method. If this method needs to be overriden, an URL
28
+ #reference must be provided here indexed by the <tt>:href</tt> symbol.
29
+ def link_attributes_for(page)
30
+ { :href => url_for(page) }
31
+ end
32
+
33
+ #Renders a link to a wiki page as a string. The default behaviour is to
34
+ #return an 'a' tag, but any string can be used here like span, or bold
35
+ #tags. This method overwrites anything provided by the <tt>url_for</tt>,
36
+ #<tt>options_for</tt> or <tt>link_attributes_for</tt> methods.
37
+ #
38
+ #The <tt>elem</tt> method may be used by subclasses for easier and safer text
39
+ #handling. For example: <tt>elem.a(:href => 'http://www.example.com')
40
+ #{ |x| x << text }</tt> will emit a link for example.com with the given link
41
+ #text
42
+ def link_for(page, text)
43
+ elem.a(link_attributes_for(page)) { |x| x << text }
44
+ end
45
+
46
+ #Method invoked to resolve references to resources of unknown types. The
47
+ #type is indicated by the resource prefix. Examples of inline links to
48
+ #unknown references include:
49
+ #* <tt>[[Media:video.mpg]]</tt> (prefix <tt>Media</tt>, resource <tt>video.mpg</tt>)
50
+ #* <tt>[[Image:pretty.png|100px|A ''pretty'' picture]]</tt> (prefix <tt>Image</tt>,
51
+ # resource <tt>pretty.png</tt>, and options <tt>100px</tt> and <tt>A
52
+ # <i>pretty</i> picture</tt>.
53
+ #The return value should be a well-formed hyperlink, image, object or
54
+ #applet tag.
55
+ def link_for_resource(prefix, resource, options=[])
56
+ "<a href=\"#{prefix}:#{resource}\">#{prefix}:#{resource}</a>"
57
+ end
58
+
59
+ def category_add(name, sort)
60
+ end
61
+
62
+ def link_for_category(category, text)
63
+ "<a href=\"javascript:void(0)\">#{text}</a>"
64
+ end
65
+
66
+ #This is invoked to generate an absolute link to a page
67
+ #when user either puts url onto the page
68
+ #or uses regular [] syntax
69
+ #
70
+ #link_type argument is either empty string or "[". Empty string indicates url written as plain text
71
+ #and "[" indicates that [] syntax for links was used
72
+ def absolute_link_for(page, text, link_type)
73
+ if page =~ /(^|\/)([^\/]*)((\.png)|(\.jpg)|(\.jpeg)|(\.gif))$/ and link_type.blank?
74
+ "<img src=\"#{page}\" alt=\"#{$2}#{$3}\" />"
75
+ else
76
+ "<a href=\"#{page}\">#{text}</a>"
77
+ end
78
+ end
79
+
80
+ protected
81
+
82
+ #A Builder object for rendering XHTML code without having to deal directly
83
+ #with text. See http://builder.rubyforge.org for usage details.
84
+ def elem
85
+ Builder::XmlMarkup.new
86
+ end
87
+
88
+ end
89
+
@@ -6,9 +6,6 @@ require 'singleton'
6
6
  #parser environment variables.
7
7
  class MediaWikiParams
8
8
 
9
- #MediaWikiParams is a signleton class
10
- include Singleton
11
-
12
9
  #The name of the wiki page author
13
10
  attr_accessor :author
14
11
 
@@ -16,14 +13,8 @@ class MediaWikiParams
16
13
  @author = "Creator"
17
14
  end
18
15
 
19
- #Creation time of the page. Use overrideTime method to override
20
- #the value (useful for testing purposes).
21
16
  def time
22
- if @time
23
- return @time
24
- else
25
- return Time.now
26
- end
17
+ (@time || Time.now.utc).strftime("%a %b %d, %Y %H:%M")
27
18
  end
28
19
 
29
20
  def time=(t)