LiterateRuby 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/literate-ruby/file.rb +44 -1
- data/lib/literate-ruby.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ea055a2a41a4063b6e6c5606af470102f4b6f23
|
4
|
+
data.tar.gz: 9f7b160248668541eeb3252512c3194900df1436
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72b5e0e705f045d115e4ac8474f4b7aa158386d6b962a891d212bd3b96fc9036258e4b76479f087e9a233b402c5b520fc7e82141853e700760916e2aaf15ebe8
|
7
|
+
data.tar.gz: f6f37d59ffea3690b9dee5b061bc61503f5d81395c139bb5e560c8fbf6f05262cdea250d25920e0683321426bc3f7769f456ba347560765483e4b0f7b4b0f536
|
data/README.md
CHANGED
data/lib/literate-ruby/file.rb
CHANGED
@@ -1,8 +1,18 @@
|
|
1
1
|
module LiterateRuby
|
2
|
+
# This class is the file class for literate ruby.
|
3
|
+
# It mostly just inherits from Ruby's default File class.
|
4
|
+
#
|
5
|
+
# The method in this class that is added is `parse`. This method
|
6
|
+
# parses a literate ruby file (extension `.lrb`).
|
2
7
|
class File < File
|
8
|
+
# This method parses a literate ruby file, (which should have the
|
9
|
+
# extension `.lrb`), to a normal ruby file (which will have the
|
10
|
+
# extension `.rb`).
|
11
|
+
#
|
12
|
+
# @return [String] the file_path to the normal ruby file.
|
3
13
|
def parse
|
4
14
|
base = File.basename(path, '.*')
|
5
|
-
`touch #{
|
15
|
+
`touch #{base}.rb`
|
6
16
|
file = read
|
7
17
|
File.open("#{base}.rb", 'w') do |f|
|
8
18
|
file.each_line do |line|
|
@@ -11,5 +21,38 @@ module LiterateRuby
|
|
11
21
|
end
|
12
22
|
"#{base}.rb"
|
13
23
|
end
|
24
|
+
|
25
|
+
# This method parses a literate ruby file, (which should have the
|
26
|
+
# extension `.lrb`), to a markdown file (which will have the
|
27
|
+
# extension `.md`).
|
28
|
+
#
|
29
|
+
# @param [Boolean] ghfm if true then it will be written in github
|
30
|
+
# flavored markdown. Otherwise it will be in a more traditional
|
31
|
+
# markdown format.
|
32
|
+
# @return [String] the file_path to the markdown file.
|
33
|
+
def to_markdown(ghfm = false)
|
34
|
+
base = File.basename(path, '.*')
|
35
|
+
`touch #{base}.md`
|
36
|
+
file = read
|
37
|
+
File.open("#{base}.md", 'w') do |f|
|
38
|
+
code_block = false
|
39
|
+
file.each_line do |line|
|
40
|
+
if line[0...2] == '> ' && code_block && !ghfm
|
41
|
+
f.write(" #{line[2..-1]}")
|
42
|
+
elsif line[0...2] == '> ' && code_block
|
43
|
+
f.write("#{line[2..-1]}")
|
44
|
+
elsif code_block
|
45
|
+
code_block = false
|
46
|
+
f.write("\n#{line}")
|
47
|
+
elsif line =~ /^\s+$/
|
48
|
+
code_block = true
|
49
|
+
f.write(line)
|
50
|
+
else
|
51
|
+
f.write(line)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
"#{base}.md"
|
56
|
+
end
|
14
57
|
end
|
15
58
|
end
|
data/lib/literate-ruby.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: LiterateRuby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eli Sadoff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: "This gem is hightly inspired by literate haskell. It currently will
|
14
14
|
support \n\"bird style\" which is described in full [here](https://wiki.haskell.org/Literate_programming#Bird_Style).\n"
|