hyde-decap 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 119633369fb206009d1dd12a167aef53e238e673ed5626d1d60004a251e961d7
4
+ data.tar.gz: 9e51474833f9230f55a3fbb36cbfe1aebe4e6a81ace1741cb4aa07e70c147e71
5
+ SHA512:
6
+ metadata.gz: 416b16fa1aa019a5208dffe2d275f9fb9d167a0bf6307d176cd4a2a492681fcbb8902af9a9c084e2d8c14ab8a83a61467e8241fd104554eb3e5ed080f2da65ae
7
+ data.tar.gz: a93e38465858b70ba3c323e1606d55f495a5968fc6db61ade28223311b0904c13a3c883459643841aa61b264bffc3f61630060b4f03aa53f9c6042bbe9b43f98
@@ -0,0 +1,33 @@
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
@@ -0,0 +1,179 @@
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
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <meta charset="utf-8" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
7
+ <meta name="robots" content="noindex" />
8
+ <title>Content Manager</title>
9
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/hithismani/responsive-decap@main/dist/responsive.min.css">
10
+ </head>
11
+
12
+ <body>
13
+ <!-- Include the script that builds the page and powers Decap CMS -->
14
+ <script src="https://unpkg.com/decap-cms@^3.0.0/dist/decap-cms.js"></script>
15
+ </body>
16
+ </html>
data/lib/hyde_decap.rb ADDED
@@ -0,0 +1,8 @@
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
+
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hyde-decap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gregory Daynes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-12-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '4.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ description: Hyde Decap is a plugin for Jekyll to add Decap CMS.
34
+ email: email@gregdaynes.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
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
43
+ homepage: https://github.com/gregdaynes/hyde-decap
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubygems_version: 3.4.10
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: Plugin for jekyll to add Decap CMS
66
+ test_files: []