frails 0.5.0 → 0.5.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/frails/monkey/action_view/partial_renderer.rb +18 -5
- data/lib/frails/version.rb +1 -1
- data/package/components.js +34 -24
- data/package/side_load.js +7 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be11f37a9eb2399e8c7da768f1a69f3b72280c453b23c9fa38725c3f3c835a3c
|
4
|
+
data.tar.gz: eeb4c69660eb4602fff64a38d298b386ab0351616a3faea9f4f0d8421c9d57a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f8c3536fa4fb8944533dc6a9dd4842b62a9f23e6092324224d1a715ac33fb555adcd28a6a5155a5d892ddff16071d025ca9476ba0be18aead3191ad09352b1b
|
7
|
+
data.tar.gz: 23a6cd608d128f1961cca8ed6623ecd7b05ba36c07f148c81300ba832471b4a1c069fec379b33571637c1181563f41ea7764d675f78c579d675d98ffb8e86a6c
|
data/Gemfile.lock
CHANGED
@@ -4,6 +4,13 @@ module Frails
|
|
4
4
|
module Monkey
|
5
5
|
module ActionView
|
6
6
|
module PartialRenderer
|
7
|
+
def render_collection(view, template)
|
8
|
+
# Side load partial assets - if any.
|
9
|
+
@asset_path = @side_load_assets && side_load_assets(view, template)
|
10
|
+
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
7
14
|
def render_partial(view, template)
|
8
15
|
# Side load partial assets - if any.
|
9
16
|
@asset_path = @side_load_assets && side_load_assets(view, template)
|
@@ -26,21 +33,21 @@ module Frails
|
|
26
33
|
doc = Nokogiri::HTML::DocumentFragment.parse(content)
|
27
34
|
|
28
35
|
return content if (modules = doc.css('[css_module]')).empty?
|
36
|
+
return content unless (path = stylesheet_path_for_ident)
|
29
37
|
|
30
38
|
modules.each do |ele|
|
31
|
-
classes = class_name_for_style(ele.delete('css_module'))
|
39
|
+
classes = class_name_for_style(ele.delete('css_module'), path)
|
32
40
|
ele['class'] = (ele['class'].nil? ? classes : classes << ele['class']).join(' ')
|
33
41
|
end
|
34
42
|
|
35
43
|
doc.to_html
|
36
44
|
end
|
37
45
|
|
38
|
-
def class_name_for_style(class_names)
|
39
|
-
class_names.to_s.split.map { |class_name| build_ident class_name }
|
46
|
+
def class_name_for_style(class_names, path)
|
47
|
+
class_names.to_s.split.map { |class_name| build_ident class_name, path }
|
40
48
|
end
|
41
49
|
|
42
|
-
def build_ident(local_name)
|
43
|
-
path = Rails.root.join('app', "#{@asset_path}.css").relative_path_from(Rails.root)
|
50
|
+
def build_ident(local_name, path)
|
44
51
|
hash_digest = Digest::MD5.hexdigest("#{path}+#{local_name}")[0, 6]
|
45
52
|
|
46
53
|
return "#{local_name}-#{hash_digest}" unless Frails.dev_server.running?
|
@@ -50,6 +57,12 @@ module Frails
|
|
50
57
|
ident.prepend("#{path.dirname.to_s.tr('/', '-')}-")
|
51
58
|
ident
|
52
59
|
end
|
60
|
+
|
61
|
+
def stylesheet_path_for_ident
|
62
|
+
return if (globs = Rails.root.glob("app/#{@asset_path}.{css,scss,sass,less}")).empty?
|
63
|
+
|
64
|
+
globs.first.relative_path_from(Rails.root)
|
65
|
+
end
|
53
66
|
end
|
54
67
|
end
|
55
68
|
end
|
data/lib/frails/version.rb
CHANGED
data/package/components.js
CHANGED
@@ -1,47 +1,57 @@
|
|
1
|
-
const glob = require(
|
2
|
-
const path = require(
|
3
|
-
const fs = require(
|
1
|
+
const glob = require("glob");
|
2
|
+
const path = require("path");
|
3
|
+
const fs = require("fs");
|
4
4
|
|
5
|
-
const appPath = path.join(process.cwd(),
|
5
|
+
const appPath = path.join(process.cwd(), "app");
|
6
6
|
|
7
7
|
// Build entry points for HTML based components (components with an index.html.erb and index.css).
|
8
8
|
//
|
9
9
|
// NOTE: Adding new files will require a rebuild!
|
10
10
|
const buildComponents = () => {
|
11
|
-
const result = {}
|
11
|
+
const result = {};
|
12
12
|
|
13
13
|
// Find HTML partials and add its corresponding index.css as an entry point if it exists.
|
14
|
-
glob
|
15
|
-
|
14
|
+
glob
|
15
|
+
.sync(path.join(appPath, "components/**/_index.html.erb"))
|
16
|
+
.forEach(paf => {
|
17
|
+
paf = paf.replace("_index.html.erb", "index.css");
|
16
18
|
|
17
|
-
|
19
|
+
if (!fs.existsSync(paf)) return;
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
+
const namespace = path.relative(path.join(appPath), path.dirname(paf));
|
22
|
+
const name = path.join(namespace, path.basename(paf, path.extname(paf)));
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
+
result[name] = paf;
|
25
|
+
});
|
24
26
|
|
25
27
|
// Find components with no JSX and HTML index files, and add its corresponding index.css as an
|
26
28
|
// entry point if it exists. These will be components that render from within the Ruby class
|
27
29
|
// itself.
|
28
|
-
glob.sync(path.join(appPath,
|
29
|
-
css_paf = paf.replace(
|
30
|
-
html_paf = paf.replace(
|
31
|
-
jsx_paf = paf.replace(
|
30
|
+
glob.sync(path.join(appPath, "components/**/*_component.rb")).forEach(paf => {
|
31
|
+
css_paf = paf.replace("_component.rb", "/index.css");
|
32
|
+
html_paf = paf.replace("_component.rb", "/_index.html.erb");
|
33
|
+
jsx_paf = paf.replace("_component.rb", "/index.entry.jsx");
|
32
34
|
|
33
35
|
// Ignore if we have a JSX or HTML file, or no CSS file.
|
34
|
-
if (
|
36
|
+
if (
|
37
|
+
fs.existsSync(jsx_paf) ||
|
38
|
+
fs.existsSync(html_paf) ||
|
39
|
+
!fs.existsSync(css_paf)
|
40
|
+
)
|
41
|
+
return;
|
35
42
|
|
36
|
-
const namespace = path.relative(path.join(appPath), path.dirname(css_paf))
|
37
|
-
const name = path.join(
|
43
|
+
const namespace = path.relative(path.join(appPath), path.dirname(css_paf));
|
44
|
+
const name = path.join(
|
45
|
+
namespace,
|
46
|
+
path.basename(css_paf, path.extname(css_paf))
|
47
|
+
);
|
38
48
|
|
39
|
-
result[name] = css_paf
|
40
|
-
})
|
49
|
+
result[name] = css_paf;
|
50
|
+
});
|
41
51
|
|
42
|
-
return result
|
43
|
-
}
|
52
|
+
return result;
|
53
|
+
};
|
44
54
|
|
45
55
|
module.exports = {
|
46
56
|
entry: { ...buildComponents() }
|
47
|
-
}
|
57
|
+
};
|
data/package/side_load.js
CHANGED
@@ -10,12 +10,14 @@ const appPath = path.join(process.cwd(), "app");
|
|
10
10
|
const build = () => {
|
11
11
|
const result = {};
|
12
12
|
|
13
|
-
glob
|
14
|
-
|
15
|
-
|
13
|
+
glob
|
14
|
+
.sync(path.join(appPath, "views/**/*.{css,scss,sass,less,js}"))
|
15
|
+
.forEach(paf => {
|
16
|
+
const namespace = path.relative(appPath, path.dirname(paf));
|
17
|
+
const name = path.join(namespace, path.basename(paf, path.extname(paf)));
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
+
has(result, name) ? result[name].push(paf) : (result[name] = [paf]);
|
20
|
+
});
|
19
21
|
|
20
22
|
return result;
|
21
23
|
};
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Moss
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|