rote 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,122 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+
4
+ require 'rote/page'
5
+ require 'rote/dirfilelist'
6
+
7
+ module Rote
8
+
9
+ #####
10
+ ## Rake task library that provides a set of tasks to transform documentation
11
+ ## using Rote. To use, create a new instance of this class in your Rakefile,
12
+ ## performing appropriate configuration in a block supplied to +new+.
13
+ ## This will automatically register a set of tasks with names based on the
14
+ ## name you supply. The tasks defined are:
15
+ ##
16
+ ## #{name} - Transform all documentation, copy resources.
17
+ ## #{name}-pages - Transform all pages
18
+ ## #{name}-res - Copy resources
19
+ ##
20
+ class DocTask < Rake::TaskLib
21
+ # Default exclusion patterns for the page sources. These are
22
+ # applied along with the defaults from +FileList+.
23
+ DEFAULT_SRC_EXCLUDES = [ /\.rb$/ ]
24
+
25
+ # The base-name for tasks created by this instance, supplied at
26
+ # instantiation.
27
+ attr_reader :name
28
+
29
+ # The directory in which output will be placed.
30
+ attr_accessor :output_dir
31
+
32
+ # The base directory within which layouts requested by pages will be
33
+ # resolved.
34
+ attr_accessor :layout_dir
35
+
36
+ # A DirectoryFileList that supplies the pages to transform. You should
37
+ # configure the +dir+ and at least one +include+ entry in the
38
+ # configuration block.
39
+ attr_reader :pages
40
+
41
+ # A DirectoryFileList that supplies the resources to copy to the
42
+ # output directory.
43
+ attr_reader :res
44
+
45
+ # If +show_page_tasks+ is +true+, then the file tasks created for each
46
+ # source page will be shown in the Rake task listing from the command line.
47
+ attr_accessor :show_page_tasks
48
+ alias :show_page_tasks? :show_page_tasks
49
+
50
+ # Create a new DocTask, using the supplied block for configuration,
51
+ # and define tasks with the specified base-name within Rake.
52
+ def initialize(name = :site) # :yield: self if block_given?
53
+ @name = name
54
+ @output_dir = '.'
55
+ @layout_dir = '.' # layouts are looked up as needed
56
+
57
+ @pages = DirectoryFileList.new
58
+ @res = DirectoryFileList.new
59
+ DEFAULT_SRC_EXCLUDES.each { |excl| @pages.exclude(excl) }
60
+
61
+ @show_page_tasks = false
62
+
63
+ yield self if block_given?
64
+
65
+ define
66
+ end
67
+
68
+ private
69
+
70
+ def define
71
+ define_res_tasks
72
+ define_page_tasks
73
+ define_main_tasks
74
+ nil
75
+ end
76
+
77
+ def define_res_tasks
78
+ desc "Copy documentation resources"
79
+ task "#{name}-res" do
80
+ res.each { |fn|
81
+ unless File.directory?(fn) # make dirs only as needed
82
+ tfn = fn.sub(/#{res.dir}/, output_dir)
83
+ dn = File.dirname(tfn)
84
+ mkdir_p dn unless File.exists?(dn)
85
+ cp fn, tfn
86
+ end
87
+ }
88
+ end #task
89
+ end
90
+
91
+ def define_page_tasks
92
+
93
+ # define a task for each page
94
+ pages.each { |fn|
95
+ unless File.directory?(fn) # make dirs only as needed
96
+ tfn = fn.sub(/#{pages.dir}/, output_dir)
97
+
98
+ desc "#{fn} => #{tfn}" if show_page_tasks?
99
+ file tfn => [fn] do
100
+ dn = File.dirname(tfn)
101
+ mkdir_p dn unless File.exists?(dn)
102
+ File.open(tfn, 'w+') { |f|
103
+ puts "tr #{fn} => #{tfn}"
104
+ f << Page.new(fn,layout_dir).render
105
+ }
106
+ end
107
+ end
108
+ }
109
+
110
+ # this is pretty convenient ;]
111
+ desc "Render all documentation pages"
112
+ task "#{name}-pages" => pages.sub(/#{pages.dir}/, output_dir)
113
+ end
114
+
115
+ def define_main_tasks
116
+ desc "Build the documentation"
117
+ task name => ["#{name}-pages", "#{name}-res"]
118
+ end
119
+
120
+ end #class
121
+
122
+ end #module
data/lib/rote.rb ADDED
@@ -0,0 +1,86 @@
1
+ # rote.rb - main Rote module
2
+ # Copyright (c) 2005 Ross Bamford (and contributors)
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
+ # of the Software, and to permit persons to whom the Software is furnished to do
9
+ # so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ # SOFTWARE.
21
+ #
22
+ # See Rote for full documentation
23
+
24
+ require 'net/ftp'
25
+ require 'rubygems'
26
+ require_gem 'rake'
27
+
28
+ require 'rote/rotetasks'
29
+
30
+ # Master Rote version. Manage this from the Rake release support.
31
+ ROTEVERSION = '0.1.0'
32
+
33
+ #####
34
+ ## *Rote* is a Rake (http://rake.rubyforge.org) based build tool for page-based
35
+ ## static websites that enables layout, textile formatting, and ERB to be used
36
+ ## to automatically generate your site, and can handle uploading the site
37
+ ## to your (host's) server.
38
+ ##
39
+ ## Rote was created for my personal site, but is general enough to be applied
40
+ ## to many different types of website, including basic blog-plus sites,
41
+ ## slower-moving news and information sites, and software documentation.
42
+ ##
43
+ ## See +README+ for general usage information. +Rote::DocTask+ documents the
44
+ ## Rake task integration, while +Rote::Page+ has information useful to template
45
+ ## writers.
46
+ ##
47
+ ## Rote is (c)2005 Ross Bamford, and is licensed under an MIT license.
48
+ ## See +LICENSE+ for details.
49
+ module Rote
50
+
51
+ private
52
+
53
+ ####################################################
54
+ ## WILL BE REMOVED... ##
55
+ ## ...I SAID, "WILL BE REMOVED" ##
56
+ ####################################################
57
+
58
+ def ftp_putdir(dir, ftp_host, ftp_user, ftp_pass = nil, ftp_root = '/')
59
+ f = Net::FTP.new(ftp_host, ftp_user, ftp_pass)
60
+ f.passive = true
61
+
62
+ Dir[dir + '/**/*'].sort.each { |fn|
63
+ # pretty f*cking trick - it's replacing the local 'target' or whatever prefix
64
+ # with remote root ;)
65
+ rfn = fn.dup
66
+ rfn[dir] = ftp_root
67
+
68
+ if File.directory?(fn)
69
+ puts "Creating remote directory #{rfn}"
70
+ begin
71
+ f.mkdir(rfn)
72
+ rescue
73
+ # forget it then, already exists prob'ly
74
+ # TODO maybe should raise if $! != FTP 550?
75
+ end
76
+ else
77
+
78
+ # TODO continue on error perhaps
79
+ puts "Uploading #{fn} => #{rfn}"
80
+ f.put(fn,rfn)
81
+ end
82
+ }
83
+
84
+ f.close
85
+ end
86
+ end
@@ -0,0 +1 @@
1
+ @global = 'some other text'
@@ -0,0 +1 @@
1
+ layout 'nonexistent'
@@ -0,0 +1 @@
1
+ layout 'baselayout'
@@ -0,0 +1 @@
1
+ format_opts << :textile
@@ -0,0 +1,5 @@
1
+ # config
2
+ layout 'simple'
3
+
4
+ # custom stuff
5
+ @myvar = 'some text'
data/test/test_page.rb ADDED
@@ -0,0 +1,137 @@
1
+ require 'test/unit'
2
+ require 'rote/page'
3
+
4
+ module Rote
5
+ class TestPage < Test::Unit::TestCase
6
+ ############## helpers #################
7
+ def new_test_page(basename)
8
+ Page.new('test/pages/' + basename + '.txt', 'test/layouts')
9
+ end
10
+
11
+ ############## initialize #################
12
+ def test_initialize_with_bad_file
13
+ begin
14
+ new_test_page('NONEXISTENT')
15
+ rescue
16
+ assert true
17
+ end
18
+ end
19
+
20
+ def test_initialize_with_bad_layout
21
+ begin
22
+ p = new_test_page('badlayout')
23
+ rescue
24
+ assert true
25
+ end
26
+ end
27
+
28
+ def test_initialize_ok
29
+ new_test_page('justtext')
30
+ end
31
+
32
+ ############## accessors #################
33
+ def test_template_accessors
34
+ p = new_test_page('justtext')
35
+ assert_equal 'Just some text', p.template_text.chomp
36
+ end
37
+
38
+ def test_layout_accessors
39
+ p = new_test_page('justtext')
40
+ assert_nil p.layout_text
41
+
42
+ p = new_test_page('withcode')
43
+ assert_equal 'layout <%= @content_for_layout %> for a change.', p.layout_text.chomp
44
+ end
45
+
46
+ def test_default_layout_params
47
+ p = Page.new('test/pages/samedir.txt')
48
+ assert_equal '<%= @global %>', p.template_text.chomp
49
+ assert_equal 'Lay <%= @content_for_layout %> out.', p.layout_text.chomp
50
+ end
51
+
52
+ # this is testing also that layouts can be specified in the template itself
53
+ def test_custom_layout_ext
54
+ p = new_test_page('custext')
55
+
56
+ # Should have no layout yet (until render)
57
+ assert_nil p.layout_text
58
+
59
+ # Render will load layout, it'll be available after
60
+ assert_equal "layout \nsome other text for a change.", p.render.chomp
61
+
62
+ assert_equal 'layout <%= @content_for_layout %> for a change.', p.layout_text.chomp
63
+ end
64
+
65
+ def test_format_opts
66
+ p = new_test_page('justtext')
67
+ assert p.format_opts.empty?
68
+
69
+ # alter array
70
+ p = new_test_page('textile')
71
+ assert_equal [:textile], p.format_opts
72
+ p.format_opts -= [:textile]
73
+ assert p.format_opts.empty?
74
+
75
+ # replace array with single sym
76
+ p = new_test_page('textile')
77
+ assert_equal [:textile], p.format_opts
78
+ p.format_opts = [:markdown]
79
+ assert_equal [:markdown], p.format_opts
80
+ p.format_opts = :textile
81
+ # should create array for one sim
82
+ assert_equal [:textile], p.format_opts
83
+
84
+ end
85
+
86
+ ############## render #################
87
+ def test_render_text
88
+ t = new_test_page('justtext').render.chomp
89
+ assert_equal 'Just some text', t
90
+ end
91
+
92
+ def test_render_textile
93
+ t = new_test_page('textile').render.chomp
94
+ assert_equal '<p><strong>This</strong> is a <em>simple</em> test of <a href="http://www.textism.org/tools/textile">Textile</a> formatting.</p>', t
95
+ end
96
+
97
+ def test_render_markdown
98
+ t = new_test_page('markdown').render.chomp
99
+ assert_equal '<h1>*this* is a _test_</h1>', t
100
+ end
101
+
102
+ def test_render_layout_code
103
+ t = new_test_page('withcode').render.chomp
104
+ assert_equal 'layout some text and some other text for a change.', t
105
+ end
106
+
107
+ ############## broken render #################
108
+ def test_render_switch_layout_freeze
109
+ p = new_test_page('withcode')
110
+ assert_equal 'layout <%= @content_for_layout %> for a change.', p.layout_text.chomp
111
+
112
+ p.layout(nil)
113
+ assert_nil p.layout_text
114
+
115
+ assert_equal 'some text and some other text', p.render.chomp
116
+
117
+ begin
118
+ p.layout('simple')
119
+ rescue TypeError # frozen
120
+ assert true
121
+ end
122
+ end
123
+
124
+ def test_render_switch_to_bad_layout
125
+ p = new_test_page('withcode')
126
+ assert_equal 'layout <%= @content_for_layout %> for a change.', p.layout_text.chomp
127
+
128
+ begin
129
+ p.layout('nonexistent')
130
+ rescue
131
+ assert true
132
+ end
133
+ end
134
+
135
+ end
136
+ end
137
+
metadata ADDED
@@ -0,0 +1,94 @@
1
+ !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: rote
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2005-11-25 00:00:00 +00:00
8
+ summary: Adds template-based doc support to Rake.
9
+ require_paths:
10
+ - lib
11
+ email: ross@roscopeco.co.uk
12
+ homepage: http://rote.rubyforge.org
13
+ rubyforge_project: rote
14
+ description: Rote is a set of Rake task libraries and utilities that enable easy rendering of textual documentation formats (like HTML) for websites and offline documentation.
15
+ autorequire:
16
+ default_executable: rote
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ authors:
29
+ - Ross Bamford
30
+ files:
31
+ - install.rb
32
+ - Rakefile
33
+ - README
34
+ - TODO
35
+ - LICENSE
36
+ - bin/rote
37
+ - lib/rote.rb
38
+ - lib/rote/rotetasks.rb
39
+ - lib/rote/page.rb
40
+ - lib/rote/app.rb
41
+ - lib/rote/dirfilelist.rb
42
+ - test/test_page.rb
43
+ - test/pages/badlayout.rb
44
+ - test/pages/samedir.rb
45
+ - test/pages/COMMON.rb
46
+ - test/pages/textile.rb
47
+ - test/pages/withcode.rb
48
+ - doc/res
49
+ - doc/jamis.rb
50
+ - doc/pages
51
+ - doc/layouts
52
+ - doc/res/images
53
+ - doc/res/stylesheets
54
+ - doc/res/images/rote-big.png
55
+ - doc/res/images/rote-small.png
56
+ - doc/res/images/rpot-tiny.png
57
+ - doc/res/images/user-id-med.png
58
+ - doc/res/images/document-new-med.png
59
+ - doc/res/images/computer-med.png
60
+ - doc/res/images/go-home-med.png
61
+ - doc/res/images/rpot-sml.png
62
+ - doc/res/images/rote-med.png
63
+ - doc/res/images/rpot-large-x.xcf
64
+ - doc/res/images/rote-logo.xcf
65
+ - doc/res/images/dialog-information-med.png
66
+ - doc/res/images/rpot-large.xcf
67
+ - doc/res/images/rpot-big.png
68
+ - doc/res/stylesheets/normal.css
69
+ - doc/pages/COMMON.rb
70
+ - doc/pages/index.html
71
+ - doc/pages/index.rb
72
+ - doc/layouts/page.html
73
+ test_files: []
74
+
75
+ rdoc_options:
76
+ - --title
77
+ - Rote -- Template-based doc support for Rake
78
+ - --main
79
+ - README
80
+ - --line-numbers
81
+ - -o
82
+ - html/rdoc
83
+ extra_rdoc_files:
84
+ - README
85
+ - LICENSE
86
+ - TODO
87
+ executables:
88
+ - rote
89
+ extensions: []
90
+
91
+ requirements: []
92
+
93
+ dependencies: []
94
+