rote 0.3.0 → 0.3.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/TODO CHANGED
@@ -16,3 +16,6 @@ Send any suggestions or patches (preferably as/with tests) to:
16
16
  pages) and user guide (one page) generated from same source.
17
17
  ** Maybe in concert with plugins?
18
18
  * (maybe?) Rant integration
19
+ * Macro that evaluates it's body
20
+ * Macro/method to run external commands and capture the output.
21
+ * Deprecate 'rote' command supporting Rake tasks.
@@ -1,6 +1,6 @@
1
1
  # rote.rb - main Rote module
2
2
  # Copyright (c) 2005 Ross Bamford (and contributors)
3
- # $Id: rote.rb,v 1.21 2005/12/12 02:47:47 roscopeco Exp $
3
+ # $Id: rote.rb,v 1.22 2005/12/14 19:19:58 roscopeco Exp $
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  # this software and associated documentation files (the "Software"), to deal in
@@ -41,7 +41,7 @@ end
41
41
  require 'rake'
42
42
 
43
43
  # Master Rote version. Manage this from the Rake release support.
44
- ROTEVERSION = '0.3.0'
44
+ ROTEVERSION = '0.3.0.2'
45
45
 
46
46
  #####
47
47
  ## *Rote* is a Rake (http://rake.rubyforge.org) based build tool for static
@@ -3,7 +3,7 @@
3
3
  # (c)2005 Ross Bamford (and contributors)
4
4
  #
5
5
  # See 'rote.rb' or LICENSE for licence information.
6
- # $Id: base.rb,v 1.2 2005/12/12 02:45:24 roscopeco Exp $
6
+ # $Id: base.rb,v 1.3 2005/12/14 19:17:21 roscopeco Exp $
7
7
  #++
8
8
  module Rote
9
9
  module Filters
@@ -15,7 +15,8 @@ module Rote
15
15
  # #code#
16
16
  #
17
17
  # to :code, args, body
18
- MACRO_RE = /^\s*\#\:([a-z]+)(?:\#([a-z]*))?\#\s*^(.*?)$\s*\#\:\1\#(?:\2\#)?\s*$/m
18
+ MACRO_RE = /^\s*\#\:([a-z]+)(?:\#([a-z]*))?\#\s*?\n?(.*?)\s*\#\:\1\#(?:\2\#)?\s*$/m
19
+ PLACEHOLDER_RE = /(?:<[^>]*>)?xmxmxmacro(\d+)orcamxmxmx(?:<[^>]*>)?/
19
20
 
20
21
  #####
21
22
  ## Baseclass from which Rote filters can be derived if
@@ -26,7 +27,7 @@ module Rote
26
27
  ## are replaced with the corresponding (numbered) original
27
28
  ## macro body.
28
29
  class TextFilter
29
- attr_accessor :handler_blk, :macro_data
30
+ attr_accessor :handler_blk, :macros
30
31
 
31
32
  # Create a new TextFilter. The supplied block will be called
32
33
  # with the text to be rendered, with all macros replaced
@@ -35,14 +36,14 @@ module Rote
35
36
  # { |text, page| "replacement" }
36
37
  def initialize(&handler)
37
38
  @handler_blk = handler
38
- @macro_data = []
39
+ @macros = []
39
40
  end
40
41
 
41
42
  def filter(text, page)
42
43
  # we need to remove any macros to stop them being touched
43
44
  n = -1
44
45
  tmp = text.gsub(MACRO_RE) do
45
- macro_data << $&
46
+ macros << $&
46
47
  # we need make the marker a 'paragraph'
47
48
  "\nxmxmxmacro#{n += 1}orcamxmxmx\n"
48
49
  end
@@ -51,7 +52,7 @@ module Rote
51
52
 
52
53
  # Match the placeholder, including any (and greedily all) markup that's
53
54
  # been placed before or after it, and put the macro text back.
