literate_maruku 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.
- data/History.txt +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +26 -0
- data/README.txt +4 -0
- data/Rakefile +4 -0
- data/bin/literate_maruku +62 -0
- data/config/hoe.rb +70 -0
- data/config/requirements.rb +17 -0
- data/lib/literate_maruku/version.rb +9 -0
- data/lib/literate_maruku.rb +84 -0
- data/log/debug.log +0 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/tasks/deployment.rake +27 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +17 -0
- data/test/test_document.mkd +25 -0
- data/test/test_helper.rb +2 -0
- data/test/test_literate_maruku.rb +70 -0
- data/website/index.html +209 -0
- data/website/index.txt +131 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +140 -0
- data/website/template.rhtml +48 -0
- data.tar.gz.sig +0 -0
- metadata +99 -0
- metadata.gz.sig +0 -0
data/History.txt
ADDED
data/License.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2007 Gregor Schmidt
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
bin/literate_maruku
|
7
|
+
config/hoe.rb
|
8
|
+
config/requirements.rb
|
9
|
+
lib/literate_maruku.rb
|
10
|
+
lib/literate_maruku/version.rb
|
11
|
+
log/debug.log
|
12
|
+
script/destroy
|
13
|
+
script/generate
|
14
|
+
script/txt2html
|
15
|
+
setup.rb
|
16
|
+
tasks/deployment.rake
|
17
|
+
tasks/environment.rake
|
18
|
+
tasks/website.rake
|
19
|
+
test/test_document.mkd
|
20
|
+
test/test_helper.rb
|
21
|
+
test/test_literate_maruku.rb
|
22
|
+
website/index.html
|
23
|
+
website/index.txt
|
24
|
+
website/javascripts/rounded_corners_lite.inc.js
|
25
|
+
website/stylesheets/screen.css
|
26
|
+
website/template.rhtml
|
data/README.txt
ADDED
data/Rakefile
ADDED
data/bin/literate_maruku
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Created by Gregor Schmidt on 2007-9-30.
|
4
|
+
# Copyright (c) 2007. All rights reserved.
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'rubygems'
|
8
|
+
rescue LoadError
|
9
|
+
# no rubygems to load, so we fail silently
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'optparse'
|
13
|
+
|
14
|
+
# NOTE: the option -p/--path= is given as an example, and should probably be replaced in your application.
|
15
|
+
|
16
|
+
OPTIONS = {
|
17
|
+
:output_path => nil
|
18
|
+
}
|
19
|
+
MANDATORY_OPTIONS = %w( )
|
20
|
+
|
21
|
+
parser = OptionParser.new do |opts|
|
22
|
+
opts.banner = <<BANNER
|
23
|
+
Literate Maruku allows you to interleave your documentation and the
|
24
|
+
corresponding code in a style of literate programming. This is the
|
25
|
+
command line front end of the literate_maruku gem. You may find
|
26
|
+
additional information on our website
|
27
|
+
|
28
|
+
http://rug-b.rubyforge.org/literate_maruku/
|
29
|
+
|
30
|
+
Usage: #{File.basename($0)} [options] filename.mkd
|
31
|
+
|
32
|
+
Options are:
|
33
|
+
BANNER
|
34
|
+
opts.separator ""
|
35
|
+
opts.on("-o", "--output_path=PATH", String,
|
36
|
+
"The root path for the generated files",
|
37
|
+
"If not set, not output will be generated") { |OPTIONS[:output_path]| }
|
38
|
+
opts.on("-h", "--help",
|
39
|
+
"Show this help message.") { puts opts; exit }
|
40
|
+
opts.parse!(ARGV)
|
41
|
+
|
42
|
+
if MANDATORY_OPTIONS && MANDATORY_OPTIONS.find { |option| OPTIONS[option.to_sym].nil? } or ARGV[0].nil?
|
43
|
+
puts opts; exit
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# do stuff
|
48
|
+
begin
|
49
|
+
gem "literate_maruku"
|
50
|
+
require "literate_maruku"
|
51
|
+
rescue LoadError
|
52
|
+
require File.dirname(__FILE__) + "/../lib/literate_maruku"
|
53
|
+
end
|
54
|
+
|
55
|
+
if OPTIONS[:output_path]
|
56
|
+
path = File.join(Dir.pwd, OPTIONS[:output_path])
|
57
|
+
puts "Generating output to \"#{OPTIONS[:output_path]}\""
|
58
|
+
LiterateMaruku.require(ARGV[0], :output => path)
|
59
|
+
else
|
60
|
+
LiterateMaruku.require(ARGV[0])
|
61
|
+
end
|
62
|
+
|
data/config/hoe.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'literate_maruku/version'
|
2
|
+
|
3
|
+
AUTHOR = 'Gregor Schmidt' # can also be an array of Authors
|
4
|
+
EMAIL = "ruby@schmidtwisser.de"
|
5
|
+
DESCRIPTION = "Literate programming for ruby based on maruku"
|
6
|
+
GEM_NAME = 'literate_maruku' # what ppl will type to install your gem
|
7
|
+
RUBYFORGE_PROJECT = 'rug-b' # The unix name for your project
|
8
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org/#{GEM_NAME}"
|
9
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
10
|
+
|
11
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
12
|
+
@config = nil
|
13
|
+
RUBYFORGE_USERNAME = "unknown"
|
14
|
+
def rubyforge_username
|
15
|
+
unless @config
|
16
|
+
begin
|
17
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
18
|
+
rescue
|
19
|
+
puts <<-EOS
|
20
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
21
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
22
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
23
|
+
EOS
|
24
|
+
exit
|
25
|
+
end
|
26
|
+
end
|
27
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
REV = nil
|
32
|
+
# UNCOMMENT IF REQUIRED:
|
33
|
+
# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
|
34
|
+
VERS = LiterateMaruku::VERSION::STRING + (REV ? ".#{REV}" : "")
|
35
|
+
RDOC_OPTS = ['--quiet', '--title', 'literate_maruku documentation',
|
36
|
+
"--opname", "index.html",
|
37
|
+
"--line-numbers",
|
38
|
+
"--main", "README",
|
39
|
+
"--inline-source"]
|
40
|
+
|
41
|
+
class Hoe
|
42
|
+
def extra_deps
|
43
|
+
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
44
|
+
@extra_deps
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Generate all the Rake tasks
|
49
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
50
|
+
hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
51
|
+
p.author = AUTHOR
|
52
|
+
p.description = DESCRIPTION
|
53
|
+
p.email = EMAIL
|
54
|
+
p.summary = DESCRIPTION
|
55
|
+
p.url = HOMEPATH
|
56
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
57
|
+
p.test_globs = ["test/**/test_*.rb"]
|
58
|
+
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
59
|
+
|
60
|
+
# == Optional
|
61
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\\n\\n")
|
62
|
+
#p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
|
63
|
+
|
64
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
69
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
70
|
+
hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
include FileUtils
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
%w[rake hoe newgem rubigen].each do |req_gem|
|
6
|
+
begin
|
7
|
+
require req_gem
|
8
|
+
rescue LoadError
|
9
|
+
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
10
|
+
puts "Installation: gem install #{req_gem} -y"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
16
|
+
|
17
|
+
require 'literate_maruku'
|
@@ -0,0 +1,84 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
gem "maruku"
|
5
|
+
require "maruku"
|
6
|
+
|
7
|
+
module LiterateMaruku
|
8
|
+
# The public interface to Literate Maruku
|
9
|
+
#
|
10
|
+
# Besides these methods, maruku itself is exented to handle the new meta-data
|
11
|
+
# keywords. In your Markdown code use <tt>{: execute}</tt> to evaluate the
|
12
|
+
# code block and <tt>{: execute attach_output}</tt> to evaluate the code and
|
13
|
+
# attach the result to the generated document. See our website or the tests
|
14
|
+
# for further examples.
|
15
|
+
module ClassMethods
|
16
|
+
# <tt>file</tt> has to have a <tt>.mkd</tt> extension. The LOAD_PATH will
|
17
|
+
# be used to find the file. It will be simply executed. If called with
|
18
|
+
# <tt>:output => dir</tt> html generated from the markdown document will
|
19
|
+
# be stored in the given directory. The resulting file name will include
|
20
|
+
# the basename of <tt>file</tt> and the <tt>.html</tt> file extension.
|
21
|
+
def require(file, options = {})
|
22
|
+
document = generate_output(file)
|
23
|
+
store_in_file(File.basename(file, ".mkd"), document, options[:output])
|
24
|
+
document
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def generate_output(file)
|
29
|
+
Maruku.new(markdown_string(file)).to_html_document
|
30
|
+
end
|
31
|
+
|
32
|
+
def markdown_string(file)
|
33
|
+
dir = $:.find { |load_dir| File.exists?(File.join(load_dir, file)) }
|
34
|
+
File.open(File.join(dir, file)){|f| f.readlines.join}
|
35
|
+
end
|
36
|
+
|
37
|
+
def store_in_file(file_base_name, string, directory)
|
38
|
+
if directory
|
39
|
+
File.open(File.join(directory, file_base_name + ".html"), "w") do |f|
|
40
|
+
f.puts(string)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
extend ClassMethods
|
47
|
+
end
|
48
|
+
|
49
|
+
$literate_maruku_binding = binding
|
50
|
+
|
51
|
+
# This is the basic module provided by Maruku, but Literate Maruku added three
|
52
|
+
# parameters to configure its behaviour.
|
53
|
+
#
|
54
|
+
# Set <tt>MaRuKu::Globals[:execute]</tt> to true, if you like to execute code
|
55
|
+
# block by default. To disable the execution for single blocks, add
|
56
|
+
# <tt>{: execute=false}</tt>.
|
57
|
+
#
|
58
|
+
# Set <tt>MaRuKu::Globals[:attach_output]</tt> to true, if you like to attach
|
59
|
+
# the results of code blocks by default. To disable this option for single
|
60
|
+
# blocks, add <tt>{: attach_output=false}</tt>.
|
61
|
+
module MaRuKu
|
62
|
+
Globals[:execute] = false
|
63
|
+
Globals[:attach_output] = false
|
64
|
+
Globals[:hide] = false
|
65
|
+
|
66
|
+
module Out # :nodoc: all
|
67
|
+
module HTML
|
68
|
+
unless instance_methods.include? "to_html_code_using_pre_with_literate"
|
69
|
+
def to_html_code_using_pre_with_literate(source)
|
70
|
+
if get_setting(:execute)
|
71
|
+
value = eval(source, $literate_maruku_binding)
|
72
|
+
source += "\n>> " + value.inspect if get_setting(:attach_output)
|
73
|
+
end
|
74
|
+
to_html_code_using_pre_without_literate(source) if !get_setting(:hide)
|
75
|
+
end
|
76
|
+
|
77
|
+
alias_method :to_html_code_using_pre_without_literate,
|
78
|
+
:to_html_code_using_pre
|
79
|
+
alias_method :to_html_code_using_pre,
|
80
|
+
:to_html_code_using_pre_with_literate
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/log/debug.log
ADDED
File without changes
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.join(File.dirname(__FILE__), '..')
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.join(File.dirname(__FILE__), '..')
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/script/txt2html
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
begin
|
5
|
+
require 'newgem'
|
6
|
+
rescue LoadError
|
7
|
+
puts "\n\nGenerating the website requires the newgem RubyGem"
|
8
|
+
puts "Install: gem install newgem\n\n"
|
9
|
+
exit(1)
|
10
|
+
end
|
11
|
+
require 'redcloth'
|
12
|
+
require 'syntax/convertors/html'
|
13
|
+
require 'erb'
|
14
|
+
require File.dirname(__FILE__) + '/../lib/literate_maruku/version.rb'
|
15
|
+
|
16
|
+
version = LiterateMaruku::VERSION::STRING
|
17
|
+
download = 'http://rubyforge.org/projects/literate_maruku'
|
18
|
+
|
19
|
+
class Fixnum
|
20
|
+
def ordinal
|
21
|
+
# teens
|
22
|
+
return 'th' if (10..19).include?(self % 100)
|
23
|
+
# others
|
24
|
+
case self % 10
|
25
|
+
when 1: return 'st'
|
26
|
+
when 2: return 'nd'
|
27
|
+
when 3: return 'rd'
|
28
|
+
else return 'th'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Time
|
34
|
+
def pretty
|
35
|
+
return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def convert_syntax(syntax, source)
|
40
|
+
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
|
41
|
+
end
|
42
|
+
|
43
|
+
if ARGV.length >= 1
|
44
|
+
src, template = ARGV
|
45
|
+
template ||= File.join(File.dirname(__FILE__), '/../website/template.rhtml')
|
46
|
+
|
47
|
+
else
|
48
|
+
puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
|
49
|
+
exit!
|
50
|
+
end
|
51
|
+
|
52
|
+
template = ERB.new(File.open(template).read)
|
53
|
+
|
54
|
+
title = nil
|
55
|
+
body = nil
|
56
|
+
File.open(src) do |fsrc|
|
57
|
+
title_text = fsrc.readline
|
58
|
+
body_text = fsrc.read
|
59
|
+
syntax_items = []
|
60
|
+
body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
|
61
|
+
ident = syntax_items.length
|
62
|
+
element, syntax, source = $1, $2, $3
|
63
|
+
syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
|
64
|
+
"syntax-temp-#{ident}"
|
65
|
+
}
|
66
|
+
title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
|
67
|
+
body = RedCloth.new(body_text).to_html
|
68
|
+
body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
|
69
|
+
end
|
70
|
+
stat = File.stat(src)
|
71
|
+
created = stat.ctime
|
72
|
+
modified = stat.mtime
|
73
|
+
|
74
|
+
$stdout << template.result(binding)
|