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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/synful +52 -48
  3. data/synful.gemspec +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bebeb5fb786aeb51dced6d659f916b4780c5d826b34cde51b20c24d567e49b67
4
- data.tar.gz: d28d17a448e5cf0c86b00e8c2589a4ada7bec18237536a910d39f14ec8ad4f25
3
+ metadata.gz: 37beb91e8a78a71b6bdbbfb1833b664a5d2cbf8d260cfb8bfe4aa3c1366ebacf
4
+ data.tar.gz: eeb2fafa7499da63f9484609c624bfbcea4ef2c29048942e5aaeeee2cedceecf
5
5
  SHA512:
6
- metadata.gz: 983bbe5586af0479ad709165cd8100c69284098a1953586ea866ec57a153e91b292ba042d5f16c86d05ab22e69c9f88f81aad32526eb850ebc6cbc5d9da316e6
7
- data.tar.gz: 246452e18e1df63ab9d99ff1a2576c50c9a9092566c4484a27cb97b9ada2f6c30bed70755430fdaafaf41bd5aa98eb51546ddd9e0c9ca9e5d8ec02dada290303
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 18, 2023
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
- set :server, "webrick"
77
-
78
- get "*" do
79
- skip, want, fore, keep, deny = [$skip, $want, $fore, $keep, $deny]
80
-
81
- init = Time.now.to_f
82
-
83
- @list = want.inject([]) do |list, path|
84
- if !File.readable?(path)
85
- warn "unreadable '#{path}'"
86
- elsif File.directory?(path)
87
- Find.find(path) do |path|
88
- path.delete_prefix!("./") #!# TODO: is this working as expected?
89
- if !File.readable?(path) || path == "."
90
- next
91
- elsif File.directory?(path)
92
- Find.prune if File.basename(path).start_with?(".") or skip&.include?(path)
93
- elsif File.file?(path)
94
- next if skip&.include?(path)
95
- type = path[/(?<=\.)[^.\/]+\z/].to_s.downcase
96
- list << path if keep ? keep.include?(type) : !deny.include?(type)
97
- else
98
- warn "unknown '#{path}'"
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
- elsif File.file?(path)
102
- list << path # requested explicitly
103
- end
104
- list
105
- end.sort.uniq
106
-
107
- # show filenames
108
- time = Time.now.strftime("%Y-%m-%d %H:%M:%S")
109
- STDERR.puts "\n[#{time}]\n\n", @list.map {|item| " • #{item}"}
110
-
111
- # generate content and generation time
112
- $err = false
113
- body = erb :page
114
- wait = Time.now.to_f - init
115
- STDERR.puts "\nTime elapsed: %.2f" % wait
116
-
117
- # send response
118
- $fore or Thread.new { sleep wait; exit! } # how can we know when the request is "done?"
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 settings.running?
125
- fork or exec "open 'http://localhost:#{settings.port}/'"
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "synful"
5
- s.version = "1.0.1"
5
+ s.version = "1.0.2"
6
6
  s.author = "Steve Shreeve"
7
7
  s.email = "steve.shreeve@gmail.com"
8
8
  s.summary =
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.1
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.6
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