54
- tmp.gsub(/(?:<.*>)?xmxmxmacro(\d+)orcamxmxmx(?:<.*>)?/) { @macro_data[$1.to_i] }
55
+ tmp.gsub(PLACEHOLDER_RE) { macros[$1.to_i] }
55
56
  end
56
57
 
57
58
  protected
@@ -66,17 +67,31 @@ module Rote
66
67
  #####
67
68
  ## Baseclass from which Rote filters can be derived if
68
69
  ## you want some help with macro replacement.
70
+ ##
71
+ ## There are three ways to make a macro filter:
72
+ ##
73
+ ## * Subclass this class, and provide +macro_name+
74
+ ## methods where +name+ is the macro name. These
75
+ ## methods receive args (args, body, raw_macro)
76
+ ##
77
+ ## * Create an instance of this class with a block
78
+ ## taking up to four arguments
79
+ ## (name,args,body,raw_macro)
80
+ ##
81
+ ## * Subclass this class and override the +handler+
82
+ ## method to process all macros.
83
+ ##
69
84
  class MacroFilter
70
85
 
71
86
  # An array of macro names supported by this filter.
72
87
  # This can be used to selectively disable individual
73
88
  # macro support.
74
- attr_accessor :macros
89
+ attr_accessor :names
75
90
 
76
91
  # Block that will be called for each supported macro
77
92
  # in the filtered text. Like:
78
93
  #
79
- # { |macro, args, body| "replacement" }
94
+ # { |macro, args, body, raw_macro| "replacement" }
80
95
  #
81
96
  # The presence of a block precludes the use of any
82
97
  # +macro_xxxx+ methods on the subclass.
@@ -88,45 +103,25 @@ module Rote
88
103
  # as methods (e.g. +macro_code+). If an array of names isn't
89
104
  # passed, a search such methods will be used to populate
90
105
  # the names array.
91
- def initialize(macros = nil, code_re = MACRO_RE, &handler_blk)
92
- @handler_blk = handler_blk
93
- @macros = macros || reflect_macro_names
106
+ def initialize(names = [], code_re = MACRO_RE, &block)
107
+ @names = (names || []).map { |n| n.to_s }
108
+ @block = block
94
109
  @code_re = code_re
95
- end
96
-
97
- def filter(text,page)
98
- # Just go through, subbing with block if this is
99
- # our macro, or with the original match if not.
100
- text.gsub(@code_re) do
101
- if macros.detect { |it| it.to_s == $1 }
102
- # Handler might refuse the macro (bad args, etc)
103
- handler($1,$2,$3) || $&
104
- else
105
- $&
106
- end
107
- end
108
110
  end
109
-
110
- protected
111
-
112
- # Calls the handler block, or attempts to call a method named
113
- # 'macro_XXXX' where 'XXXX' is the name of the macro.
114
- # Macro methods take two arguments -args and body.
115
- # Name is implied by method that is invoked.
116
- def handler(macro,args,body)
117
- if handler_blk
118
- handler_blk[macro,args,body]
119
- elsif respond_to?(meth = "macro_#{macro}")
120
- send(meth, args, body) # name implied by method
121
- end
111
+
112
+ def filter(text,page)
113
+ text.gsub(@code_re) { handler($1,$2,$3,$&) || $& }
122
114
  end
123
115
 
124
- private
125
-
126
- # inits the macro array from defined 'macro_' methods if no array is passed.
127
- def reflect_macro_names
128
- [methods, private_methods, singleton_methods, protected_methods].inject([]) do |arr,m|
129
- arr += m.grep(/macro_([a-z0-9]+)/) { $1 }
116
+ # You may override this method if you want to completely
117
+ # override the standard macro dispatch.
118
+ def handler(macro,args,body,all)
119
+ if @names.include?(macro) then
120
+ @block[macro,args,body,all]
121
+ elsif respond_to?(meth = "macro_#{macro}") then
122
+ self.send(meth,args,body,all)
123
+ else
124
+ nil
130
125
  end
131
126
  end
132
127
  end
