jekyll-ramler 0.0.1 → 0.0.2

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: dc0e1f14109050ea1f296cc5ed5b3fb1ac100510
4
- data.tar.gz: fdf5cee7e082ea0397f460233683b1b13aa5e034
3
+ metadata.gz: 0b51a16a272803f10915253d041eadd53213f8d4
4
+ data.tar.gz: eb6626d0d68f77c7faa78041428214d419a2e664
5
5
  SHA512:
6
- metadata.gz: 54959f41e90effd0ab0af92512cc49780771e6bfb5cf204e5b725f81d24f70834396eff93c9f384ee49738cfd689eb0a34959e986ef36a6a6809476d36aa9a43
7
- data.tar.gz: 4fe17f77d424cba1df92d33ce9ecb08d31179f25dfcdb03e3443f7aac569021897e50b7ce21c7d5783de3e54fad03dd7cdac006a076591eed616312faadfd87e
6
+ metadata.gz: d9c0d5900dc16eadbfe0119fca2a96b125835506d031fec593bcd8b1679be9b49f9f5dbd4771526d0571c7bd3a41febe782c43c04b32a5e4509cf96debd13048
7
+ data.tar.gz: b445707349317d6923584813ff834a430ea55d48c17106bc489515a9dad8063aadec4970a33eb8679299d30fa589bcd255e489d217f6023087c932a9a24660f9
data/.travis.yml CHANGED
@@ -7,3 +7,6 @@ install:
7
7
  - npm install raml-cop
8
8
  - bundle install
9
9
  script: "bundle exec rspec"
10
+ branches:
11
+ only:
12
+ - master
data/Gemfile CHANGED
@@ -6,5 +6,6 @@ group :test, :development do
6
6
  gem 'fakefs', require: 'fakefs/safe'
7
7
  gem 'pry'
8
8
  gem 'rspec'
9
+ gem 'rspec-mocks'
9
10
  gem 'ruby_deep_clone'
10
11
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jekyll-ramler (0.0.1)
4
+ jekyll-ramler (0.0.2)
5
5
  jekyll
6
6
 
7
7
  GEM
@@ -100,4 +100,5 @@ DEPENDENCIES
100
100
  jekyll-ramler!
101
101
  pry
102
102
  rspec
103
+ rspec-mocks
103
104
  ruby_deep_clone
