ssg 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +19 -0
  3. data/README.md +12 -0
  4. data/bin/ssg +126 -0
  5. data/ssg.gemspec +21 -0
  6. metadata +61 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 33617eb734e7582ca68bd3600a183353423e22e3b52bbdbabe5181421872106f
4
+ data.tar.gz: 07106771f16b62f591bf2e3397369026e67235c046b9b78240d417497acc5aa3
5
+ SHA512:
6
+ metadata.gz: 255672150e5794c556e15a31331ef53f3f9fac6711de935199a2b6892a0574d0e2e83ac5f2d84d136823e39f96ea635462c030e913ee63bd5201d57df5078a42
7
+ data.tar.gz: 61c859eb3f49d231607e24258e84f6ea26672d35454b93a99922868c5f298ddcb1d60fa26df6cc70fb35d19669498037c1fba21863731d298a3a96ca4431b3de
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2019 Martin Manelli
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,12 @@
1
+ # ssg
2
+ ### A simple static site generator
3
+
4
+ # Installation
5
+ ```bash
6
+ gem install ssg
7
+ ```
8
+
9
+ # Usage
10
+ ```basg
11
+ ssg -h
12
+ ```
data/bin/ssg ADDED
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ STDERR.sync = true
4
+
5
+ require 'commonmarker'
6
+ require 'erb'
7
+ require 'fileutils'
8
+ require 'optparse'
9
+ require 'ostruct'
10
+ require 'yaml'
11
+
12
+ options = OpenStruct.new(src_dir: '.', dst_dir: '.')
13
+
14
+ EXAMPLE = <<-EXAMPLE.freeze
15
+
16
+
17
+ Example files:
18
+
19
+ site.yaml
20
+ -----------
21
+
22
+ layout:
23
+ title: My Blog
24
+ date: 01-01-1970
25
+
26
+ entries:
27
+ post1:
28
+ markdown: post1.md
29
+
30
+ date: 05-04-2019
31
+
32
+
33
+
34
+ layout.erb
35
+ ----------
36
+
37
+ <!doctype html>
38
+ <html>
39
+ <head>
40
+ <meta charset="utf-8"/>
41
+ <title><%= title %></title>
42
+ </head>
43
+ <body>
44
+ <%= markdown %>
45
+ </body>
46
+ <footer>
47
+ <p>Posted on: <%= date %></p>
48
+ </footer>
49
+ </html>
50
+
51
+
52
+
53
+ post1.md
54
+ --------
55
+
56
+ # Post title
57
+
58
+ ## Some code
59
+ ```ruby
60
+ puts 'Hello world!'
61
+ ```
62
+ EXAMPLE
63
+
64
+ ARGV.options do |opts|
65
+ opts.on(
66
+ '-i',
67
+ '--input-dir=INPUT_DIR',
68
+ 'Directory with site.yaml and layout.erb files'
69
+ ) do |val|
70
+ options.src_dir = val
71
+ end
72
+
73
+ opts.on(
74
+ '-o',
75
+ '--output-dir=OUTPUT_DIR',
76
+ 'Directory where site will be generated (if not exists, it will be created)'
77
+ ) do |val|
78
+ options.dst_dir = val
79
+ end
80
+
81
+ opts.on('-h', '--help', 'Prints this help') do
82
+ puts opts
83
+ puts EXAMPLE
84
+ exit
85
+ end
86
+
87
+ opts.parse!
88
+ end
89
+
90
+ Dir.chdir(options.src_dir)
91
+
92
+ SITE_PATH = './site.yaml'.freeze
93
+ LAYOUT_PATH = './layout.erb'.freeze
94
+
95
+ abort("#{SITE_PATH} not found") unless File.file? SITE_PATH
96
+ abort("#{LAYOUT_PATH} not found") unless File.file? LAYOUT_PATH
97
+
98
+ site = YAML.load_file(SITE_PATH)
99
+ template = File.read(LAYOUT_PATH)
100
+
101
+ layout = site.fetch('layout', {})
102
+ entries = site.fetch('entries', {})
103
+ abort('No entries on site.yaml') if entries.empty?
104
+
105
+ def markdown_to_html(file)
106
+ CommonMarker.render_html(File.read(file), :DEFAULT)
107
+ end
108
+
109
+ def erb(template, vars)
110
+ ERB.new(template).result(OpenStruct.new(vars).instance_eval { binding })
111
+ end
112
+
113
+ compiled_entries = entries.map do |id, tags|
114
+ entry = layout.merge(tags)
115
+ entry['markdown'] = markdown_to_html(tags['markdown'])
116
+
117
+ { id: id, html: erb(template, entry) }
118
+ end
119
+
120
+ FileUtils.mkdir_p(options.dst_dir) unless File.directory?(options.dst_dir)
121
+
122
+ Dir.chdir(options.dst_dir)
123
+
124
+ compiled_entries.each do |entry|
125
+ File.write("./#{entry[:id]}.html", entry[:html])
126
+ end
@@ -0,0 +1,21 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'ssg'
3
+ s.version = '0.0.1'
4
+ s.summary = 'Simple site generator'
5
+ s.description = 'ssg is a simple static site generator'
6
+ s.author = 'Martin Manelli'
7
+ s.email = 'manelli.ml@gmail.com'
8
+ s.homepage = 'http://github.com/manelli/ssg'
9
+ s.license = 'MIT'
10
+
11
+ s.files = Dir[
12
+ 'LICENSE',
13
+ 'README.md',
14
+ 'bin/ssg',
15
+ 'ssg.gemspec'
16
+ ]
17
+
18
+ s.add_dependency 'commonmarker', '~> 0.19'
19
+
20
+ s.executables = ['ssg']
21
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ssg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Martin Manelli
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-04-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: commonmarker
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.19'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.19'
27
+ description: ssg is a simple static site generator
28
+ email: manelli.ml@gmail.com
29
+ executables:
30
+ - ssg
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE
35
+ - README.md
36
+ - bin/ssg
37
+ - ssg.gemspec
38
+ homepage: http://github.com/manelli/ssg
39
+ licenses:
40
+ - MIT
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubygems_version: 3.0.3
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Simple site generator
61
+ test_files: []