@@ -3,7 +3,7 @@
3
3
  # (c)2005 Ross Bamford (and contributors)
4
4
  #
5
5
  # See 'rote.rb' or LICENSE for licence information.
6
- # $Id: syntax.rb,v 1.2 2005/12/12 02:45:24 roscopeco Exp $
6
+ # $Id: syntax.rb,v 1.3 2005/12/14 19:17:21 roscopeco Exp $
7
7
  #++
8
8
 
9
9
  require 'syntax'
@@ -26,10 +26,10 @@ module Rote
26
26
  ##
27
27
  class Syntax < MacroFilter
28
28
  def initialize(macro_re = MACRO_RE)
29
- super([:code],macro_re)
29
+ super([],macro_re)
30
30
  end
31
31
 
32
- def macro_code(lang,body)
32
+ def macro_code(lang,body,raw)
33
33
  converter = ::Syntax::Convertors::HTML.for_syntax(lang)
34
34
  "<pre class='#{lang}'><code>#{converter.convert(body,false)}</code></pre>"
35
35
  end
@@ -3,7 +3,7 @@
3
3
  # (c)2005 Ross Bamford (and contributors)
4
4
  #
5
5
  # See 'rote.rb' or LICENSE for licence information.
6
- # $Id: page.rb,v 1.10 2005/12/12 02:45:24 roscopeco Exp $
6
+ # $Id: page.rb,v 1.11 2005/12/14 19:01:05 roscopeco Exp $
7
7
  #++
8
8
 
9
9
  require 'erb'
@@ -60,6 +60,7 @@ module Rote
60
60
  resolve_common_rubys(parent,arr) unless parent == dir # at root
61
61
  fn = File.join(dir,'COMMON.rb')
62
62
  arr << fn if (File.exists?(fn) && File.readable?(fn))
63
+ arr
63
64
  end
64
65
  end
65
66
 
@@ -1,16 +1,21 @@
1
1
  # Standard Rakefile for custom Rote build
2
2
  #
3
3
  # Generated from:
4
- # $Id: Rakefile,v 1.2 2005/12/12 02:45:24 roscopeco Exp $
4
+ # $Id: Rakefile,v 1.3 2005/12/14 19:01:05 roscopeco Exp $
5
5
  #
6
6
  begin
7
7
  require 'rubygems'
8
8
  rescue LoadError
9
9
  nil # optional
10
10
  end
11
+
11
12
  require 'rake'
12
13
  require 'rake/clean'
13
14
  require 'rote'
15
+ require 'rote/filters/redcloth'
16
+ require 'rote/filters/rdoc'
17
+ require 'rote/format/html'
18
+
14
19
  include Rote
15
20
 
16
21
  # Create a set of tasks with the prefix 'doc' to build the
@@ -40,18 +45,17 @@ ws = Rote::DocTask.new(:doc) do |site|
40
45
  site.res.dir = 'doc/res'
41
46
  site.res.include('**/*')
42
47
 
43
- # TODO need to figure out what default mappings should be
44
- site.ext_mapping(/(thtml)/, 'html') do |page|
48
+ site.ext_mapping(/thtml|textile/, 'html') do |page|
45
49
  page.extend Format::HTML
46
50
  page.page_filter Filters::RedCloth.new(:textile)
47
51
  end
48
52
 
49
- site.ext_mapping(/mhtml/, 'html') do |page|
53
+ site.ext_mapping(/mhtml|markdown/, 'html') do |page|
50
54
  page.extend Format::HTML
51
55
  page.page_filter Filters::RedCloth.new(:markdown)
52
56
  end
53
57
 
54
- site.ext_mapping(/rdoc/, 'html') do |page|
58
+ site.ext_mapping(/rdhtml|rdoc/, 'html') do |page|
55
59
  page.extend Format::HTML
56
60
  page.page_filter Filters::RDoc.new
57
61
  end