data/README.md CHANGED
@@ -17,6 +17,83 @@ Node.js script, to actually parse a RAML file. Thus, you will need to install
17
17
  [Node.js](http://nodejs.org/), then perform `npm install raml-cop`.
18
18
 
19
19
 
20
+ ## Configuration
21
+
22
+ Several options can be defined by your project's _config.yml:
23
+
24
+ - **ramler_api_paths**
25
+
26
+ A nested mapping of the files that jekyll-ramler should read while generating
27
+ content and the web folders where that content should be placed. *Keys* are
28
+ the file system paths (relative to your project's root directory) of the
29
+ files to be read. *Values* are the web paths (relative to web root) to place
30
+ all content generated based on the read file into. Keys must end with a
31
+ forward slash. If no value is provided, web root (/) is used.
32
+
33
+ Behavior is undefined for cases in which jekyll-ramler is configured to
34
+ output generated content of multiple source files to the same web path.
35
+
36
+ If *ramler_api_paths* is not defined, jekyll-ramler will default to reading
37
+ `api.json` from your project's root and placing generated files into web
38
+ root.
39
+
40
+ At this time, only JSON representations of RAML can be read.
41
+
42
+ Example:
43
+
44
+ ```
45
+ ramler_api_paths:
46
+ ramls/api_v1.json: /an_api/v1/
47
+ ramls/api_v2.json: /an_api/v2/
48
+ ramls/api_v3.json: /an_api/
49
+ ramls/api_v3.json: /an_api/v3/
50
+ experimental/foo.json: /unstable/
51
+ ramls/popular.json: /
52
+ ```
53
+
54
+ - **ramler_generated_sub_dirs**
55
+
56
+ A nested map defining the web sub directories that jekyll-ramler will place
57
+ generated pages into. Can have three mappings:
58
+
59
+ - *resource* - web sub directory for resource pages. Defaults to `resource`.
60
+ - *overview* - web sub directory for overview pages. Defaults to `overview`.
61
+ - *security* - web sub directory for security pages. Defaults to `security`.
62
+
63
+ Example:
64
+
65
+ ```
66
+ ramler_generated_sub_dirs:
67
+ resource: resources_pages
68
+ overview: general_documentation
69
+ security: security_information
70
+ ```
71
+
72
+ The same value can be used in multiple mappings. For example, all three
73
+ mappings could be set to `documentation`.
74
+
75
+ - **ramler_downloadable_descriptor_basenames**
76
+
77
+ A nested map defining the basename of the generated, downloadable descriptors
78
+ (RAML and JSON). Format is similar to `ramler_api_paths`, where the *keys*
79
+ are file system paths of files to be read, while *values* are the basenames
80
+ to use for generated descriptors. For example:
81
+
82
+ ```
83
+ ramler_downloadable_descriptor_basenames:
84
+ ramls/api_v1.json: api_v1
85
+ experimental/foo.json: unstable
86
+ ```
87
+
88
+ will lead to the creation of `api_v1.raml`, `api_v1.json`, `unstable.raml`,
89
+ and `unstable.json` downloadable files.
90
+
91
+ If a basename is not defined, `api` is used as a basename.
92
+
93
+ Generated descriptor files will be placed in the web folder configured for a
94
+ given source file.
95
+
96
+
20
97
  ## JSON Schema Support
21
98
 
22
99
  jekyll-ramler includes a few features for JSON Schema.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jekyll-ramler'
3
- s.version = '0.0.1'
3
+ s.version = '0.0.2'
4
4
  s.date = '2015-02-09'
5
5
  s.authors = ['GovDelivery']
6
6
  s.email = 'support@govdelivery.com'
data/lib/raml-generate.rb CHANGED
@@ -17,10 +17,11 @@ module Jekyll
17
17
  end
18
18
 
19
19
  class GeneratedPage<Page
20
- def initialize(site, base, dir, item, layout=nil)
20
+ def initialize(site, base, web_root, dir, item, layout=nil)
21
21
  @site = site
22
22
  @base = base
23
23
  @dir = dir.gsub(/{(\w*)}/, '--\1--').gsub(/\s/, '_')
24
+ @dir = File.join(web_root, @dir)
24
25
  @name = 'index.html'
25
26
 
26
27
  layout = get_layout(dir) if layout.nil?
@@ -57,14 +58,14 @@ module Jekyll
57
58
  end
58
59
 
59
60
  class SecuritySchemePage<GeneratedPage
60
- def initialize(site, base, dir, securityScheme)
61
- super(site, base, dir, securityScheme, layout=get_layout('resource', site))
61
+ def initialize(site, base, web_root, dir, securityScheme)
62
+ super(site, base, web_root, dir, securityScheme, layout=get_layout('resource', site))
62
63
  end
63
64
  end
64
65
 
65
66
  class DocumentationPage<GeneratedPage
66
- def initialize(site, base, dir, documentation)
67
- super(site, base, dir, documentation)
67
+ def initialize(site, base, web_root, dir, documentation)
68
+ super(site, base, web_root, dir, documentation)
68
69
 
69
70
  output = documentation['content']
70
71
  self.data['body'] = transform_md(output)
@@ -72,13 +73,13 @@ module Jekyll
72
73
  end
73
74
 
74
75
  class ResourcePage<GeneratedPage
75
- def initialize(site, base, dir, resource, traits, securitySchemes)
76
+ def initialize(site, base, web_root, dir, resource, traits, securitySchemes)
76
77
  # Sandbox our resource, and do nothing with child resources
77
78
  resource = resource.dup
78
79
  resource.delete('resources')
79
80
 
80
81
  resource['title'] = dir.sub('resource', '') if not resource.include?('title')
81
- super(site, base, dir, resource)
82
+ super(site, base, web_root, dir, resource)
82
83
 
83
84
  # Add security data to the resource
84
85
  resource.fetch('methods', []).each do |method|
@@ -196,8 +197,16 @@ module Jekyll
196
197
  def generate(site)
197
198
  @site = site
198
199
 
199
- raml_js_path = site.config.fetch('raml_json_file_path', 'api.json')
200
- raml_js = File.open(raml_js_path).read
200
+ site.config.fetch('ramler_api_paths', {'api.json' => '/'}).each do |file_path, web_root|
201
+ web_root = '/' if web_root.nil? or web_root.empty?
202
+ raise 'raml_api_paths web paths must end with "/"' if web_root[-1] != '/'
203
+ generate_api_pages(file_path, web_root)
204
+ end
205
+ end
206
+
207
+ def generate_api_pages(raml_path, web_root)
208
+ @web_root = web_root
209
+ raml_js = File.open(raml_path).read
201
210
  raml_hash = JSON.parse(raml_js)
202
211
 
203
212
  # BETTER THE DATASTRUCTURES!
@@ -221,26 +230,30 @@ module Jekyll
221
230
  generate_resource_pages(raml_hash['resources'])
222
231
  end
223
232
 
224
- dir = Jekyll::get_dir('overview', @site.config)
233
+ dir = Jekyll::get_dir('security', @site.config)
225
234
  @securitySchemes.each do |scheme_name, scheme|
226
235
  scheme_dir = File.join(dir, scheme_name)
227
236
  scheme['title'] = scheme_name
228
- @site.pages << SecuritySchemePage.new(@site, @site.source, scheme_dir, scheme)
237
+ @site.pages << SecuritySchemePage.new(@site, @site.source, @web_root, scheme_dir, scheme)
229
238
  end
230
239
 
240
+ dir = Jekyll::get_dir('overview', @site.config)
231
241
  raml_hash.fetch('documentation', []).each do |documentation|
232
242
  documentation_dir = File.join(dir, documentation['title'])
233
- @site.pages << DocumentationPage.new(@site, @site.source, documentation_dir, documentation)
243
+ @site.pages << DocumentationPage.new(@site, @site.source, @web_root, documentation_dir, documentation)
234
244
  end
235
245
 
236
- # Allow users to download the RAML, which may be modified since it was read
237
- raml_download_path = site.config.fetch('raml_download_path', 'api.raml').split('/')
238
- raml_download_filename = raml_download_path.delete_at(-1)
239
- raml_download_path = raml_download_path.join('/') + '/'
246
+ # Allow users to download descriptor as RAML and JSON, which may be modified since it was read
247
+ download_basename = @site.config.fetch('ramler_downloadable_descriptor_basenames', {}).fetch(raml_path, 'api')
248
+ raml_download_filename = download_basename + '.raml'
249
+ json_download_filename = download_basename + '.json'
240
250
 
241
251
  raml_yaml = raml_hash.to_yaml
242
252
  raml_yaml.sub!('---', '#%RAML 0.8')
243
- @site.static_files << RawFile.new(@site, @site.source, raml_download_path, raml_download_filename, raml_yaml)
253
+ @site.static_files << RawFile.new(@site, @site.source, @web_root, raml_download_filename, raml_yaml)
254
+
255
+ raml_json = JSON.pretty_generate(raml_hash)
256
+ @site.static_files << RawFile.new(@site, @site.source, @web_root, json_download_filename, raml_json)
244
257
  end
245
258
 
246
259
  private
@@ -255,7 +268,7 @@ module Jekyll
255
268
  resources.each do |resource|
256
269
  resource_name = resource["relativeUri"]
257
270
  resource_dir = File.join(dir, resource_name)
258
- @site.pages << ResourcePage.new(@site, @site.source, resource_dir, resource, @traits, @securitySchemes)
271
+ @site.pages << ResourcePage.new(@site, @site.source, @web_root, resource_dir, resource, @traits, @securitySchemes)
259
272
  if resource.has_key?('resources')
260
273
  generate_resource_pages(resource['resources'], resource_dir)
261
274
  end
data/lib/utils.rb CHANGED
@@ -2,7 +2,7 @@ require 'json'
2
2
 
3
3
  module Jekyll
4
4
  def self.get_dir(page_type, config)
5
- config.fetch('page_dirs', {}).fetch(page_type, page_type)
5
+ config.fetch('ramler_generated_sub_dirs', {}).fetch(page_type, page_type)
6
6
  end
7
7
 
8
8
  def self.sanatize_json_string(s)
@@ -0,0 +1,145 @@
1
+ require_relative './spec_helper.rb'
2
+
3
+ describe 'ReferencePageGenerator', fakefs:true do
4
+
5
+ before(:each) do
6
+ @site = Jekyll::Site.new(Jekyll.configuration({
7
+ "skip_config_files" => true,
8
+ "json_schema_schema_uri" => "http://json-schema.org/draft-04/schema#",
9
+ "ramler_api_paths" => {
10
+ 'api.json' => '',
11
+ 'productA/api.json' => '/productA/',
12
+ 'service.json' => '/'}
13
+ }))
14
+ @rpg = Jekyll::ReferencePageGenerator.new
15
+
16
+ FakeFS.activate!
17
+ Pry.config.history.should_save = false;
18
+ Pry.config.history.should_load = false;
19
+
20
+ FileUtils.mkdir_p('_layouts')
21
+ File.open('_layouts/default.html', 'w') { |f| f << "{{ content }}" }
22
+
23
+ File.open('api.json', 'w') do |f|
24
+ f << JSON.pretty_generate(load_simple_raml)
25
+ end
26
+
27
+ FileUtils.mkdir_p('productA')
28
+ File.open('productA/api.json', 'w') do |f|
29
+ f << JSON.pretty_generate(load_simple_raml)
30
+ end
31
+
32
+ File.open('service.json', 'w') do |f|
33
+ f << JSON.pretty_generate(load_simple_raml)
34
+ end
35
+ end
36
+
37
+ after(:each) do
38
+ FakeFS.deactivate!
39
+ end
40
+
41
+ context 'Configuration' do
42
+
43
+ it 'reads "api.json" if no ramler_api_paths is provided' do
44
+ @site.config.delete('ramler_api_paths')
45
+ expect(File).to receive(:open).with('api.json').and_return(StringIO.new(JSON.pretty_generate(load_simple_raml)))
46
+ @rpg.generate(@site)
47
+ end
48
+
49
+ it 'reads ramls listed in the ramler_api_paths configuration mapping' do
50
+ expect(File).to receive(:open).with('api.json').and_return(StringIO.new(JSON.pretty_generate(load_simple_raml)))
51
+ expect(File).to receive(:open).with('productA/api.json').and_return(StringIO.new(JSON.pretty_generate(load_simple_raml)))
52
+ expect(File).to receive(:open).with('service.json').and_return(StringIO.new(JSON.pretty_generate(load_simple_raml)))
53
+ @rpg.generate(@site)
54
+ end
55
+
56
+ it 'places generated content into folders based on the ramler_api_paths configuration mapping' do
57
+ # Relying on some default values in this test
58
+
59
+ @site.config['ramler_api_paths'].delete('api.json')
60
+ @rpg.generate(@site)
61
+ @site.process
62
+
63
+ # Look for files generated from service.json
64
+ expect(File.file?('_site/api.raml')).to be true
65
+ expect(File.directory?('_site/resource')).to be true
66
+
67
+ # Look for files generated from
68
+ expect(File.directory?('_site/productA')).to be true
69
+ expect(File.file?('_site/productA/api.raml')).to be true
70
+ expect(File.directory?('_site/productA/resource')).to be true
71
+ end
72
+
73
+ it 'defaults to web root for any unconfigured ramls' do
74
+ # Only generate content for api.json, which does not define a web root
75
+ @site.config['ramler_api_paths'].delete('/productA/api.json')
76
+ @site.config['ramler_api_paths'].delete('service.json')
77
+ @rpg.generate(@site)
78
+ @site.process
79
+
80
+ expect(File.file?('_site/api.raml')).to be true
81
+ expect(File.directory?('_site/resource')).to be true
82
+ end
83
+
84
+ it 'throws an error if ramler_api_paths includes a value without a trailing slash' do
85
+ @site.config['ramler_api_paths'].delete('/productA/api.json')
86
+ @site.config['ramler_api_paths'].delete('service.json')
87
+ @site.config['ramler_api_paths']['api.json'] = 'api/v1'
88
+ expect {@rpg.generate(@site)}.to raise_error
89
+ end
90
+
91
+ it 'defaults to "resource", "overview", and "security" for generated folders' do
92
+ @site.config['ramler_api_paths'].delete('/productA/api.json')
93
+ @site.config['ramler_api_paths'].delete('service.json')
94
+ @rpg.generate(@site)
95
+ @site.process
96
+
97
+ expect(File.directory?('_site/resource')).to be true
98
+ expect(File.directory?('_site/overview')).to be true
99
+ expect(File.directory?('_site/security')).to be true
100
+ end
101
+
102
+ it 'places generated content into folders based on ramler_generated_sub_dirs configuration mapping' do
103
+ @site.config['ramler_generated_sub_dirs'] = {
104
+ 'resource' => 'endpoints',
105
+ 'overview' => 'info',
106
+ 'security' => 'auth'
107
+ }
108
+ @rpg.generate(@site)
109
+ @site.process
110
+
111
+ expect(File.directory?('_site/endpoints')).to be true
112
+ expect(File.directory?('_site/info')).to be true
113
+ expect(File.directory?('_site/auth')).to be true
114
+
115
+ expect(File.directory?('_site/productA/endpoints')).to be true
116
+ expect(File.directory?('_site/productA/info')).to be true
117
+ expect(File.directory?('_site/productA/auth')).to be true
118
+ end
119
+
120
+ it 'names downloadable descriptors "api.raml" and "api.json" by default' do
121
+ @site.config['ramler_api_paths'].delete('service.json')
122
+ @rpg.generate(@site)
123
+ @site.process
124
+
125
+ expect(File.file?('_site/api.json')).to be true
126
+ expect(File.file?('_site/api.raml')).to be true
127
+ expect(File.file?('_site/productA/api.json')).to be true
128
+ expect(File.file?('_site/productA/api.raml')).to be true
129
+ end
130
+
131
+ it 'names downloadable descriptors based on ramler_downloadable_descriptor_basenames' do
132
+ @site.config['ramler_api_paths'].delete('service.json')
133
+ @site.config['ramler_downloadable_descriptor_basenames'] = {
134
+ 'productA/api.json' => 'productA_api'
135
+ }
136
+ @rpg.generate(@site)
137
+ @site.process
138
+
139
+ expect(File.file?('_site/api.json')).to be true
140
+ expect(File.file?('_site/api.raml')).to be true
141
+ expect(File.file?('_site/productA/productA_api.json')).to be true
142
+ expect(File.file?('_site/productA/productA_api.raml')).to be true
143
+ end
144
+ end
145
+ end
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,7 @@ require 'fakefs/spec_helpers'
3
3
  require 'jekyll'
4
4
  require 'pry'
5
5
  require 'rspec/expectations'
6
+ require 'rspec/mocks'
6
7
  require_relative '../lib/jekyll-ramler.rb'
7
8
 
8
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-ramler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - GovDelivery
@@ -40,6 +40,7 @@ files:
40
40
  - lib/jekyll-ramler.rb
41
41
  - lib/raml-generate.rb
42
42
  - lib/utils.rb
43
+ - spec/config_spec.rb
43
44
  - spec/reference_page_generator_spec.rb
44
45
  - spec/spec_assets/json/schema/allOf_schema.schema.json
45
46
  - spec/spec_assets/json/schema/foo.include.schema.json