view-cell 0.7.0 → 0.7.1

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/.version +1 -1
  3. data/lib/view-cell/instance.rb +27 -5
  4. metadata +17 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a15d49ffdcd069071a8221bbc30a4085ddc6e5a99899aa4269b1c8e806557971
4
- data.tar.gz: 22c6c8ddf07120ffbc4b4efb69bbc8329d769e8577da336f6d2d8081cca7afd4
3
+ metadata.gz: e57db81e45fc3e232ce7afb041c20bb97bbac6a18fa506c298af0ba360a55ba5
4
+ data.tar.gz: 6af3ceeb169cd80cbd4e920bde15a3c6f82f568e1167da4bc3e43d770e366dec
5
5
  SHA512:
6
- metadata.gz: f57e0b945f9533fd17c0cbd389c81ce860129a73299b54b6384ab3ea037d6da7510355540df5a2211ca6d473aa55388d40d8e67b771f4319a3ea3634de2c08f6
7
- data.tar.gz: 9b8c586e7353abcd7a365a5634f30943ee7cdbf010d5c88bd4d66cd2ac127a2a3353afcbd5356331a10a5a3f083b8aababa9f9743c7787066a4cadbe2fc3f9c4
6
+ metadata.gz: 9c24dd9399235abe966e5443f772135a7902f46c2130751a193f2ae50efa585cc0602c8488e1a89ad01ad3ebde145c1d709731c32fbed68d7832f763a3ccd101
7
+ data.tar.gz: 6ca55a097a68220fcd0e4b7cd291e9da905dab3800eeed9d3399a298f835d2504cfa6eb27d10c5b2b90ab993dcfb05d109126f58e8505decb6d9f6970ab12045
data/.version CHANGED
@@ -1 +1 @@
1
- 0.7.0
1
+ 0.7.1
@@ -30,7 +30,7 @@ class ViewCell
30
30
  # render template by name
31
31
  def render name
32
32
  template_root = self.class.template_root
33
- class_part = self.class.to_s.underscore.sub(/_cell$/, '')
33
+ class_part = _underscore self.class.to_s.sub(/_cell$/, '')
34
34
 
35
35
  if template_root
36
36
  name = [template_root, name].join '/'
@@ -42,7 +42,7 @@ class ViewCell
42
42
 
43
43
  name = name % class_part if name.include?('%s')
44
44
 
45
- RENDER_CACHE.delete(name) if Rails.env.development?
45
+ RENDER_CACHE.delete(name) if _development?
46
46
 
47
47
  RENDER_CACHE[name] ||= proc do
48
48
  # find extension if one not provided
@@ -51,14 +51,36 @@ class ViewCell
51
51
  unless name =~ /\.\w{2,4}$/
52
52
  if (file = Dir['%s*' % name].first)
53
53
  file_name = file
54
- else
55
- raise 'Template "%s.*" not found' % name
56
54
  end
57
55
  end
58
56
 
57
+ unless File.exist?(file_name)
58
+ raise ArgumentError, 'Template "%s.*" not found' % name
59
+ end
60
+
59
61
  Tilt.new(file_name)
60
62
  end.call
61
63
 
62
- RENDER_CACHE[name].render(self).html_safe
64
+ out = RENDER_CACHE[name].render(self)
65
+ out.respond_to?(:html_safe) ? out.html_safe : out
66
+ end
67
+
68
+ private
69
+
70
+ def _development?
71
+ ENV['RAILS_ENV'] == 'development' || ENV['RACK_ENV'] == 'development'
72
+ end
73
+
74
+ def _underscore text
75
+ if text.respond_to?(:underscore)
76
+ # use framework underscore if possible
77
+ text.underscore
78
+ else
79
+ text.gsub(/::/, '/')
80
+ .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
81
+ .gsub(/([a-z\d])([A-Z])/,'\1_\2')
82
+ .tr("-", "_")
83
+ .downcase
84
+ end
63
85
  end
64
86
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view-cell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dino Reic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-11 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2021-02-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tilt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: Clean, simple explicit and strait-forward web view cell for use in Rails/Sinatra/Lux.
14
28
  email: reic.dino@gmail.com
15
29
  executables: []