lit_doc 0.1.1.pre → 0.1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b2bf42a0be7604c9ea09d497743ffc04a04fc47
4
- data.tar.gz: 809ea9a2ec38b4b5eddf3ff08ce922b259124f3a
3
+ metadata.gz: 75312356aaa43eea947262886fcfef1ce1f18f8c
4
+ data.tar.gz: 8a47d9a97d452baeca23775ea680cfb8faaac3c7
5
5
  SHA512:
6
- metadata.gz: 1cd80387090c1641d05c04722ae6e6015bc8b2bf07c58b78a4f500d6410ac06be381ea2fb423acdd532604037c3d1498e37eeff5507273762b16022c8c3bf7ec
7
- data.tar.gz: df3cb53f9d03be289ebb85fd01df17a91efef27a32d8d7ec159e3a99b58017ed43df402cf2e86409e5504dda80c60246ba89689bb5428f16cf9e3861956a31e9
6
+ metadata.gz: 6c5280fa971f932d50084cfc8681a0a45c994e76f0bb698c4c8f8192736b720a816be6caae324f66ee642b45273e12018f5f4c6d70d0ba528f595934f0c6c385
7
+ data.tar.gz: ee5e9df3b82e4e87830c5a246518d81dd37ac0be3391abb7a5aa7266bbc176ed1a99a8ca73c9466bc05cf2772de1a7d4aa20f1925047c51d1399ca20fa50ac43
data/README.md CHANGED
@@ -23,7 +23,10 @@ or in rails gemfile
23
23
  * `@import "app/controllers/application_controller.rb"`
24
24
  3. run `rails lit_doc:generate` to generate a doc. You can find the result in doc/gen/generate.md.
25
25
 
26
- ## End Goal Usage Scenario
26
+ ## Features to be Implemented
27
+ - [ ] Allow specific response (res) and body (b) imports, for example @res-model-index and @b-serializer-create
28
+
29
+ ## Usage Example
27
30
  in source.md:
28
31
 
29
32
  have a mixture of markdown syntax and "@import 'rails.root/path_to_file'" statements
@@ -37,7 +40,7 @@ above each action that the user wishes to document, he/she will use the followin
37
40
  **NOTE:** Lit Doc syntax starts with 2 hashtags
