hyde-decap 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 119633369fb206009d1dd12a167aef53e238e673ed5626d1d60004a251e961d7
4
- data.tar.gz: 9e51474833f9230f55a3fbb36cbfe1aebe4e6a81ace1741cb4aa07e70c147e71
3
+ metadata.gz: ad9137d218e78ce079ea8bc536bd127dc77c5440d2c1bb6958403542775136b9
4
+ data.tar.gz: 4b41a9e242adb9f3afcb01277d55278576f3e83ccd66c4cd06540ff59c7e29f5
5
5
  SHA512:
6
- metadata.gz: 416b16fa1aa019a5208dffe2d275f9fb9d167a0bf6307d176cd4a2a492681fcbb8902af9a9c084e2d8c14ab8a83a61467e8241fd104554eb3e5ed080f2da65ae
7
- data.tar.gz: a93e38465858b70ba3c323e1606d55f495a5968fc6db61ade28223311b0904c13a3c883459643841aa61b264bffc3f61630060b4f03aa53f9c6042bbe9b43f98
6
+ metadata.gz: 9da625c6c2331cdc0c8ebb87ad4908a5704b86214cb0bcd14fc580e13d0c3069e6853ac4c4bce478755192331dcd75150a920ed11c84506ba78f3e569d0e51a4
7
+ data.tar.gz: dfa86f78cf0777ab52294068fc1afd358c9417a872fea5b726cd8e39eef9170184a0fcae0b516b3f5e6fe608209143d50417699bd626726ae50a3f0c1217f9ed
@@ -0,0 +1,37 @@
1
+ require "jekyll"
2
+
3
+ module Hyde
4
+ module Decap
5
+ # Alternative class for jekyll's static files
6
+ # this allows the creation of files without a source file
7
+
8
+ class GeneratedFile < Jekyll::StaticFile
9
+ attr_accessor :file_contents
10
+ attr_reader :generator
11
+
12
+ def initialize(site, dir, name)
13
+ @site = site
14
+ @dir = dir
15
+ @name = name
16
+ @relative_path = File.join(*[@dir, @name].compact)
17
+ @extname = File.extname(@name)
18
+ @type = @collection&.label&.to_sym
19
+ @generator = "hyde-decap"
20
+ end
21
+
22
+ def write(dest)
23
+ dest_path = destination(dest)
24
+ return false if File.exist?(dest_path)
25
+
26
+ FileUtils.mkdir_p(File.dirname(dest_path))
27
+ FileUtils.rm(dest_path) if File.exist?(dest_path)
28
+
29
+ File.open(dest_path, "w") do |output_file|
30
+ output_file << file_contents
31
+ end
32
+
33
+ true
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,57 @@
1
+ module Hyde
2
+ module Decap
3
+ class Generator
4
+ @@config = {
5
+ "file_output_path" => "/admin",
6
+ "enable" => true,
7
+ "keep_files" => true
8
+ }
9
+
10
+ def initialize(site)
11
+ @site = site
12
+ @config = site.config.dig("hyde_decap")
13
+
14
+ @config = @@config.merge(@site.config.dig("hyde_decap") || {})
15
+
16
+ # compatibility with jekyll-sitemap
17
+ # set the admin path to ignore
18
+ @site.config["defaults"].push({
19
+ "scope" => {
20
+ "path" => "admin/index.html"
21
+ },
22
+ "values" => {
23
+ "sitemap" => false
24
+ }
25
+ })
26
+
27
+ if config("keep_files") == true
28
+ @site.config["keep_files"].push(config("file_output_path"))
29
+ end
30
+
31
+ if site.config.dig("hyde_decap").nil?
32
+ @site.config["hyde_decap"] = @config
33
+ end
34
+ end
35
+
36
+ def generate
37
+ return unless config("enable") == true
38
+
39
+ # create new index.html file
40
+ html_file = Hyde::Decap::GeneratedFile.new(@site, config("file_output_path"), "index.html")
41
+ html_file.file_contents = File.read(File.join(File.dirname(__FILE__), "index.html"))
42
+ @site.static_files << html_file
43
+
44
+ # create new config.yml file
45
+ config_file = Hyde::Decap::GeneratedFile.new(@site, config("file_output_path"), "config.yml")
46
+ config_file.file_contents = @config.to_yaml
47
+ @site.static_files << config_file
48
+ end
49
+
50
+ private
51
+
52
+ def config(*)
53
+ @config.dig(*)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,37 @@
1
+ module Hyde
2
+ # copied from http://stackoverflow.com/a/1162850/83386
3
+ # credit to [ehsanul](https://stackoverflow.com/users/127219/ehsanul)
4
+ # and [funroll](https://stackoverflow.com/users/878969/funroll)
5
+ module Decap
6
+ class Subprocess
7
+ def initialize(cmd, &block)
8
+ Open3.popen3(cmd) do |stdin, stdout, stderr, thread|
9
+ trap("INT") {
10
+ Jekyll.logger.info "Decap:", "shutting down server and Decap CMS Proxy"
11
+ thread.exit
12
+ }
13
+
14
+ # read each stream from a new thread
15
+ {out: stdout, err: stderr}.each do |key, stream|
16
+ Thread.new do
17
+ until (line = stream.gets).nil?
18
+ # yield the block depending on the stream
19
+ if key == :out
20
+ yield line, nil, thread if block
21
+ elsif block
22
+ yield nil, line, thread
23
+ end
24
+ end
25
+ rescue IOError => e
26
+ if e.message != "stream closed in another thread"
27
+ raise e
28
+ end
29
+ end
30
+ end
31
+
32
+ thread.join # don't exit until the external process is done
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hyde
4
+ module Decap
5
+ VERSION = "0.1.1"
6
+ end
7
+ end
data/lib/hyde/decap.rb ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "decap/version"
4
+ require_relative "decap/generator"
5
+ require_relative "decap/subprocess"
6
+ require_relative "decap/generated_file"
data/lib/hyde-decap.rb ADDED
@@ -0,0 +1,3 @@
1
+ require_relative "hyde/decap"
2
+ require_relative "jekyll/decap"
3
+ require_relative "jekyll/commands/decap"
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Commands
5
+ class Decap < Command
6
+ class << self
7
+ # command options should mirror from `jekyll serve`
8
+ COMMAND_OPTIONS = {
9
+ "ssl_cert" => ["--ssl-cert [CERT]", "X.509 (SSL) certificate."],
10
+ "host" => ["host", "-H", "--host [HOST]", "Host to bind to"],
11
+ "open_url" => ["-o", "--open-url", "Launch your site in a browser"],
12
+ "detach" => ["-B", "--detach",
13
+ "Run the server in the background"],
14
+ "ssl_key" => ["--ssl-key [KEY]", "X.509 (SSL) Private Key."],
15
+ "port" => ["-P", "--port [PORT]", "Port to listen on"],
16
+ "show_dir_listing" => ["--show-dir-listing",
17
+ "Show a directory listing instead of loading " \
18
+ "your index file."],
19
+ "skip_initial_build" => ["skip_initial_build", "--skip-initial-build",
20
+ "Skips the initial site build which occurs before " \
21
+ "the server is started."],
22
+ "livereload" => ["-l", "--livereload",
23
+ "Use LiveReload to automatically refresh browsers"],
24
+ "livereload_ignore" => ["--livereload-ignore ignore GLOB1[,GLOB2[,...]]",
25
+ Array,
26
+ "Files for LiveReload to ignore. " \
27
+ "Remember to quote the values so your shell " \
28
+ "won't expand them"],
29
+ "livereload_min_delay" => ["--livereload-min-delay [SECONDS]",
30
+ "Minimum reload delay"],
31
+ "livereload_max_delay" => ["--livereload-max-delay [SECONDS]",
32
+ "Maximum reload delay"],
33
+ "livereload_port" => ["--livereload-port [PORT]", Integer,
34
+ "Port for LiveReload to listen on"]
35
+ }.freeze
36
+
37
+ LIVERELOAD_PORT = 35_729
38
+ LIVERELOAD_DIR = File.join(__dir__, "serve", "livereload_assets")
39
+
40
+ def init_with_program(prog)
41
+ prog.command(:decap) do |c|
42
+ c.description "Serve your site locally while running Decap CMS"
43
+ c.syntax "decap [options]"
44
+ c.alias :decap
45
+ c.alias :d
46
+
47
+ COMMAND_OPTIONS.each do |key, val|
48
+ c.option key, *val
49
+ end
50
+
51
+ c.action do |args, options|
52
+ # need to convert options to flags
53
+ flags = options.map do |key, value|
54
+ if value == true
55
+ "--#{key}"
56
+ else
57
+ "--#{key} #{value}"
58
+ end
59
+ end
60
+
61
+ # TODO replace netlify-cms-proxy-server with decap version when released
62
+ cmd = "trap 'kill %1; kill %2; exit;' SIGINT SIGTERM;"
63
+ cmd += " jekyll serve #{flags.join(" ")} & npx netlify-cms-proxy-server"
64
+
65
+ begin
66
+ Hyde::Decap::Subprocess.new cmd do |stdout, stderr, thread|
67
+ unless stdout.nil?
68
+ stdout_filtered = stdout.inspect.gsub('"\e[32m', "").gsub('\e[39m', "").gsub('\n"', "").chomp
69
+
70
+ if stdout_filtered.start_with?("info")
71
+ Jekyll.logger.info "Decap CMS:", stdout_filtered
72
+ else
73
+ puts stdout
74
+ end
75
+ end
76
+ puts stderr unless stderr.nil?
77
+ end
78
+ rescue => e
79
+ puts e
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,7 @@
1
+ module Jekyll
2
+ class HydeDecapGenerator < Generator
3
+ def generate(site)
4
+ Hyde::Decap::Generator.new(site).generate
5
+ end
6
+ end
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyde-decap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory Daynes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-22 00:00:00.000000000 Z
11
+ date: 2023-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -36,10 +36,15 @@ executables: []
36
36
  extensions: []
