textualize 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +28 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +1 -0
- data/README.md +76 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/bin/textualize +7 -0
- data/circle.yml +8 -0
- data/lib/textualize.rb +33 -0
- data/lib/textualize/tasks/helpers/route_hash_creator.rb +62 -0
- data/lib/textualize/tasks/helpers/route_hashes.rb +21 -0
- data/lib/textualize/tasks/helpers/transformers/two_hundred.rb +30 -0
- data/lib/textualize/tasks/helpers/transformers/two_hundred_four.rb +17 -0
- data/lib/textualize/tasks/http_backend.rb +59 -0
- data/lib/textualize/tasks/new.rb +44 -0
- data/lib/textualize/tasks/request_specs.rb +48 -0
- data/lib/textualize/tasks/server.rb +35 -0
- data/lib/textualize/templates/http_backend/delete.js.erb +10 -0
- data/lib/textualize/templates/http_backend/get.js.erb +10 -0
- data/lib/textualize/templates/http_backend/module.js +1 -0
- data/lib/textualize/templates/http_backend/patch.js.erb +10 -0
- data/lib/textualize/templates/http_backend/post.js.erb +10 -0
- data/lib/textualize/templates/new/.gitignore +3 -0
- data/lib/textualize/templates/new/.ruby-version +1 -0
- data/lib/textualize/templates/new/Gemfile +5 -0
- data/lib/textualize/templates/new/Gemfile.lock +28 -0
- data/lib/textualize/templates/new/Readme.md +10 -0
- data/lib/textualize/templates/new/apis/base.raml +26 -0
- data/lib/textualize/templates/new/apis/base/routes/items.yaml +8 -0
- data/lib/textualize/templates/new/apis/base/routes/orders.yaml +8 -0
- data/lib/textualize/templates/new/apis/base/samples/item.json +12 -0
- data/lib/textualize/templates/new/apis/base/samples/items.json +34 -0
- data/lib/textualize/templates/new/apis/base/samples/order.json +43 -0
- data/lib/textualize/templates/new/apis/base/samples/orders.json +70 -0
- data/lib/textualize/templates/new/apis/base/schemas/item.json +17 -0
- data/lib/textualize/templates/new/apis/base/schemas/order.json +25 -0
- data/lib/textualize/templates/new/apis/documentation/authentication.yaml +21 -0
- data/lib/textualize/templates/new/apis/documentation/http_statuses.md +26 -0
- data/lib/textualize/templates/new/apis/errors.yaml +6 -0
- data/lib/textualize/templates/new/apis/resourceTypes/collection-item-ro.yaml +20 -0
- data/lib/textualize/templates/new/apis/resourceTypes/collection-item.yaml +20 -0
- data/lib/textualize/templates/new/apis/resourceTypes/collection-ro.yaml +18 -0
- data/lib/textualize/templates/new/apis/resourceTypes/collection.yaml +18 -0
- data/lib/textualize/templates/new/apis/responses/200.yaml +3 -0
- data/lib/textualize/templates/new/apis/responses/204.yaml +1 -0
- data/lib/textualize/templates/new/apis/responses/400.yaml +8 -0
- data/lib/textualize/templates/new/apis/responses/401.yaml +4 -0
- data/lib/textualize/templates/new/apis/responses/403.yaml +4 -0
- data/lib/textualize/templates/new/apis/responses/404.yaml +4 -0
- data/lib/textualize/templates/new/apis/responses/422.yaml +8 -0
- data/lib/textualize/templates/new/apis/responses/500.yaml +4 -0
- data/lib/textualize/templates/new/gulpfile.js +93 -0
- data/lib/textualize/templates/new/package.json +38 -0
- data/lib/textualize/templates/new/server/api/v1/items/get.json +1 -0
- data/lib/textualize/templates/new/server/api/v1/items/{item_id}/get.json +1 -0
- data/lib/textualize/templates/new/server/api/v1/orders/get.json +1 -0
- data/lib/textualize/templates/new/server/api/v1/orders/{order_id}/get.json +1 -0
- data/lib/textualize/templates/request_specs/delete_collection-item.rb.erb +0 -0
- data/lib/textualize/templates/request_specs/get_collection-item.rb.erb +16 -0
- data/lib/textualize/templates/request_specs/get_collection.rb.erb +16 -0
- data/lib/textualize/templates/request_specs/patch_collection-item.rb.erb +0 -0
- data/lib/textualize/templates/request_specs/post_collection.rb.erb +13 -0
- data/lib/textualize/version.rb +3 -0
- data/sample_item.rb +43 -0
- data/textualize.gemspec +41 -0
- metadata +259 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: af940a0bcbb1bca548ca4e51e84f68b5d69acaba
|
4
|
+
data.tar.gz: de4ec19be34141abc6612c767e861771819dab32
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1b6ceb22aa93feea2da4318fcd4a20bb356e96f497791ed99c43e5d834359ab56c0fc476e68376097c4bf26de746b865ec3e27be9708d254cd965faa912f4649
|
7
|
+
data.tar.gz: ba3df8ebf284c32d7dd086bffcb4c09f4b8db37902c8acd18b2eba909a0c8a12e5f5e9ed6913815594d66e4ce022d98c3a7beb70b718c7a003eb2f7b6eadc555
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.2
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all
|
4
|
+
people who contribute through reporting issues, posting feature requests,
|
5
|
+
updating documentation, submitting pull requests or patches, and other
|
6
|
+
activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, age, or religion.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include the use of sexual
|
14
|
+
language or imagery, derogatory comments or personal attacks, trolling, public
|
15
|
+
or private harassment, insults, or other unprofessional conduct.
|
16
|
+
|
17
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
18
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
19
|
+
that are not aligned to this Code of Conduct. Project maintainers who do not
|
20
|
+
follow the Code of Conduct may be removed from the project team.
|
21
|
+
|
22
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
23
|
+
reported by opening an issue or contacting one or more of the project
|
24
|
+
maintainers.
|
25
|
+
|
26
|
+
This Code of Conduct is adapted from the [Contributor
|
27
|
+
Covenant](http:contributor-covenant.org), version 1.0.0, available at
|
28
|
+
[http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
© Copyright 2015 - Q-Centrix LLC - MIT License
|
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# Textualize
|
2
|
+
|
3
|
+
A documentation template written in RAML and thor tasks to turn documentation
|
4
|
+
into so much more.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'textualize'
|
12
|
+
```
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
Textualize comes with the following generators:
|
17
|
+
|
18
|
+
### New
|
19
|
+
|
20
|
+
```bash
|
21
|
+
textualize new <folder-name>
|
22
|
+
```
|
23
|
+
|
24
|
+
The ``textualize new`` command creates sample documentation with the folder
|
25
|
+
structure needed for the other commands.
|
26
|
+
|
27
|
+
### Server
|
28
|
+
|
29
|
+
```bash
|
30
|
+
textualize server
|
31
|
+
```
|
32
|
+
|
33
|
+
The ``textualize server`` command creates a folder structure of JSON in the
|
34
|
+
``server`` folder.
|
35
|
+
|
36
|
+
### HttpBackend
|
37
|
+
|
38
|
+
```bash
|
39
|
+
textualize http_backend
|
40
|
+
```
|
41
|
+
|
42
|
+
The ``textualize http_backend`` command creates a minified javascript file,
|
43
|
+
``angular/textualize_http_backend.min.js`` that contains an angular module that
|
44
|
+
can be injected to provide a stubbed
|
45
|
+
[httpBackend](https://docs.angularjs.org/api/ngMockE2E/service/$httpBackend).
|
46
|
+
This can be used in both e2e tests and for prototyping.
|
47
|
+
|
48
|
+
### Request Specs
|
49
|
+
|
50
|
+
```bash
|
51
|
+
textualize request_specs
|
52
|
+
```
|
53
|
+
|
54
|
+
The ``textualize request_specs`` command creates a folder of request specs
|
55
|
+
written in [airborne](https://github.com/brooklynDev/airborne) that can be used
|
56
|
+
writing ruby apps with Rack. It is recommended that tests are run in isolation
|
57
|
+
while developing, and as a suite in continuous integration.
|
58
|
+
|
59
|
+
## Development
|
60
|
+
|
61
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
62
|
+
`bin/console` for an interactive prompt that will allow you to experiment.
|
63
|
+
|
64
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
65
|
+
release a new version, update the version number in `version.rb`, and then run
|
66
|
+
`bundle exec rake release` to create a git tag for the version, push git
|
67
|
+
commits and tags, and push the `.gem` file to
|
68
|
+
[rubygems.org](https://rubygems.org).
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
|
72
|
+
1. Fork it ( https://github.com/[my-github-username]/textualize/fork )
|
73
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
74
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
75
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
76
|
+
5. Create a new Pull Request
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "textualize"
|
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
|
data/bin/setup
ADDED
data/bin/textualize
ADDED
data/circle.yml
ADDED
data/lib/textualize.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
Dir["#{__dir__}/**/*.rb"].each { |file| require file }
|
2
|
+
|
3
|
+
module Textualize
|
4
|
+
class Textualize < Thor
|
5
|
+
register(
|
6
|
+
::Textualize::New,
|
7
|
+
'new',
|
8
|
+
'new',
|
9
|
+
'create a new documentation project'
|
10
|
+
)
|
11
|
+
|
12
|
+
register(
|
13
|
+
::Textualize::Server,
|
14
|
+
'server',
|
15
|
+
'server',
|
16
|
+
'create a folder structure of json responses'
|
17
|
+
)
|
18
|
+
|
19
|
+
register(
|
20
|
+
::Textualize::HttpBackend,
|
21
|
+
'http_backend',
|
22
|
+
'http_backend',
|
23
|
+
'create an Angular 1.x module for stubbing backend responses'
|
24
|
+
)
|
25
|
+
|
26
|
+
register(
|
27
|
+
::Textualize::RequestSpecs,
|
28
|
+
'request_specs',
|
29
|
+
'request_specs',
|
30
|
+
'create requset specs using airborne'
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'attr_extras'
|
2
|
+
require 'hashie'
|
3
|
+
|
4
|
+
module Textualize
|
5
|
+
class RouteHashCreator
|
6
|
+
|
7
|
+
pattr_initialize :json_from_gulp_task
|
8
|
+
|
9
|
+
def create_route_hashes
|
10
|
+
json_from_gulp_task.fetch('resources').flat_map do |resource|
|
11
|
+
create_method_hashes(resource)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def create_method_hashes(resource, relativeUri=nil)
|
18
|
+
relative_path = if relativeUri
|
19
|
+
relativeUri + resource.fetch('relativeUri')
|
20
|
+
else
|
21
|
+
resource.fetch('relativeUri')
|
22
|
+
end
|
23
|
+
|
24
|
+
method_hashes = []
|
25
|
+
method_hashes += resource.fetch('methods').map do |method|
|
26
|
+
method_hash = Hashie::Mash.new
|
27
|
+
method_hash.verb = method.fetch('method')
|
28
|
+
method_hash.url = base_path + relative_path
|
29
|
+
method_hash.relative_path = relative_path
|
30
|
+
method_hash.type = resource.fetch('type').keys.first
|
31
|
+
method_hash.secured_by = method.fetch('securedBy').first.
|
32
|
+
fetch('oauth_2_0').fetch('scopes')
|
33
|
+
method_hash.name = relative_path.split('/').last.gsub(
|
34
|
+
/{|}|_id/, ''
|
35
|
+
)
|
36
|
+
method_hash.merge!(transformed_response(method))
|
37
|
+
end
|
38
|
+
|
39
|
+
if resource.has_key? 'resources'
|
40
|
+
resource.fetch('resources').each do |nested_resource|
|
41
|
+
method_hashes += create_method_hashes(nested_resource, relative_path)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
return method_hashes
|
46
|
+
end
|
47
|
+
|
48
|
+
def base_path
|
49
|
+
URI(json_from_gulp_task.fetch('baseUri')).path
|
50
|
+
end
|
51
|
+
|
52
|
+
def transformed_response(method_hash)
|
53
|
+
response = method_hash.fetch('responses')
|
54
|
+
|
55
|
+
case response.keys.first
|
56
|
+
when '200' then ::Textualize::TwoHundred.new(response).transform
|
57
|
+
when '204' then ::Textualize::TwoHundredFour.new(response).transform
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Textualize
|
2
|
+
class RouteHashes
|
3
|
+
class << self
|
4
|
+
def hashes
|
5
|
+
fail 'run gulp first' if raml_json_files.empty?
|
6
|
+
|
7
|
+
raml_json_files.flat_map do |json_file|
|
8
|
+
json = JSON.parse(File.read(json_file))
|
9
|
+
|
10
|
+
RouteHashCreator.new(json).create_route_hashes
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def raml_json_files
|
17
|
+
Dir.glob('.tmp/apis/*.json')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'attr_extras'
|
2
|
+
|
3
|
+
module Textualize
|
4
|
+
class TwoHundred
|
5
|
+
|
6
|
+
pattr_initialize :response
|
7
|
+
|
8
|
+
def transform
|
9
|
+
transformed_hash = {}
|
10
|
+
|
11
|
+
transformed_hash[:response_code] = response.keys.first.to_i
|
12
|
+
|
13
|
+
transformed_hash[:body] = fetch_example
|
14
|
+
|
15
|
+
return transformed_hash
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def fetch_example
|
21
|
+
string_body = response.
|
22
|
+
fetch('200').
|
23
|
+
fetch('body').
|
24
|
+
fetch('application/json').
|
25
|
+
fetch('example')
|
26
|
+
|
27
|
+
JSON.parse(string_body)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'attr_extras'
|
2
|
+
|
3
|
+
module Textualize
|
4
|
+
class TwoHundredFour
|
5
|
+
|
6
|
+
pattr_initialize :response
|
7
|
+
|
8
|
+
def transform
|
9
|
+
transformed_hash = {}
|
10
|
+
|
11
|
+
transformed_hash[:response_code] = response.keys.first.to_s.to_i
|
12
|
+
|
13
|
+
return transformed_hash
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'uglifier'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
module Textualize
|
5
|
+
class HttpBackend < Thor::Group
|
6
|
+
include Thor::Actions
|
7
|
+
|
8
|
+
desc(
|
9
|
+
'Creates an angular 1.x module based off ngMockE2E that stubs a backend'
|
10
|
+
)
|
11
|
+
|
12
|
+
def create_angular_module
|
13
|
+
create_basic_http_backend_file
|
14
|
+
|
15
|
+
append_uglified_hashes
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def create_basic_http_backend_file
|
21
|
+
File.open(dist_file, 'w') do |file|
|
22
|
+
file.write(
|
23
|
+
Uglifier.compile(
|
24
|
+
File.read("#{template_directory}/module.js")
|
25
|
+
)
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def dist_file
|
31
|
+
FileUtils.mkdir_p('dist/angular/backend')
|
32
|
+
|
33
|
+
'dist/angular/backend/fake_http_backend.min.js'
|
34
|
+
end
|
35
|
+
|
36
|
+
def http_backend_template(route_hash)
|
37
|
+
ERB.new(
|
38
|
+
File.read("#{template_directory}/#{route_hash.verb}.js.erb")
|
39
|
+
).result(route_hash.instance_eval { binding })
|
40
|
+
end
|
41
|
+
|
42
|
+
def template_directory
|
43
|
+
path = File.join(__dir__, '..', 'templates/http_backend')
|
44
|
+
File.expand_path(path)
|
45
|
+
end
|
46
|
+
|
47
|
+
def append_uglified_hashes
|
48
|
+
RouteHashes.hashes.each do |route_hash|
|
49
|
+
File.open(dist_file, 'a') do |file|
|
50
|
+
file.write(
|
51
|
+
Uglifier.compile(
|
52
|
+
http_backend_template(route_hash)
|
53
|
+
)
|
54
|
+
)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Textualize
|
2
|
+
class New < Thor::Group
|
3
|
+
include Thor::Actions
|
4
|
+
|
5
|
+
argument :app_name, desc: 'Name for your documentation folder'
|
6
|
+
desc('Creates an initial folder structure for writing documentation')
|
7
|
+
|
8
|
+
def self.source_root
|
9
|
+
__dir__.chomp('/tasks')
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_application_directory
|
13
|
+
directory "#{lib_directory}/templates/new/", app_name
|
14
|
+
end
|
15
|
+
|
16
|
+
def installation_complete
|
17
|
+
puts <<-POST_INSTALL_MESSAGE
|
18
|
+
♪┏(°.°)┛┗(°.°)┓┗(°.°)┛┏(°.°)┓┏(°.°)┛┗(°.°)┓┗(°.°)┛┏(°.°)┓♪
|
19
|
+
|
20
|
+
Thank you for installing textualize, please finish setting up your
|
21
|
+
project with: `cd #{app_name} && npm install`
|
22
|
+
|
23
|
+
In your new folder you can now use the following commands:
|
24
|
+
|
25
|
+
* textualize server
|
26
|
+
* textualize request_specs
|
27
|
+
* textualize seeds
|
28
|
+
* textualize factories
|
29
|
+
|
30
|
+
Each command depends on gulp being installed. Please install gulp globally with
|
31
|
+
``npm install -g gulp`` and locally with ``npm install``.
|
32
|
+
|
33
|
+
♪┏(°.°)┛┗(°.°)┓┗(°.°)┛┏(°.°)┓┏(°.°)┛┗(°.°)┓┗(°.°)┛┏(°.°)┓♪
|
34
|
+
POST_INSTALL_MESSAGE
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def lib_directory
|
40
|
+
__dir__.chomp('/tasks')
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|