38
41
  ``` ruby
39
42
  ## @h: header text
40
- ## @r: http method route
43
+ ## @r: http_method route
41
44
  ## @b-model: path to model
42
45
  ## @b-serializer: path to serializer
43
46
  ## @res-model: path to model
@@ -1,3 +1,3 @@
1
1
  module LitDoc
2
- VERSION = "0.1.1.pre"
2
+ VERSION = "0.1.2.pre"
3
3
  end
@@ -6,14 +6,15 @@ module Scanner
6
6
  # [ { file: "file_path", header_sizes: {h: integer} } ]
7
7
  def read_source_file(file_path)
8
8
  file_paths_and_header_sizes = []
9
+ regular_markdown_lines = []
9
10
 
10
11
  File.open(file_path, "r").each_line do |line|
11
- line.lstrip!
12
- args = line.split(' ')
12
+ inspect_line = line.lstrip
13
+ args = inspect_line.split(' ')
13
14
  # puts "arguments in source.md: #{args}"
14
15
  if args[0] == "@import"
15
16
  # see if {h: 1} pattern exists
16
- header_sizes = line[/{\s*h:\s*[0-9]\s*}/]
17
+ header_sizes = inspect_line[/{\s*h:\s*[0-9]\s*}/]
17
18
  header_hash = Hash.new
18
19
  # if user passed sizes
19
20
  if header_sizes
@@ -27,10 +28,12 @@ module Scanner
27
28
 
28
29
  hash = {file: file_path.gsub('"', ''), header_sizes: header_hash}
29
30
  file_paths_and_header_sizes.push(hash)
31
+ else
32
+ regular_markdown_lines.push(line)
30
33
  end
31
34
  end
32
35
 
33
- return file_paths_and_header_sizes
36
+ return file_paths_and_header_sizes, regular_markdown_lines
34
37
  end
35
38
 
36
39
  # go through imported files and return lines that contain lit doc code
@@ -47,7 +50,7 @@ module Scanner
47
50
 
48
51
  file_paths_and_sizes.each do |path_and_size|
49
52
  lines_with_doc = []
50
-
53
+
51
54
  File.open("#{root_path}/#{path_and_size[:file]}", "r").each_line do |line|
52
55
  # regex: lines that satisfy the following conditions:
53
56
  # 1. can start with a white space
@@ -71,20 +74,31 @@ module Scanner
71
74
 
72
75
  return lines_and_header_sizes
73
76
  end
77
+
78
+ def process_regular_markdown_lines(lines, generated_file_path)
79
+ File.open(generated_file_path, "a") do |f|
80
+ lines.each do |line|
81
+ f << "#{line}"
82
+ end
83
+ end
84
+ end
74
85
  ##############################################################################
75
86
  ### detect lit doc code and process it
76
87
  ### lit code syntax:
77
88
  ## @h: header text
78
- ## @r: http method route
89
+ ## @r: http_method route
79
90
  ## @b-model: path to model
80
91
  ## @b-serializer: path to serializer
81
92
  ## @res-model: path to model
82
93
  ## @res-serializer: path to serializer
83
94
  ## regular markdown
84
- def process_lines(files_and_header_sizes, generated_file_path)
95
+ def process_lit_doc_lines(files_and_header_sizes, generated_file_path)
85
96
  files_and_header_sizes.each do |entry|
86
97
  entry[:file][:lines].each do |line|
87
98
  args = line.split(' ')
99
+
100
+ File.open(generated_file_path, "a"){ |f| f << "\n" }
101
+
88
102
  case args[1]
89
103
  when "@h:"
90
104
  # puts "this is a header"
@@ -92,6 +106,11 @@ module Scanner
92
106
  args.shift(2)
93
107
  header_size = entry[:file][:sizes][:h]
94
108
  process_header(args, generated_file_path, header_size)
109
+ when "@r:"
110
+ # puts "this is a route"
111
+ # remove first 2 entries in array
112
+ args.shift(2)
113
+ process_route(args, generated_file_path)
95
114
  when "@b-model:"
96
115
  # puts "this is a body"
97
116
  # remove first 2 entries in array
@@ -102,6 +121,16 @@ module Scanner
102
121
  # remove first 2 entries in array
103
122
  args.shift(2)
104
123
  process_response_model(args, generated_file_path)
124
+ when "@b-serializer:"
125
+ # puts "this is a body"
126
+ # remove first 2 entries in array
127
+ args.shift(2)
128
+ process_body_serializer(args, generated_file_path)
129
+ when "@res-serializer:"
130
+ # puts "this is a response"
131
+ # remove first 2 entries in array
132
+ args.shift(2)
133
+ process_response_serializer(args, generated_file_path)
105
134
  else
106
135
  # puts "this is regular markdown"
107
136
  # remove first entry in array
@@ -113,10 +142,6 @@ module Scanner
113
142
  end
114
143
 
115
144
  private
116
- ############################################################################
117
- #### FORMAT:
118
- # TODO user passes size of headers(number of # to print) when importing
119
- #
120
145
  def process_header(args, file_path, header_size)
121
146
  # puts "args: #{args}"
122
147
  args = args.join(' ')
@@ -128,6 +153,16 @@ module Scanner
128
153
  f << "\n"
129
154
  end
130
155
  end
156
+ # args = http_method url
157
+ def process_route(args, file_path)
158
+
159
+ File.open(file_path, "a") do |f|
160
+ # write to file
161
+ str = "`#{args[0].upcase} #{args[1]}`"
162
+ f << str
163
+ f << "\n"
164
+ end
165
+ end
131
166
 
132
167
  def process_body_model(args, file_path)
133
168
  # puts "args: #{args}"
@@ -153,6 +188,30 @@ module Scanner
153
188
  end
154
189
  end
155
190
 