@@ -1,7 +1,9 @@
1
- # Shared code for all pages in this directory.
2
-
1
+ # Shared code for all pages below this directory.
2
+ #
3
3
  # This is executed for every file transformed, in the binding of
4
4
  # the appropriate Rote::Page instance. Individual page sources
5
5
  # ([pagename].rb) override anything defined here.
6
-
6
+ #
7
+ # Any COMMON.rb files found in directories above this will also
8
+ # be loaded.
7
9
  @site_title = "My site"
@@ -2,9 +2,6 @@
2
2
  # set layout and formatting, and then create a custom variable
3
3
  # for use in the layout.
4
4
 
5
- # This page uses Textile
6
- format_opts << :textile
7
-
8
5
  # Apply the 'normal' layout
9
6
  layout 'normal'
10
7
 
@@ -8,7 +8,6 @@ require 'test/unit'
8
8
  require 'rote/page'
9
9
  require 'rote/filters/redcloth'
10
10
  require 'rote/filters/rdoc'
11
- require 'rote/filters/proc'
12
11
  require 'rote/filters/toc'
13
12
  require 'rote/filters/syntax'
14
13
 
@@ -87,30 +86,8 @@ module Rote
87
86
  end
88
87
  end
89
88
 
90
- ############## filters/proc #################
91
- # FIXME Fails under Gem install, but passes when run normally (???)
92
- def test_proc_no_block
93
- begin
94
- Filters::Proc.new
95
- rescue ArgumentError => ex
96
- assert_equal 'No block given', ex.message
97
- end
98
- end
89
+ ############## filters #################
99
90
 
100
- def test_render_with_proc
101
- f = Filters::Proc.new { |text, page| text + page }
102
- assert_equal f.filter('some text ', 'fake page'), 'some text fake page'
103
-
104
- # equivalent
105
- f = Filters::Proc.with do |text, page|
106
- text + page
107
- end
108
- assert_equal f.filter('some text ', 'fake page'), 'some text fake page'
109
- end
110
-
111
- # Toc filter is a non-output filter - it's used to get a list of links in
112
- # the page, from layout code. It should output it's input directly, so
113
- # that it doesn't matter where in the chain it is.
114
91
  def test_toc_filter
115
92
  # default RE
116
93
  toc = Filters::TOC::new
@@ -128,13 +105,16 @@ module Rote
128
105
 
129
106
  def test_syntax_filter
130
107
  # bad
131
- assert_equal '', Filters::Syntax.new.filter('', nil)
132
- assert_equal 'Has no source', Filters::Syntax.new.filter('Has no source', nil)
108
+ assert_equal '', Filters::Syntax.new.filter('',nil)
109
+ assert_equal 'Has no source', Filters::Syntax.new.filter('Has no source',nil)
133
110
 
134
111
  # good
135
- assert_equal SYNEXPECT.chomp, Filters::Syntax.new.filter(SYNTEST, nil)
112
+ assert_equal SYNEXPECT.chomp, Filters::Syntax.new.filter(SYNTEST,nil)
136
113
  end
114
+ # TODO test macro stuff etc.
115
+
137
116
  end
138
117
 
118
+
139
119
  end
140
120
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: rote
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.0
7
- date: 2005-12-12 00:00:00 +00:00
6
+ version: 0.3.0.2
7
+ date: 2005-12-14 00:00:00 +00:00
8
8
  summary: Adds template-based doc support to Rake.
9
9
  require_paths:
10
10
  - lib
@@ -60,8 +60,8 @@ files:
60
60
  - lib/rote/project/doc/layouts
61
61
  - lib/rote/project/doc/res/images
62
62
  - lib/rote/project/doc/res/images/rote-tiny.png
63
- - lib/rote/project/doc/pages/index.html
64
- - lib/rote/project/doc/layouts/normal.html
63
+ - lib/rote/project/doc/pages/index.thtml
64
+ - lib/rote/project/doc/layouts/normal.thtml
65
65
  - test/test_formatting.rb
66
66
  - test/test_page.rb
67
67
  - test/pages