hoe-manualgen 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.autotest +23 -0
  2. data/History.md +4 -0
  3. data/README.md +72 -0
  4. data/Rakefile +85 -0
  5. data/data/hoe-manualgen/layouts/default.erb.erb +87 -0
  6. data/data/hoe-manualgen/lib/api-filter.rb +76 -0
  7. data/data/hoe-manualgen/lib/editorial-filter.rb +59 -0
  8. data/data/hoe-manualgen/lib/examples-filter.rb +238 -0
  9. data/data/hoe-manualgen/lib/links-filter.rb +111 -0
  10. data/data/hoe-manualgen/resources/css/manual.css.erb +755 -0
  11. data/data/hoe-manualgen/resources/fonts/GraublauWeb.otf +0 -0
  12. data/data/hoe-manualgen/resources/fonts/GraublauWebBold.otf +0 -0
  13. data/data/hoe-manualgen/resources/fonts/Inconsolata.otf +0 -0
  14. data/data/hoe-manualgen/resources/images/arrow_225_small.png +0 -0
  15. data/data/hoe-manualgen/resources/images/arrow_315_small.png +0 -0
  16. data/data/hoe-manualgen/resources/images/arrow_skip.png +0 -0
  17. data/data/hoe-manualgen/resources/images/cc-by.png +0 -0
  18. data/data/hoe-manualgen/resources/images/dialog-error.png +0 -0
  19. data/data/hoe-manualgen/resources/images/dialog-information.png +0 -0
  20. data/data/hoe-manualgen/resources/images/dialog-warning.png +0 -0
  21. data/data/hoe-manualgen/resources/images/emblem-important.png +0 -0
  22. data/data/hoe-manualgen/resources/images/help.png +0 -0
  23. data/data/hoe-manualgen/resources/images/information.png +0 -0
  24. data/data/hoe-manualgen/resources/images/magnifier.png +0 -0
  25. data/data/hoe-manualgen/resources/images/magnifier_left.png +0 -0
  26. data/data/hoe-manualgen/resources/images/page_white_code.png +0 -0
  27. data/data/hoe-manualgen/resources/images/page_white_copy.png +0 -0
  28. data/data/hoe-manualgen/resources/images/printer.png +0 -0
  29. data/data/hoe-manualgen/resources/images/question.png +0 -0
  30. data/data/hoe-manualgen/resources/images/scripts_code.png +0 -0
  31. data/data/hoe-manualgen/resources/images/wrap.png +0 -0
  32. data/data/hoe-manualgen/resources/images/wrapping.png +0 -0
  33. data/data/hoe-manualgen/resources/js/jquery-1.4.4.min.js +167 -0
  34. data/data/hoe-manualgen/resources/js/manual.js +30 -0
  35. data/data/hoe-manualgen/resources/js/sh.js +580 -0
  36. data/data/hoe-manualgen/resources/swf/clipboard.swf +0 -0
  37. data/data/hoe-manualgen/src/index.page.erb +59 -0
  38. data/lib/hoe/manualgen.rb +804 -0
  39. data.tar.gz.sig +0 -0
  40. metadata +230 -0
  41. metadata.gz.sig +4 -0
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # A manual filter to generate links from the page catalog.
4
+ #
5
+ # Authors:
6
+ # * Michael Granger <ged@FaerieMUD.org>
7
+ # * Mahlon E. Smith <mahlon@martini.nu>
8
+ #
9
+ #
10
+
11
+
12
+ ### A filter for generating links from the page catalog. This allows you to refer to other pages
13
+ ### in the source and have them automatically updated as the structure of the manual changes.
14
+ ###
15
+ ### Links are XML processing instructions. Pages can be referenced in one of several ways:
16
+ ###
17
+ ### <?link Page Title ?>
18
+ ### <?link "click here":Page Title ?>
19
+ ### <?link Page Title #section_id ?>
20
+ ### <?link "click here":Page Title#section_id ?>
21
+ ###
22
+ ### This first form links to a page by title. Link text defaults to the page title unless an
23
+ ### optional quoted string is prepended. If you want to link to an anchor inside the page, include
24
+ ### its ID with a hash mark after the title.
25
+ ###
26
+ ### <?link path/to/Catalog.page ?>
27
+ ### <?link "click here":path/to/Catalog.page ?>
28
+ ### <?link path/to/Catalog.page#section_id ?>
29
+ ### <?link "click here":path/to/Catalog.page#section_id ?>
30
+ ###
31
+ ### The second form links to a page by its path relative to the base manual source directory.
32
+ ### Again, the link text defaults to the page title, or can be overriden via a prepended string,
33
+ ### and you can link into a page with an appended ID.
34
+ class Hoe::ManualGen::LinksFilter < Hoe::ManualGen::Page::Filter
35
+
36
+ # PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
37
+ LinkPI = %r{
38
+ <\?
39
+ link # Instruction Target
40
+ \s+
41
+ (?:"
42
+ (.*?) # Optional link text [$1]
43
+ ":)?
44
+ (.*?) # Title or path [$2]
45
+ \s*
46
+ (\#\w+)? # Fragment [$3]
47
+ \s+
48
+ \?>
49
+ }x
50
+
51
+
52
+ ######
53
+ public
54
+ ######
55
+
56
+ ### Process the given +source+ for <?link ... ?> processing-instructions, calling out
57
+ def process( source, page, metadata )
58
+ return source.gsub( LinkPI ) do |match|
59
+ # Grab the tag values
60
+ link_text = $1
61
+ reference = $2
62
+ fragment = $3
63
+
64
+ self.generate_link( page, reference, link_text, fragment )
65
+ end
66
+ end
67
+
68
+
69
+ ### Create an HTML link fragment from the parsed LinkPI.
70
+ def generate_link( current_page, reference, link_text=nil, fragment=nil )
71
+
72
+ if other_page = self.find_linked_page( current_page, reference )
73
+ href_path = other_page.sourcefile.relative_path_from( current_page.sourcefile.dirname )
74
+ href = href_path.to_s.gsub( '.page', '.html' )
75
+
76
+ if link_text
77
+ return %{<a href="#{href}#{fragment}">#{link_text}</a>}
78
+ else
79
+ return %{<a href="#{href}#{fragment}">#{other_page.title}</a>}
80
+ end
81
+ else
82
+ link_text ||= reference
83
+ error_message = "Could not find a link for reference '%s'" % [ reference ]
84
+ $stderr.puts( error_message )
85
+ return %{<a href="#" title="#{error_message}" class="broken-link">#{link_text}</a>}
86
+ end
87
+ end
88
+
89
+
90
+ ### Lookup a page +reference+ in the catalog. +reference+ can be either a
91
+ ### path to the .page file, relative to the manual root path, or a page title.
92
+ ### Returns a matching Page object, or nil if no match is found.
93
+ def find_linked_page( current_page, reference )
94
+
95
+ catalog = current_page.catalog
96
+
97
+ # Lookup by page path
98
+ if reference =~ /\.page$/
99
+ return catalog.uri_index[ reference ]
100
+
101
+ # Lookup by page title
102
+ else
103
+ return catalog.title_index[ reference ]
104
+ end
105
+ end
106
+ end
107
+
108
+
109
+
110
+
111
+