synful 1.0.1 → 1.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 +4 -4
- data/bin/synful +52 -48
- data/synful.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 37beb91e8a78a71b6bdbbfb1833b664a5d2cbf8d260cfb8bfe4aa3c1366ebacf
|
|
4
|
+
data.tar.gz: eeb2fafa7499da63f9484609c624bfbcea4ef2c29048942e5aaeeee2cedceecf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 37af9ab3ba9e38bf792d7a46aea3ec7c0621524d6393c2cf52998fdf6e789957d03c5cb5dbdc2a0192899ccd24e54913e39aec37370c7e076eef20f1bd9cc881
|
|
7
|
+
data.tar.gz: 4fa79294450f004e253e37fac1da593a25520b8261ae61132a43c1eeaa76a72e82c1567b80bcede2bb2704eb99e44e0b5426042dd09117d36bfcc324b258ffd8
|
data/bin/synful
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# synful - Ruby utility that shows syntax highlighted code in your browser
|
|
5
5
|
#
|
|
6
6
|
# Author: Steve Shreeve (steve.shreeve@gmail.com)
|
|
7
|
-
# Date: Feb
|
|
7
|
+
# Date: Feb 22, 2023
|
|
8
8
|
#
|
|
9
9
|
# Thanks to Julie Evans for creating the amazing rouge library!
|
|
10
10
|
# ============================================================================
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
# ============================================================================
|
|
15
15
|
# TODO:
|
|
16
16
|
# 1. Ensure there is a section for a file, even when it has a bad encoding
|
|
17
|
-
# 2. See https://stackoverflow.com/questions/18519641/why-cant-i-refer-to-data-in-class-context
|
|
18
17
|
# ============================================================================
|
|
19
18
|
|
|
20
19
|
require "optparse"
|
|
@@ -69,62 +68,67 @@ Rouge::Lexers::ERB.filenames "*.eco"
|
|
|
69
68
|
|
|
70
69
|
require "find"
|
|
71
70
|
require "set"
|
|
72
|
-
require "sinatra"
|
|
71
|
+
require "sinatra/base"
|
|
73
72
|
|
|
74
73
|
$stderr = $stderr.dup.reopen File.new("/dev/null", "w") # turn off logger
|
|
75
74
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
75
|
+
class Synful < Sinatra::Application
|
|
76
|
+
enable :inline_templates
|
|
77
|
+
set :server, "webrick"
|
|
78
|
+
|
|
79
|
+
get "*" do
|
|
80
|
+
skip, want, fore, keep, deny = [$skip, $want, $fore, $keep, $deny]
|
|
81
|
+
|
|
82
|
+
init = Time.now.to_f
|
|
83
|
+
|
|
84
|
+
@list = want.inject([]) do |list, path|
|
|
85
|
+
if !File.readable?(path)
|
|
86
|
+
warn "unreadable '#{path}'"
|
|
87
|
+
elsif File.directory?(path)
|
|
88
|
+
Find.find(path) do |path|
|
|
89
|
+
path.delete_prefix!("./") #!# TODO: is this working as expected?
|
|
90
|
+
if !File.readable?(path) || path == "."
|
|
91
|
+
next
|
|
92
|
+
elsif File.directory?(path)
|
|
93
|
+
Find.prune if File.basename(path).start_with?(".") or skip&.include?(path)
|
|
94
|
+
elsif File.file?(path)
|
|
95
|
+
next if skip&.include?(path)
|
|
96
|
+
type = path[/(?<=\.)[^.\/]+\z/].to_s.downcase
|
|
97
|
+
list << path if keep ? keep.include?(type) : !deny.include?(type)
|
|
98
|
+
else
|
|
99
|
+
warn "unknown '#{path}'"
|
|
100
|
+
end
|
|
99
101
|
end
|
|
102
|
+
elsif File.file?(path)
|
|
103
|
+
list << path # requested explicitly
|
|
100
104
|
end
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
headers "Connection" => "close"
|
|
120
|
-
body
|
|
105
|
+
list
|
|
106
|
+
end.sort.uniq
|
|
107
|
+
|
|
108
|
+
# show filenames
|
|
109
|
+
time = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
|
110
|
+
STDERR.puts "\n[#{time}]\n\n", @list.map {|item| " • #{item}"}
|
|
111
|
+
|
|
112
|
+
# generate content and generation time
|
|
113
|
+
$err = false
|
|
114
|
+
body = erb :page
|
|
115
|
+
wait = Time.now.to_f - init
|
|
116
|
+
STDERR.puts "\nTime elapsed: %.2f" % wait
|
|
117
|
+
|
|
118
|
+
# send response
|
|
119
|
+
$fore or Thread.new { sleep wait; exit! } # how can we know when the request is "done?"
|
|
120
|
+
headers "Connection" => "close"
|
|
121
|
+
body
|
|
122
|
+
end
|
|
121
123
|
end
|
|
122
124
|
|
|
123
125
|
Thread.new do
|
|
124
|
-
sleep 0.1 until
|
|
125
|
-
fork or exec "open 'http://localhost:#{
|
|
126
|
+
sleep 0.1 until Synful.running?
|
|
127
|
+
fork or exec "open 'http://localhost:#{Synful.port}/'"
|
|
126
128
|
end
|
|
127
129
|
|
|
130
|
+
Synful.run!
|
|
131
|
+
|
|
128
132
|
__END__
|
|
129
133
|
|
|
130
134
|
@@ layout
|
data/synful.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: synful
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Steve Shreeve
|
|
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
69
69
|
- !ruby/object:Gem::Version
|
|
70
70
|
version: '0'
|
|
71
71
|
requirements: []
|
|
72
|
-
rubygems_version: 3.4.
|
|
72
|
+
rubygems_version: 3.4.7
|
|
73
73
|
signing_key:
|
|
74
74
|
specification_version: 4
|
|
75
75
|
summary: Ruby utility that shows syntax highlighted code in your browser
|