literate_maruku 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/History.txt +10 -1
- data/lib/literate_maruku.rb +44 -16
- data/lib/literate_maruku/version.rb +1 -1
- data/website/index.html +1 -1
- metadata +2 -2
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/History.txt
CHANGED
@@ -1,4 +1,13 @@
|
|
1
|
-
== 0.
|
1
|
+
== 0.1.1 2007-10-05
|
2
|
+
|
3
|
+
* minor enhancement:
|
4
|
+
* Removed global variable to fetch the root binding, use class variable
|
5
|
+
instead
|
6
|
+
* Configurable default values for execute, attach_output and hide
|
7
|
+
* looking for the file to load in current directory as well
|
8
|
+
* updated docs
|
9
|
+
|
10
|
+
== 0.1.0 2007-09-30
|
2
11
|
|
3
12
|
* 1 major enhancement:
|
4
13
|
* Initial release
|
data/lib/literate_maruku.rb
CHANGED
@@ -10,27 +10,47 @@ module LiterateMaruku
|
|
10
10
|
# Besides these methods, maruku itself is exented to handle the new meta-data
|
11
11
|
# keywords. In your Markdown code use <tt>{: execute}</tt> to evaluate the
|
12
12
|
# code block and <tt>{: execute attach_output}</tt> to evaluate the code and
|
13
|
-
# attach the result to the generated document.
|
14
|
-
#
|
13
|
+
# attach the result to the generated document. If you need to execute code
|
14
|
+
# that should not be rendered attach <tt>{: execute hide}</tt>.
|
15
15
|
module ClassMethods
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
|
16
|
+
# This accessor stores the binding, in which the code will be executed. By
|
17
|
+
# default, this is the root context. Use the setter to change it, if you
|
18
|
+
# would like to have all your code in a special context, a module for
|
19
|
+
# example.
|
20
|
+
attr_accessor :binding
|
21
|
+
|
22
|
+
# <tt>file</tt> has to have a <tt>.mkd</tt> extension. The
|
23
|
+
# <tt>LOAD_PATH</tt> will be used to find the file. It will be simply
|
24
|
+
# executed. If called with <tt>:output => dir</tt>, html generated from the
|
25
|
+
# markdown document will be stored in the given directory. The resulting
|
26
|
+
# file name will include the basename of <tt>file</tt> and the
|
27
|
+
# <tt>.html</tt> file extension.
|
28
|
+
#
|
29
|
+
# Additionally default values, that influence the code generation and
|
30
|
+
# execution may be set.
|
31
|
+
#
|
32
|
+
# LiterateMaruku.require("file.mkd", :output => ".",
|
33
|
+
# :attributes => {:execute => true})
|
34
|
+
#
|
35
|
+
# will enable execution for all code block per default, for example. Other
|
36
|
+
# options are <tt>:attach_output</tt> and <tt>:hide</tt>.
|
21
37
|
def require(file, options = {})
|
22
38
|
document = generate_output(file)
|
23
|
-
|
24
|
-
document
|
39
|
+
|
40
|
+
document.attributes.merge!(options[:attributes] || {})
|
41
|
+
content = options[:inline] ? document.to_html : document.to_html_document
|
42
|
+
store_in_file(File.basename(file, ".mkd"), content, options[:output])
|
43
|
+
|
44
|
+
content
|
25
45
|
end
|
26
46
|
|
27
47
|
private
|
28
48
|
def generate_output(file)
|
29
|
-
Maruku.new(markdown_string(file))
|
49
|
+
Maruku.new(markdown_string(file))
|
30
50
|
end
|
31
51
|
|
32
52
|
def markdown_string(file)
|
33
|
-
dir = $:.find
|
53
|
+
dir = $:.find{ |load_dir| File.exists?(File.join(load_dir, file)) } || "."
|
34
54
|
File.open(File.join(dir, file)){|f| f.readlines.join}
|
35
55
|
end
|
36
56
|
|
@@ -46,7 +66,7 @@ module LiterateMaruku
|
|
46
66
|
extend ClassMethods
|
47
67
|
end
|
48
68
|
|
49
|
-
|
69
|
+
LiterateMaruku.binding = binding
|
50
70
|
|
51
71
|
# This is the basic module provided by Maruku, but Literate Maruku added three
|
52
72
|
# parameters to configure its behaviour.
|
@@ -58,6 +78,9 @@ $literate_maruku_binding = binding
|
|
58
78
|
# Set <tt>MaRuKu::Globals[:attach_output]</tt> to true, if you like to attach
|
59
79
|
# the results of code blocks by default. To disable this option for single
|
60
80
|
# blocks, add <tt>{: attach_output=false}</tt>.
|
81
|
+
#
|
82
|
+
# *Note*: These settings may also be configured on an instance basis, when
|
83
|
+
# calling <tt>LiterateMaruku#require</tt> with an attributes Hash.
|
61
84
|
module MaRuKu
|
62
85
|
Globals[:execute] = false
|
63
86
|
Globals[:attach_output] = false
|
@@ -67,17 +90,22 @@ module MaRuKu
|
|
67
90
|
module HTML
|
68
91
|
unless instance_methods.include? "to_html_code_using_pre_with_literate"
|
69
92
|
def to_html_code_using_pre_with_literate(source)
|
70
|
-
if
|
71
|
-
value = eval(source,
|
72
|
-
source += "\n>> " + value.inspect if
|
93
|
+
if is_true?(:execute)
|
94
|
+
value = eval(source, LiterateMaruku.binding)
|
95
|
+
source += "\n>> " + value.inspect if is_true?(:attach_output)
|
73
96
|
end
|
74
|
-
to_html_code_using_pre_without_literate(source) if !
|
97
|
+
to_html_code_using_pre_without_literate(source) if !is_true?(:hide)
|
75
98
|
end
|
76
99
|
|
77
100
|
alias_method :to_html_code_using_pre_without_literate,
|
78
101
|
:to_html_code_using_pre
|
79
102
|
alias_method :to_html_code_using_pre,
|
80
103
|
:to_html_code_using_pre_with_literate
|
104
|
+
|
105
|
+
private
|
106
|
+
def is_true?(key)
|
107
|
+
get_setting(key) && get_setting(key) != "false"
|
108
|
+
end
|
81
109
|
end
|
82
110
|
end
|
83
111
|
end
|
data/website/index.html
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
<h1>literate_maruku</h1>
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/literate_maruku"; return false'>
|
35
35
|
<p>Get Version</p>
|
36
|
-
<a href="http://rubyforge.org/projects/literate_maruku" class="numbers">0.1.
|
36
|
+
<a href="http://rubyforge.org/projects/literate_maruku" class="numbers">0.1.1</a>
|
37
37
|
</div>
|
38
38
|
<h1>→ ‘literate_maruku’</h1>
|
39
39
|
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: literate_maruku
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.1.1
|
7
|
+
date: 2007-10-05 00:00:00 +02:00
|
8
8
|
summary: Literate programming for ruby based on maruku
|
9
9
|
require_paths:
|
10
10
|
- lib
|
metadata.gz.sig
CHANGED
Binary file
|