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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a83fe70c28d8a6cb8cc3405ad8d4a74a7524e76e
4
- data.tar.gz: 836191dec59cbd069d3071b67c2b5c88b60b17c0
3
+ metadata.gz: 1ea055a2a41a4063b6e6c5606af470102f4b6f23
4
+ data.tar.gz: 9f7b160248668541eeb3252512c3194900df1436
5
5
  SHA512:
6
- metadata.gz: 3e74933ae262fd7a7457b972bea899a2e078d37b7e38a1c38fb46fe945193c9fe067c5f9671777cc539bff8c68199b6d35f988dc16277c205d7c80e1e92c6e67
7
- data.tar.gz: bcc1add2ddc784458b8f5b7071de7b5b2a6b6c2defbd166c3fe01942c7fa78da5eba66c67962370608f91e6615442f452efe0bd4ebea6ab886990651970515e9
6
+ metadata.gz: 72b5e0e705f045d115e4ac8474f4b7aa158386d6b962a891d212bd3b96fc9036258e4b76479f087e9a233b402c5b520fc7e82141853e700760916e2aaf15ebe8
7
+ data.tar.gz: f6f37d59ffea3690b9dee5b061bc61503f5d81395c139bb5e560c8fbf6f05262cdea250d25920e0683321426bc3f7769f456ba347560765483e4b0f7b4b0f536
data/README.md CHANGED
@@ -22,6 +22,7 @@ and here is some more commentary.
22
22
  > end
23
23
  > # if you want to
24
24
  > end
25
+ ```
25
26
 
26
27
  This is called bird style. There are specs on it
27
28
  [here](https://wiki.haskell.org/Literate_programming#Bird_Style).
@@ -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 #{File.basename(path, '.*')}.rb`
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
@@ -1,4 +1,5 @@
1
1
  require 'literate-ruby/file'
2
2
 
3
+ # This is the general module for the gem literate ruby.
3
4
  module LiterateRuby
4
5
  end
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.0
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-10 00:00:00.000000000 Z
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"