lit_doc 0.1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 01fa47592181c786d76c665e4df652cb9807129b
4
+ data.tar.gz: c3dd4dc2324965ef0b1b5df3cdbea32caf62cd0f
5
+ SHA512:
6
+ metadata.gz: 9217466d62fe008d2a994c06d47b92ae920d3a673632a41893d213bd175d8d6b23854633b724f8e3fa625a0a5b5f39f7d228a933f35be7ffad45110e01fb138e
7
+ data.tar.gz: 66dc4dfa84abf7e8fd39ee71ab5520ef3f65161a44748aaa75f26d838559246f510b56f6474bbdd340357b022cfd9c01ca6c243d8f5849d9c8883f6e566216ee
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+
14
+ spec/support/rails_app/doc/gen/generated.md
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.14.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at humoud.alsaleh@kgl.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lit_doc.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Homood
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,99 @@
1
+ # Lit Doc 🔥
2
+ [![Build Status](https://travis-ci.org/Humoud/lit_doc.svg?branch=master)](https://travis-ci.org/Humoud/lit_doc)
3
+
4
+ **this gem hasn't been released yet**
5
+
6
+ This gem is a collection of Rake Tasks that make writing docs easier by
7
+ allowing you to write the docs inside ruby files.
8
+ It also makes documentation much less of a repetitive process.
9
+ That is done by using the Lit Doc code to generate the repetitive parts of the doc.
10
+
11
+ ## Installation
12
+
13
+ this gem hasn't been released yet
14
+
15
+ ## Usage
16
+
17
+ 1. run `rails lit_doc:prepare` generate the following:
18
+ 1. doc/source/source.md
19
+ 2. doc/gen/generate.md
20
+ 2. in source.md import the files that contain lit doc documentation like so:
21
+ * `@import "app/controllers/application_controller.rb"`
22
+ 3. run `rails lit_doc:generate` to generate a doc. You can find the result in doc/gen/generate.md.
23
+
24
+ ## End Goal Usage Scenario
25
+ in source.md:
26
+
27
+ have a mixture of markdown syntax and "@import 'rails.root/path_to_file'" statements
28
+ the markdown syntax will be copied as it is to the generate.md while the imported files
29
+ will be scanned for Lit Doc code.
30
+
31
+ Lit Doc code example:
32
+ Let's say we have a controller that we want to document some actions/methods in it.
33
+ above each action that the user wishes to document, he/she will use the following syntax:
34
+
35
+ **NOTE:** Lit Doc syntax starts with 2 hashtags
36
+ ``` ruby
37
+ ## @h: header text
38
+ ## @r: http method route
39
+ ## @b-model: path to model
40
+ ## @b-serializer: path to serializer
41
+ ## @res-model: path to model
42
+ ## @res-serializer: path to serializer
43
+ ## regular markdown
44
+ def index
45
+ ## do something
46
+ end
47
+
48
+ # Example:
49
+ # in app/controllers/users_controller.rb
50
+ class UsersController < ApplicationController
51
+ ## @h: User Create
52
+ ## @r: POST /users
53
+ ## @b-model: User
54
+ ## @res-model: User
55
+ ## **NOTE:** This needs optimization
56
+ def create
57
+ ## do something
58
+ end
59
+ end
60
+
61
+ # and in app/models/user.rb
62
+ class User < ApplicationRecord
63
+ ## @b:
64
+ ## {
65
+ ## name: 'tim',
66
+ ## email: "tim@mailz.com"
67
+ ## }
68
+
69
+ ## @res:
70
+ ## {
71
+ ## name: 'tim',
72
+ ## email: "tim@mailz.com",
73
+ ## updated_at: "91231-543-157",
74
+ ## created_at: "123-1231-123"
75
+ ## }
76
+ end
77
+ ```
78
+
79
+ A brief example of the Lit Doc code/syntax:
80
+
81
+ * `@h` means header.
82
+ * `@r` means route.
83
+ * `@b` means body and `@res` means response.
84
+ * `@b-model` means generating body using model and `@res-model` means generating
85
+ * response using model.
86
+
87
+ ## Development
88
+
89
+ run tests with `rake spec`
90
+
91
+
92
+ ## Contributing
93
+
94
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Humoud/lit_doc. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
95
+
96
+
97
+ ## License
98
+
99
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "lit_doc"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ class LitDoc::Railtie < Rails::Railtie
2
+ rake_tasks do
3
+ load 'tasks/lit_doc.rake'
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module LitDoc
2
+ VERSION = "0.1.0.pre"
3
+ end
data/lib/lit_doc.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "lit_doc/version"
2
+ require "lit_doc/railtie" if defined?(Rails)
3
+
4
+ module LitDoc
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,163 @@
1
+ module Scanner
2
+
3
+ # return all files to be imported/scanned(files that contain lit doc)
4
+ def read_source_file(file_path)
5
+ import_file_paths = []
6
+
7
+ File.open(file_path, "r").each_line do |line|
8
+ line.lstrip!
9
+ args = line.split(' ')
10
+ # puts "arguments in source.md: #{args}"
11
+ if args[0] == "@import"
12
+ import_file_paths.push(args[1].gsub('"', ''))
13
+ end
14
+ end
15
+
16
+ return import_file_paths
17
+ end
18
+
19
+ # go through imported files and return lines that contain lit doc code
20
+ def scan_file(file_paths, root_path=Rails.root)
21
+ lines_with_doc = []
22
+
23
+ file_paths.each do |path|
24
+ File.open("#{root_path}/#{path}", "r").each_line do |line|
25
+ # regex: lines that satisfy the following conditions:
26
+ # 1. can start with a white space
27
+ # 2. start with 2 hashtags
28
+ if (line[/^\s*##.*/])
29
+ # remove trailing and leading white space and add to array
30
+ lines_with_doc.push(line.strip)
31
+ end
32
+ end
33
+ end
34
+
35
+ return lines_with_doc
36
+ end
37
+ ##############################################################################
38
+ ### detect lit doc code and process it
39
+ ### lit code syntax:
40
+ ## @h: header text
41
+ ## @r: http method route
42
+ ## @b-model: path to model
43
+ ## @b-serializer: path to serializer
44
+ ## @res-model: path to model
45
+ ## @res-serializer: path to serializer
46
+ ## regular markdown
47
+ def process_lines(lines, generated_file_path)
48
+ lines.each do |line|
49
+ args = line.split(' ')
50
+ case args[1]
51
+ when "@h:"
52
+ # puts "this is a header"
53
+ # remove first 2 entries in array
54
+ args.shift(2)
55
+ process_header(args, generated_file_path)
56
+ when "@b-model:"
57
+ # puts "this is a body"
58
+ # remove first 2 entries in array
59
+ args.shift(2)
60
+ process_body_model(args, generated_file_path)
61
+ when "@res-model:"
62
+ # puts "this is a response"
63
+ # remove first 2 entries in array
64
+ args.shift(2)
65
+ process_response_model(args, generated_file_path)
66
+ else
67
+ # puts "this is regular markdown"
68
+ # remove first entry in array
69
+ args.shift
70
+ process_markdown(args, generated_file_path)
71
+ end
72
+ end
73
+ end
74
+
75
+ private
76
+ ############################################################################
77
+ #### FORMAT:
78
+ # TODO user passes size of headers(number of # to print) when importing
79
+ #
80
+ def process_header(args, file_path)
81
+ # puts "args: #{args}"
82
+ args = args.join(' ')
83
+ File.open(file_path, "a") do |f|
84
+ f << "#### #{args}"
85
+ f << "\n"
86
+ end
87
+ end
88
+
89
+ def process_body_model(args, file_path)
90
+ # puts "args: #{args}"
91
+ args = args.join(' ').strip
92
+ lines = scan_model_for_body(args)
93
+ File.open(file_path, "a") do |f|
94
+ lines.each do |l|
95
+ f << l
96
+ f << "\n"
97
+ end
98
+ end
99
+ end
100
+
101
+ def process_response_model(args, file_path)
102
+ # puts "args: #{args}"
103
+ args = args.join(' ').strip
104
+ lines = scan_model_for_response(args)
105
+ File.open(file_path, "a") do |f|
106
+ lines.each do |l|
107
+ f << l
108
+ f << "\n"
109
+ end
110
+ end
111
+ end
112
+
113
+ def process_markdown(args, file_path)
114
+ # puts "args: #{args}"
115
+ args = args.join(' ')
116
+ File.open(file_path, "a") do |f|
117
+ f << "#{args}"
118
+ f << "\n"
119
+ end
120
+ end
121
+
122
+ ############################################################################
123
+ ####### GET RESPONSE AND BODY FROM MODEL
124
+ ### detect lit doc code and process it
125
+ ### lit code syntax:
126
+ ## @h: header text
127
+ ## @b: body
128
+ ## @res: response
129
+ def scan_model_for_body(model_name)
130
+ return scan_model("@b:", model_name)
131
+ end
132
+
133
+ def scan_model_for_response(model_name)
134
+ return scan_model("@res:", model_name)
135
+ end
136
+
137
+ def scan_model(switch, model_name)
138
+ path = "app/models/#{model_name.downcase}.rb"
139
+ scanned_docs = []
140
+ read_doc_flag = false
141
+ File.open(path, "r").each_line do |line|
142
+ if (line[/^\s*##.*/])
143
+ args = line.strip.split(' ')
144
+ # at start of body doc
145
+ if args[1] == switch
146
+ read_doc_flag = true
147
+ scanned_docs.push("``` json")
148
+ elsif read_doc_flag
149
+ args.shift(1)
150
+ doc = args.join(' ')
151
+ scanned_docs.push("#{doc}")
152
+ end
153
+ else
154
+ # line has no ##, switch read flag off
155
+ if read_doc_flag
156
+ read_doc_flag = false
157
+ scanned_docs.push("```")
158
+ end
159
+ end
160
+ end
161
+ return scanned_docs
162
+ end
163
+ end
@@ -0,0 +1,36 @@
1
+ # should be at root of rails app for this to work
2
+ require 'modules/scanner'
3
+ include Scanner
4
+
5
+ namespace :lit_doc do
6
+ @generated_file_path = "doc/gen/generated.md"
7
+ ##########################################################################
8
+ ### CREATE FILES AND FOLDERS DEPENDENCIES
9
+ #
10
+ directory "doc"
11
+ directory "doc/gen" => "doc"
12
+ directory "doc/source" => "doc"
13
+ file "doc/source/source.md" => ["doc/source", "doc/gen"] do
14
+ touch "doc/source/source.md"
15
+ end
16
+ file @generated_file_path => "doc/source/source.md" do
17
+ touch @generated_file_path
18
+ end
19
+
20
+ task :prepare => ["doc/source/source.md", @generated_file_path]
21
+
22
+ ##########################################################################
23
+ ### Lit Doc Rake Task
24
+ #
25
+ task :generate => :prepare do
26
+ puts "Reading list of files to scan:"
27
+ # get files that are imported
28
+ file_paths = Scanner.read_source_file("doc/source/source.md")
29
+ puts "files to be imported: #{file_paths}"
30
+ # get lines that contain lit doc code
31
+ lines_with_docs = Scanner.scan_file(file_paths)
32
+ # puts "lines that contain doc syntax: #{lines_with_docs}"
33
+ # process lines
34
+ process_lines(lines_with_docs, @generated_file_path)
35
+ end
36
+ end
data/lit_doc.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lit_doc/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lit_doc"
8
+ spec.version = LitDoc::VERSION
9
+ spec.authors = ["Humoud"]
10
+ spec.email = ["humoud.m.alsaleh@gmail.com"]
11
+
12
+ spec.summary = "Makes documenting Rails APIs swift and easy."
13
+ spec.description = "Used to generate markdown docs for Rails API projects"
14
+ spec.homepage = "https://github.com/Humoud/lit_doc"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.14"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "activesupport", "~> 5.1"
28
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lit_doc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre
5
+ platform: ruby
6
+ authors:
7
+ - Humoud
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.1'
69
+ description: Used to generate markdown docs for Rails API projects
70
+ email:
71
+ - humoud.m.alsaleh@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/lit_doc.rb
87
+ - lib/lit_doc/railtie.rb
88
+ - lib/lit_doc/version.rb
89
+ - lib/modules/scanner.rb
90
+ - lib/tasks/lit_doc.rake
91
+ - lit_doc.gemspec
92
+ homepage: https://github.com/Humoud/lit_doc
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">"
108
+ - !ruby/object:Gem::Version
109
+ version: 1.3.1
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.6.11
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Makes documenting Rails APIs swift and easy.
116
+ test_files: []