lit_doc 0.1.0.pre → 0.1.1.pre
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.
- checksums.yaml +4 -4
- data/README.md +9 -3
- data/lib/lit_doc/version.rb +1 -1
- data/lib/modules/scanner.rb +77 -34
- data/lib/tasks/lit_doc.rake +3 -3
- 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: 5b2bf42a0be7604c9ea09d497743ffc04a04fc47
|
4
|
+
data.tar.gz: 809ea9a2ec38b4b5eddf3ff08ce922b259124f3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cd80387090c1641d05c04722ae6e6015bc8b2bf07c58b78a4f500d6410ac06be381ea2fb423acdd532604037c3d1498e37eeff5507273762b16022c8c3bf7ec
|
7
|
+
data.tar.gz: df3cb53f9d03be289ebb85fd01df17a91efef27a32d8d7ec159e3a99b58017ed43df402cf2e86409e5504dda80c60246ba89689bb5428f16cf9e3861956a31e9
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Lit Doc 🔥
|
2
2
|
[](https://travis-ci.org/Humoud/lit_doc)
|
3
3
|
|
4
|
-
**this gem hasn't been released yet**
|
5
|
-
|
6
4
|
This gem is a collection of Rake Tasks that make writing docs easier by
|
7
5
|
allowing you to write the docs inside ruby files.
|
8
6
|
It also makes documentation much less of a repetitive process.
|
@@ -10,7 +8,11 @@ That is done by using the Lit Doc code to generate the repetitive parts of the d
|
|
10
8
|
|
11
9
|
## Installation
|
12
10
|
|
13
|
-
|
11
|
+
`gem install lit_doc --pre`
|
12
|
+
|
13
|
+
or in rails gemfile
|
14
|
+
|
15
|
+
`gem "lit_doc", "0.1.1.pre"`
|
14
16
|
|
15
17
|
## Usage
|
16
18
|
|
@@ -46,6 +48,10 @@ def index
|
|
46
48
|
end
|
47
49
|
|
48
50
|
# Example:
|
51
|
+
# in doc/source/source.md:
|
52
|
+
# where h: 2 is the number of #'s before the @h header
|
53
|
+
@import "app/controllers/users_controller.rb", {h: 2}
|
54
|
+
|
49
55
|
# in app/controllers/users_controller.rb
|
50
56
|
class UsersController < ApplicationController
|
51
57
|
## @h: User Create
|
data/lib/lit_doc/version.rb
CHANGED
data/lib/modules/scanner.rb
CHANGED
@@ -1,27 +1,54 @@
|
|
1
1
|
module Scanner
|
2
2
|
|
3
3
|
# return all files to be imported/scanned(files that contain lit doc)
|
4
|
+
# and headers sizes for each file
|
5
|
+
# returns array of hashes:
|
6
|
+
# [ { file: "file_path", header_sizes: {h: integer} } ]
|
4
7
|
def read_source_file(file_path)
|
5
|
-
|
8
|
+
file_paths_and_header_sizes = []
|
6
9
|
|
7
10
|
File.open(file_path, "r").each_line do |line|
|
8
11
|
line.lstrip!
|
9
12
|
args = line.split(' ')
|
10
13
|
# puts "arguments in source.md: #{args}"
|
11
14
|
if args[0] == "@import"
|
12
|
-
|
15
|
+
# see if {h: 1} pattern exists
|
16
|
+
header_sizes = line[/{\s*h:\s*[0-9]\s*}/]
|
17
|
+
header_hash = Hash.new
|
18
|
+
# if user passed sizes
|
19
|
+
if header_sizes
|
20
|
+
# convert str to ruby hash
|
21
|
+
header_hash = eval header_sizes
|
22
|
+
# set default size
|
23
|
+
else
|
24
|
+
header_hash = {h: 2}
|
25
|
+
end
|
26
|
+
file_path = args[1][/".*"/]
|
27
|
+
|
28
|
+
hash = {file: file_path.gsub('"', ''), header_sizes: header_hash}
|
29
|
+
file_paths_and_header_sizes.push(hash)
|
13
30
|
end
|
14
31
|
end
|
15
32
|
|
16
|
-
return
|
33
|
+
return file_paths_and_header_sizes
|
17
34
|
end
|
18
35
|
|
19
36
|
# go through imported files and return lines that contain lit doc code
|
20
|
-
|
21
|
-
|
37
|
+
# returns an array of hashes with the following format:
|
38
|
+
# {
|
39
|
+
# file:
|
40
|
+
# {
|
41
|
+
# sizes: {h: integer},
|
42
|
+
# lines: ["line of lit doc code"]
|
43
|
+
# }
|
44
|
+
# }
|
45
|
+
def scan_file(file_paths_and_sizes, root_path=Rails.root)
|
46
|
+
lines_and_header_sizes = []
|
22
47
|
|
23
|
-
|
24
|
-
|
48
|
+
file_paths_and_sizes.each do |path_and_size|
|
49
|
+
lines_with_doc = []
|
50
|
+
|
51
|
+
File.open("#{root_path}/#{path_and_size[:file]}", "r").each_line do |line|
|
25
52
|
# regex: lines that satisfy the following conditions:
|
26
53
|
# 1. can start with a white space
|
27
54
|
# 2. start with 2 hashtags
|
@@ -30,9 +57,19 @@ module Scanner
|
|
30
57
|
lines_with_doc.push(line.strip)
|
31
58
|
end
|
32
59
|
end
|
60
|
+
|
61
|
+
lines_and_header_sizes.push(
|
62
|
+
{
|
63
|
+
file:
|
64
|
+
{
|
65
|
+
sizes: path_and_size[:header_sizes],
|
66
|
+
lines: lines_with_doc
|
67
|
+
}
|
68
|
+
}
|
69
|
+
)
|
33
70
|
end
|
34
71
|
|
35
|
-
return
|
72
|
+
return lines_and_header_sizes
|
36
73
|
end
|
37
74
|
##############################################################################
|
38
75
|
### detect lit doc code and process it
|
@@ -44,30 +81,33 @@ module Scanner
|
|
44
81
|
## @res-model: path to model
|
45
82
|
## @res-serializer: path to serializer
|
46
83
|
## regular markdown
|
47
|
-
def process_lines(
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
84
|
+
def process_lines(files_and_header_sizes, generated_file_path)
|
85
|
+
files_and_header_sizes.each do |entry|
|
86
|
+
entry[:file][:lines].each do |line|
|
87
|
+
args = line.split(' ')
|
88
|
+
case args[1]
|
89
|
+
when "@h:"
|
90
|
+
# puts "this is a header"
|
91
|
+
# remove first 2 entries in array
|
92
|
+
args.shift(2)
|
93
|
+
header_size = entry[:file][:sizes][:h]
|
94
|
+
process_header(args, generated_file_path, header_size)
|
95
|
+
when "@b-model:"
|
96
|
+
# puts "this is a body"
|
97
|
+
# remove first 2 entries in array
|
98
|
+
args.shift(2)
|
99
|
+
process_body_model(args, generated_file_path)
|
100
|
+
when "@res-model:"
|
101
|
+
# puts "this is a response"
|
102
|
+
# remove first 2 entries in array
|
103
|
+
args.shift(2)
|
104
|
+
process_response_model(args, generated_file_path)
|
105
|
+
else
|
106
|
+
# puts "this is regular markdown"
|
107
|
+
# remove first entry in array
|
108
|
+
args.shift
|
109
|
+
process_markdown(args, generated_file_path)
|
110
|
+
end
|
71
111
|
end
|
72
112
|
end
|
73
113
|
end
|
@@ -77,11 +117,14 @@ module Scanner
|
|
77
117
|
#### FORMAT:
|
78
118
|
# TODO user passes size of headers(number of # to print) when importing
|
79
119
|
#
|
80
|
-
def process_header(args, file_path)
|
120
|
+
def process_header(args, file_path, header_size)
|
81
121
|
# puts "args: #{args}"
|
82
122
|
args = args.join(' ')
|
83
123
|
File.open(file_path, "a") do |f|
|
84
|
-
|
124
|
+
str = " #{args}"
|
125
|
+
header_size.to_i.times{ str.insert(0, "#")}
|
126
|
+
# write to file
|
127
|
+
f << str
|
85
128
|
f << "\n"
|
86
129
|
end
|
87
130
|
end
|
data/lib/tasks/lit_doc.rake
CHANGED
@@ -25,12 +25,12 @@ namespace :lit_doc do
|
|
25
25
|
task :generate => :prepare do
|
26
26
|
puts "Reading list of files to scan:"
|
27
27
|
# get files that are imported
|
28
|
-
|
28
|
+
file_paths_and_header_sizes = Scanner.read_source_file("doc/source/source.md")
|
29
29
|
puts "files to be imported: #{file_paths}"
|
30
30
|
# get lines that contain lit doc code
|
31
|
-
|
31
|
+
lines_and_header_sizes = Scanner.scan_file(file_paths_and_header_sizes)
|
32
32
|
# puts "lines that contain doc syntax: #{lines_with_docs}"
|
33
33
|
# process lines
|
34
|
-
process_lines(
|
34
|
+
process_lines(lines_and_header_sizes, @generated_file_path)
|
35
35
|
end
|
36
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lit_doc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Humoud
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|