servel 0.6.0 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9415e93e4c4259efd8b7547c1d8a67c8bb71c54
4
- data.tar.gz: 87744e0b049184c5b2138fd34ab3e34c292016dd
3
+ metadata.gz: d4a27247e6a018f755e9ace67a1135b4a324702a
4
+ data.tar.gz: d812976aaa161dc23b9fea1d661db77b7b81d5af
5
5
  SHA512:
6
- metadata.gz: 30c5075efb1b5fab6b79ee68b55a18e75fddfe681bd7c03d159a83f2321b97f7442b7cd9430d8c3aadf5117db6a9fd244c48ed1d23200ba8c8f4302f5c915821
7
- data.tar.gz: 5e2e42e1b6caf5857a3d16a6d44d8207343401a4188a82af8bbbee4a7cca5bfc599b25755a1c3edba805c247276cadd160444fbc5f1b42509ea4b7dc984d007a
6
+ metadata.gz: 37bd1b9749d58c39d15c97165f07ee3bc49795d68cc7bdaf89aaccbbfa70baa71295b92faa5f23f53fe120515d2abde5bf020618651b8a179fca845bf30a0635
7
+ data.tar.gz: 96af2ce748d56880f872f12e1af2841010d9aa959553883480de01ffdbc19af6f8ef4e3a62ad71b75fef24115b28fa538b27a4fec12c4bdd5a2af8a8053cdc07
data/lib/servel/path.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  class Servel::Path
2
2
  attr_reader :type, :media_type, :listing_classes, :icon, :href, :name, :size, :mtime
3
3
 
4
- def initialize(type:, media_type:, listing_classes:, icon:, href:, name:, size: nil, mtime: nil)
4
+ def initialize(type:, media_type: nil, listing_classes:, icon:, href:, name:, size: nil, mtime: nil)
5
5
  @type = type
6
6
  @media_type = media_type
7
7
  @listing_classes = listing_classes
@@ -12,34 +12,23 @@ class Servel::Path
12
12
  @mtime = mtime
13
13
  end
14
14
 
15
- def listing_attrs
16
- {
17
- class: @listing_classes,
18
- data: {
19
- type: @media_type
20
- }
21
- }
22
- end
23
-
24
15
  def media?
25
- @media_type != "unknown"
16
+ !@media_type.nil?
26
17
  end
27
18
 
28
19
  def self.top(href)
29
20
  Servel::Path.new(
30
21
  type: "Dir",
31
- media_type: "unknown",
32
22
  listing_classes: "top directory",
33
23
  icon: "🔝",
34
24
  href: href,
35
25
  name: "Top Directory"
36
26
  )
37
27
  end
38
-
28
+
39
29
  def self.parent(href)
40
30
  Servel::Path.new(
41
31
  type: "Dir",
42
- media_type: "unknown",
43
32
  listing_classes: "parent directory",
44
33
  icon: "⬆️",
45
34
  href: href,
@@ -1,8 +1,12 @@
1
1
  class Servel::PathBuilder
2
+ IMAGE_EXTS = %w(.jpg .jpeg .png .gif)
3
+ VIDEO_EXTS = %w(.webm .mp4)
4
+ AUDIO_EXTS = %w(.mp3 .m4a .wav)
5
+
2
6
  def initialize(path)
3
7
  @path = Pathname.new(path)
4
8
  end
5
-
9
+
6
10
  def build
7
11
  Servel::Path.new(
8
12
  type: type,
@@ -15,22 +19,6 @@ class Servel::PathBuilder
15
19
  mtime: @path.mtime
16
20
  )
17
21
  end
18
-
19
- def image?
20
- @path.file? && @path.extname && %w(.jpg .jpeg .png .gif).include?(@path.extname.downcase)
21
- end
22
-
23
- def video?
24
- @path.file? && @path.extname && %w(.webm .mp4).include?(@path.extname.downcase)
25
- end
26
-
27
- def audio?
28
- @path.file? && @path.extname && %w(.mp3 .m4a .wav).include?(@path.extname.downcase)
29
- end
30
-
31
- def media?
32
- image? || video? || audio?
33
- end
34
22
 
35
23
  def type
36
24
  if @path.directory?
@@ -43,31 +31,37 @@ class Servel::PathBuilder
43
31
  end
44
32
 
45
33
  def media_type
46
- return "video" if video?
47
- return "image" if image?
48
- return "audio" if audio?
49
- "unknown"
34
+ return nil unless @path.file? && @path.extname
35
+
36
+ case @path.extname.downcase
37
+ when *IMAGE_EXTS
38
+ :image
39
+ when *VIDEO_EXTS
40
+ :video
41
+ when *AUDIO_EXTS
42
+ :audio
43
+ else
44
+ nil
45
+ end
50
46
  end
51
47
 
52
48
  def listing_classes
53
49
  klasses = []
54
- klasses << "media" if media?
55
- klasses << "image" if image?
56
- klasses << "video" if video?
57
- klasses << "audio" if audio?
58
50
  klasses << "file" if @path.file?
59
51
  klasses << "directory" if @path.directory?
52
+ klasses << "media" if media_type
53
+ klasses << media_type if media_type
60
54
  klasses.join(" ")
61
55
  end
62
56
 
63
57
  def icon
64
- if @path.directory?
65
- "📁"
66
- elsif video?
58
+ return "📁" if @path.directory?
59
+ case media_type
60
+ when :video
67
61
  "🎞️"
68
- elsif image?
62
+ when :image
69
63
  "🖼️"
70
- elsif audio?
64
+ when :audio
71
65
  "🔊"
72
66
  else
73
67
  "📝"
@@ -13,9 +13,9 @@
13
13
  %tr
14
14
  %td
15
15
  %span.icon= file.icon
16
- %a.default{href: file.href, **file.listing_attrs}= file.name
16
+ %a.default{href: file.href, class: file.listing_classes, data: { type: file.media_type }}= file.name
17
17
  %td
18
- %a.new-tab{href: file.href, target: "_blank", **file.listing_attrs} (New tab)
18
+ %a.new-tab{href: file.href, class: file.listing_classes, target: "_blank"} (New tab)
19
19
  %td= file.type
20
20
  %td= file.size.nil? ? "-" : number_to_human_size(file.size)
21
21
  %td= file.mtime.nil? ? "-" : file.mtime.strftime("%e %b %Y %l:%M %p")
@@ -1,3 +1,3 @@
1
1
  module Servel
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: servel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brenton "B-Train" Fletcher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-10 00:00:00.000000000 Z
11
+ date: 2018-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler