synful 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -1
  3. data/bin/synful +90 -68
  4. data/synful.gemspec +1 -1
  5. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e868e7d2521446e9bee4d813d8e15580b5ccfb58f71c0b7fad2459d212585a13
4
- data.tar.gz: 1b2b05e76f6718625c94b77fa43e55c3d808a2c3c22ded2a83c9f4a24d8d99e9
3
+ metadata.gz: 37beb91e8a78a71b6bdbbfb1833b664a5d2cbf8d260cfb8bfe4aa3c1366ebacf
4
+ data.tar.gz: eeb2fafa7499da63f9484609c624bfbcea4ef2c29048942e5aaeeee2cedceecf
5
5
  SHA512:
6
- metadata.gz: f7c6834c135e52ed6aa55f5ea9422a566957a3b046f02a94ff9a32391c34f927513801a866f8d2ec919fc7b721dddc7ef80d9e314b4977d0bb971ef54fed7287
7
- data.tar.gz: 50d63b3c5b7af27adbc8b4e38765a8c60d183d1cc2c413e3e1edf5a4982184dad28f090e9518ddcc5b46c26641d1be042f11197d83eb0728d0f628207158f87b
6
+ metadata.gz: 37af9ab3ba9e38bf792d7a46aea3ec7c0621524d6393c2cf52998fdf6e789957d03c5cb5dbdc2a0192899ccd24e54913e39aec37370c7e076eef20f1bd9cc881
7
+ data.tar.gz: 4fa79294450f004e253e37fac1da593a25520b8261ae61132a43c1eeaa76a72e82c1567b80bcede2bb2704eb99e44e0b5426042dd09117d36bfcc324b258ffd8
data/README.md CHANGED
@@ -25,6 +25,8 @@ is made possible by the amazing Rouge library.
25
25
  $ synful winr/bin/winr censive/lib/censive.rb
26
26
  ```
27
27
 
28
+ <img src="https://user-images.githubusercontent.com/142875/219864590-482cb060-465c-4fbb-9fe0-3de34dea703e.png" width="900">
29
+
28
30
  A more complicated example is:
29
31
 
30
32
  ```
@@ -36,7 +38,7 @@ exclude all files with the `.spec` or `.ru` extensions. It will also
36
38
  include files from the `lib/` and `test/` directories as well as the
37
39
  `/tmp/example.rb` file. Even though the `test/boring-results.txt` file
38
40
  should be rendered, we have disabled it via the `-` (minus sign or dash)
39
- in front of it's filename. Note that to use this type of negation, we
41
+ in front of its filename. Note that to use this type of negation, we
40
42
  need to precede it with a "double-dash" `--` to tell `synful` that we
41
43
  are done with the normal command options.
42
44
 
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
  # ============================================================================
@@ -68,62 +68,67 @@ Rouge::Lexers::ERB.filenames "*.eco"
68
68
 
69
69
  require "find"
70
70
  require "set"
71
- require "sinatra"
71
+ require "sinatra/base"
72
72
 
73
73
  $stderr = $stderr.dup.reopen File.new("/dev/null", "w") # turn off logger
74
74
 
75
- set :server, "webrick"
76
-
77
- get "*" do
78
- skip, want, fore, keep, deny = [$skip, $want, $fore, $keep, $deny]
79
-
80
- init = Time.now.to_f
81
-
82
- @list = want.inject([]) do |list, path|
83
- if !File.readable?(path)
84
- warn "unreadable '#{path}'"
85
- elsif File.directory?(path)
86
- Find.find(path) do |path|
87
- path.delete_prefix!("./") #!# TODO: is this working as expected?
88
- if !File.readable?(path) || path == "."
89
- next
90
- elsif File.directory?(path)
91
- Find.prune if File.basename(path).start_with?(".") or skip&.include?(path)
92
- elsif File.file?(path)
93
- next if skip&.include?(path)
94
- type = path[/(?<=\.)[^.\/]+\z/].to_s.downcase
95
- list << path if keep ? keep.include?(type) : !deny.include?(type)
96
- else
97
- 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
98
101
  end
102
+ elsif File.file?(path)
103
+ list << path # requested explicitly
99
104
  end
100
- elsif File.file?(path)
101
- list << path # requested explicitly
102
- end
103
- list
104
- end.sort.uniq
105
-
106
- # show filenames
107
- time = Time.now.strftime("%Y-%m-%d %H:%M:%S")
108
- STDERR.puts "\n[#{time}]\n\n", @list.map {|item| " • #{item}"}
109
-
110
- # generate content and generation time
111
- $err = false
112
- body = erb :page
113
- wait = Time.now.to_f - init
114
- STDERR.puts "\nTime elapsed: %.2f" % wait
115
-
116
- # send response
117
- $fore or Thread.new { sleep wait; exit! } # how can we know when the request is "done?"
118
- headers "Connection" => "close"
119
- 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
120
123
  end
121
124
 
122
125
  Thread.new do
123
- sleep 0.1 until settings.running?
124
- fork or exec "open 'http://localhost:#{settings.port}/'"
126
+ sleep 0.1 until Synful.running?
127
+ fork or exec "open 'http://localhost:#{Synful.port}/'"
125
128
  end
126
129
 
130
+ Synful.run!
131
+
127
132
  __END__
128
133
 
129
134
  @@ layout
@@ -134,15 +139,28 @@ __END__
134
139
  <title>Synful</title>
135
140
  <link rel="icon" href="data:,">
136
141
  <style type="text/css">
137
- html body { font-size: 14px; }
138
- body { font-family: Verdana; padding: 5px; }
139
- a { text-decoration: none; }
140
- h4 a { color: #fff; font-weight: bold; margin: 0; border: none; }
141
- h4 a:hover { background: #333; }
142
- h4 { background: black; color: white; padding: 5px; margin: 0; border: none; }
142
+ body { margin: 0; padding: 0; font-family: Verdana; font-size: 14px; }
143
+ pre { margin: 0; font-family: Consolas, Menlo, monospace; }
144
+ a { text-decoration: none; scroll-margin-top: 0.5em; }
145
+
146
+ .cap {
147
+ background: black;
148
+ color: white;
149
+ font-weight: bold;
150
+ line-height: 30px;
151
+ display: grid;
152
+ grid-template-columns: 1fr 10em;
153
+ align-items: stretch;
154
+ }
155
+ .cap > div:nth-child(1) { padding-left: 1em; }
156
+ .cap > div:nth-child(2) { display: grid; grid-template-columns: 1fr 1fr 1fr; place-content: stretch; }
157
+ .cap a { text-align: center; color: white; }
158
+ .cap a:hover { background: rgba(255,255,255,0.5); }
159
+
160
+ @media print { .cap > div:nth-child(2) { display: none; } }
161
+
143
162
  li a { color: #000; }
144
163
  li a:hover { text-decoration: underline; color: #666; }
145
- pre { margin: 0; font-family: Consolas, Menlo, monospace; }
146
164
 
147
165
  .rouge-table { padding: 0; border-collapse: collapse; }
148
166
  .rouge-table td { padding: 0; vertical-align: top; }
@@ -225,13 +243,15 @@ __END__
225
243
  <%= erb :toc if (count = @list.size) > 1 %><%
226
244
  @list.each_with_index do |file, i|
227
245
  @file = file
228
- @prev = @list[(i - 1) % count]
229
246
  @next = @list[(i + 1) % count]
247
+ @prev = @list[(i - 1) % count]
230
248
  @curr = count > 1 ? "#{i + 1}) " : "" %>
231
249
  <%= erb :file %><% end %>
232
250
 
233
251
  @@ toc
234
- <h4><a name="top">Index</a></h4>
252
+ <div class="cap">
253
+ <div><a name="top">Index</a></div>
254
+ </div>
235
255
 
236
256
  <ul><% @list.each do |file| %>
237
257
  <li><a href="#<%= file %>"><%= file %></a></li><% end %>
@@ -261,18 +281,20 @@ __END__
261
281
  end
262
282
  %>
263
283
 
264
- <h4>
265
- <a name="<%= @file %>"><%= @curr %><%= @file %>
266
- (<%= data.count("\n") + 1 %> lines)
267
- <%= "[" + type.tag + "]" if type %>
268
- <%= File.mtime(@file).strftime("on %Y-%m-%d at %-I:%M %P") %>
269
- </a>
270
- <span style="float: right">
271
- <a class="jump" href="#<%= @prev %>">&nbsp;&nbsp;&nbsp;&nbsp;&darr;&nbsp;&nbsp;&nbsp;&nbsp;</a>
272
- <a class="jump" href="#<%= @next %>">&nbsp;&nbsp;&nbsp;&nbsp;&UpArrow;&nbsp;&nbsp;&nbsp;&nbsp;</a>
273
- <a class="jump" href="#top">&nbsp;&nbsp;&nbsp;&nbsp;⥣&nbsp;&nbsp;&nbsp;&nbsp;</a>
274
- </span>
275
- </h4>
284
+ <div class="cap">
285
+ <div>
286
+ <a name="<%= @file %>"><%= @curr %><%= @file %>
287
+ (<%= data.count("\n") + 1 %> lines)
288
+ <%= "[" + type.tag + "]" if type %>
289
+ <%= File.mtime(@file).strftime("on %Y-%m-%d at %-I:%M %P") %>
290
+ </a>
291
+ </div>
292
+ <div>
293
+ <a href="#<%= @next %>">&darr;</a>
294
+ <a href="#<%= @prev %>">&UpArrow;</a>
295
+ <a href="#top">⥣</a>
296
+ </div>
297
+ </div>
276
298
 
277
299
  <%=
278
300
  if type
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.0"
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synful
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Shreeve
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-18 00:00:00.000000000 Z
11
+ date: 2023-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rouge
@@ -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