37
37
  extra_rdoc_files: []
38
38
  files:
39
- - lib/hyde_decap.rb
40
- - lib/hyde_decap/generated_file.rb
41
- - lib/hyde_decap/hyde_decap.rb
42
- - lib/hyde_decap/index.html
39
+ - lib/hyde-decap.rb
40
+ - lib/hyde/decap.rb
41
+ - lib/hyde/decap/generated_file.rb
42
+ - lib/hyde/decap/generator.rb
43
+ - lib/hyde/decap/index.html
44
+ - lib/hyde/decap/subprocess.rb
45
+ - lib/hyde/decap/version.rb
46
+ - lib/jekyll/commands/decap.rb
47
+ - lib/jekyll/decap.rb
43
48
  homepage: https://github.com/gregdaynes/hyde-decap
44
49
  licenses:
45
50
  - MIT
@@ -1,33 +0,0 @@
1
- module Hyde
2
- # Alternative class for jekyll's static files
3
- # this allows the creation of files without a source file
4
-
5
- class GeneratedFile < Jekyll::StaticFile
6
- attr_accessor :file_contents
7
- attr_reader :generator
8
-
9
- def initialize(site, dir, name)
10
- @site = site
11
- @dir = dir
12
- @name = name
13
- @relative_path = File.join(*[@dir, @name].compact)
14
- @extname = File.extname(@name)
15
- @type = @collection&.label&.to_sym
16
- @generator = 'hyde_fonts'
17
- end
18
-
19
- def write(dest)
20
- dest_path = destination(dest)
21
- return false if File.exist?(dest_path)
22
-
23
- FileUtils.mkdir_p(File.dirname(dest_path))
24
- FileUtils.rm(dest_path) if File.exist?(dest_path)
25
-
26
- File.open(dest_path, 'w') do |output_file|
27
- output_file << file_contents
28
- end
29
-
30
- true
31
- end
32
- end
33
- end
@@ -1,179 +0,0 @@
1
- require 'jekyll'
2
- require 'yaml'
3
- require 'open3'
4
- require_relative 'generated_file.rb'
5
-
6
- module Jekyll
7
- class HydeDecapGenerator < Generator
8
- def generate(site)
9
- Hyde::Decap.new(site).generate()
10
- end
11
- end
12
-
13
- module Commands
14
- class Decap < Command
15
- class << self
16
- # command options should mirror from `jekyll serve`
17
- COMMAND_OPTIONS = {
18
- "ssl_cert" => ["--ssl-cert [CERT]", "X.509 (SSL) certificate."],
19
- "host" => ["host", "-H", "--host [HOST]", "Host to bind to"],
20
- "open_url" => ["-o", "--open-url", "Launch your site in a browser"],
21
- "detach" => ["-B", "--detach",
22
- "Run the server in the background",],
23
- "ssl_key" => ["--ssl-key [KEY]", "X.509 (SSL) Private Key."],
24
- "port" => ["-P", "--port [PORT]", "Port to listen on"],
25
- "show_dir_listing" => ["--show-dir-listing",
26
- "Show a directory listing instead of loading " \
27
- "your index file.",],
28
- "skip_initial_build" => ["skip_initial_build", "--skip-initial-build",
29
- "Skips the initial site build which occurs before " \
30
- "the server is started.",],
31
- "livereload" => ["-l", "--livereload",
32
- "Use LiveReload to automatically refresh browsers",],
33
- "livereload_ignore" => ["--livereload-ignore ignore GLOB1[,GLOB2[,...]]",
34
- Array,
35
- "Files for LiveReload to ignore. " \
36
- "Remember to quote the values so your shell " \
37
- "won't expand them",],
38
- "livereload_min_delay" => ["--livereload-min-delay [SECONDS]",
39
- "Minimum reload delay",],
40
- "livereload_max_delay" => ["--livereload-max-delay [SECONDS]",
41
- "Maximum reload delay",],
42
- "livereload_port" => ["--livereload-port [PORT]", Integer,
43
- "Port for LiveReload to listen on",],
44
- }.freeze
45
-
46
- LIVERELOAD_PORT = 35_729
47
- LIVERELOAD_DIR = File.join(__dir__, "serve", "livereload_assets")
48
-
49
- def init_with_program(prog)
50
- prog.command(:decap) do |c|
51
- c.description "Serve your site locally while running Decap CMS"
52
- c.syntax "decap [options]"
53
- c.alias :decap
54
- c.alias :d
55
-
56
- COMMAND_OPTIONS.each do |key, val|
57
- c.option key, *val
58
- end
59
-
60
- c.action do |args, options|
61
- # need to convert options to flags
62
- flags = options.map do |key, value|
63
- if value == true
64
- "--#{key}"
65
- else
66
- "--#{key} #{value}"
67
- end
68
- end
69
-
70
- # TODO replace netlify-cms-proxy-server with decap version when released
71
- cmd = "trap 'kill %1; kill %2; exit;' SIGINT SIGTERM;"
72
- cmd += " jekyll serve #{flags.join(' ')} & npx netlify-cms-proxy-server"
73
-
74
- begin
75
- Hyde::Utils::Subprocess.new cmd do |stdout, stderr, thread|
76
- unless stdout.nil?
77
- stdout_filtered = stdout.inspect.gsub('"\e[32m', '').gsub('\e[39m', '').gsub('\n"', '').chomp
78
-
79
- if stdout_filtered.start_with?("info")
80
- Jekyll.logger.info "Decap CMS:", stdout_filtered
81
- else
82
- puts stdout
83
- end
84
- end
85
- puts stderr unless stderr.nil?
86
- end
87
- rescue => e
88
- puts e
89
- end
90
- end
91
- end
92
- end
93
- end
94
- end
95
- end
96
- end
97
-
98
- module Hyde
99
- class Decap
100
- @@config = {
101
- "file_output_path" => 'admin',
102
- "enable" => true,
103
- "keep_files" => true
104
- }
105
-
106
- def initialize(site)
107
- @site = site
108
- @config = site.config.dig('hyde_decap')
109
-
110
- @config = @@config.merge(@site.config.dig('hyde_decap') || {})
111
-
112
- if config('keep_files') == true
113
- @site.config['keep_files'].push(config('file_output_path'))
114
- end
115
-
116
- if site.config.dig('hyde_decap').nil?
117
- @site.config['hyde_decap'] = @config
118
- end
119
- end
120
-
121
- def generate
122
- return unless config('enable') == true
123
-
124
- # create new index.html file
125
- html_file = Hyde::GeneratedFile.new(@site, config('file_output_path'), 'index.html')
126
- html_file.file_contents = File.read(File.join(File.dirname(__FILE__), 'index.html'))
127
- @site.static_files << html_file
128
-
129
- # create new config.yml file
130
- config_file = Hyde::GeneratedFile.new(@site, config('file_output_path'), 'config.yml')
131
- config_file.file_contents = @config.to_yaml
132
- @site.static_files << config_file
133
- end
134
-
135
- private
136
-
137
- def config(*keys)
138
- @config.dig(*keys)
139
- end
140
- end
141
-
142
- # copied from http://stackoverflow.com/a/1162850/83386
143
- # credit to [ehsanul](https://stackoverflow.com/users/127219/ehsanul)
144
- # and [funroll](https://stackoverflow.com/users/878969/funroll)
145
- module Utils
146
- class Subprocess
147
- def initialize(cmd, &block)
148
- Open3.popen3(cmd) do |stdin, stdout, stderr, thread|
149
- trap("INT") {
150
- Jekyll.logger.info "Decap:", "shutting down server and Decap CMS Proxy"
151
- thread.exit
152
- }
153
-
154
- # read each stream from a new thread
155
- { :out => stdout, :err => stderr }.each do |key, stream|
156
- Thread.new do
157
- begin
158
- until (line = stream.gets).nil? do
159
- # yield the block depending on the stream
160
- if key == :out
161
- yield line, nil, thread if block_given?
162
- else
163
- yield nil, line, thread if block_given?
164
- end
165
- end
166
- rescue IOError => e
167
- if e.message != 'stream closed in another thread'
168
- raise e
169
- end
170
- end
171
- end
172
- end
173
-
174
- thread.join # don't exit until the external process is done
175
- end
176
- end
177
- end
178
- end
179
- end
data/lib/hyde_decap.rb DELETED
@@ -1,8 +0,0 @@
1
- module Hyde
2
- class Decap
3
- VERSION = "0.1.0"
4
- end
5
- end
6
-
7
- require_relative './hyde_decap/hyde_decap.rb'
8
-
File without changes