view-cell 0.8.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.version +2 -1
- data/lib/adapters/view.rb +14 -11
- data/lib/view-cell/class.rb +28 -5
- data/lib/view-cell/instance.rb +17 -24
- data/lib/view-cell.rb +4 -0
- metadata +45 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17fa863f47248eaa8787f33a52b94287380c194adb6502b5757b3adfc4b68e42
|
4
|
+
data.tar.gz: 58783589b2318b83f796cf65b8ee074b02472bd154046c1c674401334ee05361
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2c9d1cad6445cd5aeafc47be258bc534c2fffe8192a42654b5d3f4b9d5e1e651a7f8a7fbaf8f2adcdb67dbae676bf4691aa486876f646d22453459c24a7b27c
|
7
|
+
data.tar.gz: 8f0c5655356dd424c9803cf164db2c85b2e54a884de894b3de51320efa3758bafbc73d4d3dc42543f269bd12ba2fd0391afd991896f43b881c1579fa5bae6844
|
data/.version
CHANGED
data/lib/adapters/view.rb
CHANGED
@@ -1,14 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
ActionView::Base.include ViewCell::ProxyMethod
|
1
|
+
# enables shorcut
|
2
|
+
# FooCell.new(self).bar -> cell.foo.bar
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
Lux::Template::Helper.include ViewCell::ProxyMethod
|
8
|
-
|
9
|
-
elsif Object.const_defined?('Sinatra::Application')
|
10
|
-
# Sinatra inject
|
11
|
-
Sinatra::Application.include ViewCell::ProxyMethod
|
4
|
+
# include gem before rails if you do not want to import proxy methods
|
5
|
+
# gem 'view-cell'
|
12
6
|
|
7
|
+
[
|
8
|
+
'ActionView::Base',
|
9
|
+
'ActionController::Base',
|
10
|
+
'Lux::Template::Helper',
|
11
|
+
'Lux::Controller',
|
12
|
+
'Sinatra::Application'
|
13
|
+
].each do |klass|
|
14
|
+
if Object.const_defined?(klass)
|
15
|
+
klass.constantize.include ViewCell::ProxyMethod
|
16
|
+
end
|
13
17
|
end
|
14
|
-
|
data/lib/view-cell/class.rb
CHANGED
@@ -1,4 +1,14 @@
|
|
1
1
|
class ViewCell
|
2
|
+
include HtmlTag
|
3
|
+
|
4
|
+
DATA ||= {
|
5
|
+
template_root: nil,
|
6
|
+
css: {}
|
7
|
+
}
|
8
|
+
|
9
|
+
# exports "template_root" class attr
|
10
|
+
cattr :template_root, class: true
|
11
|
+
|
2
12
|
class << self
|
3
13
|
# load cell based on a name, pass context and optional vars
|
4
14
|
# ViewCell.get(:user, self) -> UserCell.new(self)
|
@@ -56,12 +66,25 @@ class ViewCell
|
|
56
66
|
end
|
57
67
|
end
|
58
68
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
69
|
+
def css text = nil
|
70
|
+
if text
|
71
|
+
require 'sassc' unless Object.const_defined?('SassC')
|
72
|
+
|
73
|
+
unless text.include?('{')
|
74
|
+
dir_name = self.template_root || File.dirname(caller[0].split(':')[0])
|
75
|
+
class_part = to_s.underscore.sub(/_cell$/, '')
|
76
|
+
dir_name = dir_name % class_part if dir_name.include?('%s')
|
77
|
+
css_file = Pathname.new(dir_name).join(text)
|
78
|
+
text = css_file.read
|
79
|
+
end
|
80
|
+
|
81
|
+
key = caller[0].split(':in ')[0]
|
82
|
+
DATA[:css][key] = SassC::Engine.new(text, style: :compact).render.gsub(/\n+/, $/).chomp
|
63
83
|
else
|
64
|
-
|
84
|
+
DATA[:css].inject([]) do |list, el|
|
85
|
+
name = el[0].split('/').last.split('.')[0].gsub('_', '-')
|
86
|
+
list.push("/* #{name} */\n" + el[1])
|
87
|
+
end.join("\n\n")
|
65
88
|
end
|
66
89
|
end
|
67
90
|
end
|
data/lib/view-cell/instance.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
class ViewCell
|
2
2
|
RENDER_CACHE ||= {}
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
def initialize parent=nil, vars={}
|
4
|
+
def initialize parent = nil, vars={}
|
7
5
|
@_parent = parent
|
8
6
|
vars.each { |k,v| instance_variable_set "@#{k}", v}
|
9
7
|
before
|
@@ -29,40 +27,35 @@ class ViewCell
|
|
29
27
|
|
30
28
|
# render template by name
|
31
29
|
def template name
|
32
|
-
template_root = self.class.template_root
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
name = [template_root, name].join '/'
|
37
|
-
elsif name.is_a?(Symbol)
|
38
|
-
name = './app/views/cells/%s/%s' % [class_part, name]
|
39
|
-
elsif name.to_s =~ /^\w/
|
40
|
-
name = './app/views/cells/%s' % name
|
30
|
+
path = if template_root = self.class.template_root
|
31
|
+
[template_root, name].join '/'
|
32
|
+
else
|
33
|
+
[File.dirname(caller[0]), name].join '/'
|
41
34
|
end
|
42
35
|
|
43
|
-
|
36
|
+
class_part = self.class.to_s.underscore.sub(/_cell$/, '')
|
37
|
+
path = path % class_part if path.include?('%s')
|
44
38
|
|
45
|
-
RENDER_CACHE.delete(
|
39
|
+
RENDER_CACHE.delete(path) if _development?
|
40
|
+
RENDER_CACHE[path] ||= begin
|
41
|
+
file_name = ''
|
46
42
|
|
47
|
-
RENDER_CACHE[name] ||= proc do
|
48
43
|
# find extension if one not provided
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
if (file = Dir['%s
|
44
|
+
if path =~ /\.\w{2,4}$/
|
45
|
+
file_name = path
|
46
|
+
else
|
47
|
+
if (file = Dir['%s.*' % path].first)
|
53
48
|
file_name = file
|
54
49
|
end
|
55
50
|
end
|
56
51
|
|
57
52
|
unless File.exist?(file_name)
|
58
|
-
raise ArgumentError, 'Template "%s.*" not found' %
|
53
|
+
raise ArgumentError, 'Template "%s.*" not found' % [path.sub(Dir.pwd, '.')]
|
59
54
|
end
|
60
55
|
|
61
56
|
Tilt.new(file_name)
|
62
|
-
end
|
63
|
-
|
64
|
-
out = RENDER_CACHE[name].render(self)
|
65
|
-
out.respond_to?(:html_safe) ? out.html_safe : out
|
57
|
+
end
|
58
|
+
RENDER_CACHE[path].render(self)
|
66
59
|
end
|
67
60
|
|
68
61
|
private
|
data/lib/view-cell.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: view-cell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dino Reic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tilt
|
@@ -38,6 +38,48 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sassc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: html-tag
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: class-cattr
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
41
83
|
description: Clean, simple explicit and strait-forward web view cell for use in Rails/Sinatra/Lux.
|
42
84
|
email: reic.dino@gmail.com
|
43
85
|
executables: []
|
@@ -69,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
111
|
- !ruby/object:Gem::Version
|
70
112
|
version: '0'
|
71
113
|
requirements: []
|
72
|
-
rubygems_version: 3.
|
114
|
+
rubygems_version: 3.5.3
|
73
115
|
signing_key:
|
74
116
|
specification_version: 4
|
75
117
|
summary: Simple to use web view cell
|