191
+ def process_body_serializer(args, file_path)
192
+ # puts "args: #{args}"
193
+ args = args.join(' ').strip
194
+ lines = scan_serializer_for_body(args)
195
+ File.open(file_path, "a") do |f|
196
+ lines.each do |l|
197
+ f << l
198
+ f << "\n"
199
+ end
200
+ end
201
+ end
202
+
203
+ def process_response_serializer(args, file_path)
204
+ # puts "args: #{args}"
205
+ args = args.join(' ').strip
206
+ lines = scan_serializer_for_response(args)
207
+ File.open(file_path, "a") do |f|
208
+ lines.each do |l|
209
+ f << l
210
+ f << "\n"
211
+ end
212
+ end
213
+ end
214
+
156
215
  def process_markdown(args, file_path)
157
216
  # puts "args: #{args}"
158
217
  args = args.join(' ')
@@ -170,15 +229,32 @@ module Scanner
170
229
  ## @b: body
171
230
  ## @res: response
172
231
  def scan_model_for_body(model_name)
173
- return scan_model("@b:", model_name)
232
+ return scan_hash("@b:", "app/models/#{model_name.downcase}.rb")
174
233
  end
175
234
 
176
235
  def scan_model_for_response(model_name)
177
- return scan_model("@res:", model_name)
236
+ return scan_hash("@res:", "app/models/#{model_name.downcase}.rb")
178
237
  end
179
238
 
180
- def scan_model(switch, model_name)
181
- path = "app/models/#{model_name.downcase}.rb"
239
+ ############################################################################
240
+ ####### GET RESPONSE AND BODY FROM SERIALIZER
241
+ ### detect lit doc code and process it
242
+ ### lit code syntax:
243
+ ## @h: header text
244
+ ## @b: body
245
+ ## @res: response
246
+ def scan_serializer_for_body(model_name)
247
+ return scan_hash("@b:", "app/serializers/#{model_name.downcase}.rb")
248
+ end
249
+
250
+ def scan_serializer_for_response(model_name)
251
+ return scan_hash("@res:", "app/serializers/#{model_name.downcase}.rb")
252
+ end
253
+
254
+ ############################################################################
255
+ ####### HELPER METHODS
256
+ # scans for hash and turns it to jason
257
+ def scan_hash(switch, path)
182
258
  scanned_docs = []
183
259
  read_doc_flag = false
184
260
  File.open(path, "r").each_line do |line|
@@ -188,9 +264,20 @@ module Scanner
188
264
  if args[1] == switch
189
265
  read_doc_flag = true
190
266
  scanned_docs.push("``` json")
267
+ # start writing json
191
268
  elsif read_doc_flag
192
269
  args.shift(1)
193
- doc = args.join(' ')
270
+ formatted_json = []
271
+ args.map do |entry|
272
+ if /.*:/ =~ entry
273
+ #format
274
+ formatted_json.push('"'+entry[0..-2]+'"'+':')
275
+ else
276
+ # doesn't need formatting
277
+ formatted_json.push(entry)
278
+ end
279
+ end
280
+ doc = formatted_json.join(' ')
194
281
  scanned_docs.push("#{doc}")
195
282
  end
196
283
  else
@@ -25,12 +25,13 @@ 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
- file_paths_and_header_sizes = Scanner.read_source_file("doc/source/source.md")
28
+ file_paths_and_header_sizes, regular_markdown_lines = 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
- # puts "lines that contain doc syntax: #{lines_with_docs}"
33
- # process lines
34
- process_lines(lines_and_header_sizes, @generated_file_path)
32
+ # process regular markdown lines
33
+ process_regular_markdown_lines(regular_markdown_lines, @generated_file_path)
34
+ # process lit doc lines
35
+ process_lit_doc_lines(lines_and_header_sizes, @generated_file_path)
35
36
  end
36
37
  end
data/lit_doc.gemspec CHANGED
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
26
  spec.add_development_dependency "rspec", "~> 3.0"
27
27
  spec.add_development_dependency "activesupport", "~> 5.1"
28
+ spec.add_development_dependency "byebug"
28
29
  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.1.pre
4
+ version: 0.1.2.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-24 00:00:00.000000000 Z
11
+ date: 2017-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '5.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: Used to generate markdown docs for Rails API projects
70
84
  email:
71
85
  - humoud.m.alsaleh@gmail.com