jekyll-json 0.0.1
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 +7 -0
- data/lib/jekyll-json.rb +50 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 58356d3ccd2a4dda18e9c2d962d08ef20851233d
|
4
|
+
data.tar.gz: cb9a78d9bc3419a6667c0c53320dffeec827f771
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7504962c179099891c6dfca5b0d411a384828c8562ecdfbaa94161dabdf2418b151b8d145a809f0cd8af2324551dde14340d4ac7a8d4fb75475a4907da194df9
|
7
|
+
data.tar.gz: 7ccf488e81b269609e4bbb0a541eead476e01cedbd798024f0ffc5bc17dc0419cb3c1fd0eb7b92fcef478fa6e33be68e55592c8323f2fcf113455ea67eab3dd1
|
data/lib/jekyll-json.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'csv'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
module Jekyll
|
8
|
+
|
9
|
+
class ConvertYamlToCsvJson < Generator
|
10
|
+
|
11
|
+
safe true
|
12
|
+
|
13
|
+
def generate(site)
|
14
|
+
files_to_generate = YAML.load_file(File.join(site.source, '_config.yml'))
|
15
|
+
files_to_generate['serve-json-csv'].each do |options|
|
16
|
+
yml_file = YAML.load_file(File.join(site.source, options['origin']))
|
17
|
+
headers = options['headers']
|
18
|
+
path_to_destination = File.join(site.source, options['destination'] + '/index')
|
19
|
+
if options['csv'] == true
|
20
|
+
convert_yaml_to_csv(yml_file, path_to_destination, headers)
|
21
|
+
end
|
22
|
+
if options['json'] == true
|
23
|
+
convert_yaml_to_json(yml_file, path_to_destination, headers, options['filter-json'])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def convert_yaml_to_csv(yml_file, path_to_destination, headers)
|
29
|
+
CSV.open(path_to_destination + '.csv', "wb") do |csv|
|
30
|
+
csv << headers
|
31
|
+
yml_file.each do |data|
|
32
|
+
row = []
|
33
|
+
headers.each { |header| data[header] ? row << data[header] : row << nil }
|
34
|
+
csv << row
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def convert_yaml_to_json(yml_file, path_to_destination, headers, filter_options )
|
40
|
+
File.open(path_to_destination + '.json', 'wb') do |json|
|
41
|
+
if filter_options == true
|
42
|
+
yml_file = yml_file.collect do |entry|
|
43
|
+
entry.select{ |key, value| headers.include? key }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
json << JSON.dump(yml_file)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-json
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Patterson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-03 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: serve json and csv files on jekyll
|
14
|
+
email: ben@benpatterson.io
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/jekyll-json.rb
|
20
|
+
homepage: https://github.com/BenRuns/jekyll-json
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.4.3
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: serve json and csv files on jekyll
|
44
|
+
test_files: []
|