frails 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a5dc3c71ad5adadae28c1dd72b8b2dbff630c6b51d93084b3dce0b6902eed42
4
- data.tar.gz: 580fe686a4e0e93779571144fbc3ccd9d55398cb1a67683310068310903954bf
3
+ metadata.gz: be11f37a9eb2399e8c7da768f1a69f3b72280c453b23c9fa38725c3f3c835a3c
4
+ data.tar.gz: eeb4c69660eb4602fff64a38d298b386ab0351616a3faea9f4f0d8421c9d57a0
5
5
  SHA512:
6
- metadata.gz: 28ee475ad7e401f72434510f8ed2fce9d05ecf57640ab13f7655e897b3995d3f422d9dfdec946f763c88cf7ce0282c531d280da23c641040ea39708923618ece
7
- data.tar.gz: a3142865ffd21446af2f877c30938fe6b91ea3eedf550d6dc585478ed6c87f15fa7b7fa7e3676f9592ea68cd8580529c4af35cd07e61976d62e557a8298d22a6
6
+ metadata.gz: 2f8c3536fa4fb8944533dc6a9dd4842b62a9f23e6092324224d1a715ac33fb555adcd28a6a5155a5d892ddff16071d025ca9476ba0be18aead3191ad09352b1b
7
+ data.tar.gz: 23a6cd608d128f1961cca8ed6623ecd7b05ba36c07f148c81300ba832471b4a1c069fec379b33571637c1181563f41ea7764d675f78c579d675d98ffb8e86a6c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- frails (0.4.0)
4
+ frails (0.5.0)
5
5
  nokogiri (>= 1.10.4)
6
6
  rack-proxy (>= 0.6.5)
7
7
  rails (>= 6.0)
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Frails
4
- VERSION = '0.5.0'
4
+ VERSION = '0.5.1'
5
5
  end
@@ -1,47 +1,57 @@
1
- const glob = require('glob')
2
- const path = require('path')
3
- const fs = require('fs')
1
+ const glob = require("glob");
2
+ const path = require("path");
3
+ const fs = require("fs");
4
4
 
5
- const appPath = path.join(process.cwd(), 'app')
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.sync(path.join(appPath, 'components/**/_index.html.erb')).forEach(paf => {
15
- paf = paf.replace('_index.html.erb', 'index.css')
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
- if (!fs.existsSync(paf)) return
19
+ if (!fs.existsSync(paf)) return;
18
20
 
19
- const namespace = path.relative(path.join(appPath), path.dirname(paf))
20
- const name = path.join(namespace, path.basename(paf, path.extname(paf)))
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
- result[name] = paf
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, 'components/**/*_component.rb')).forEach(paf => {
29
- css_paf = paf.replace('_component.rb', '/index.css')
30
- html_paf = paf.replace('_component.rb', '/_index.html.erb')
31
- jsx_paf = paf.replace('_component.rb', '/index.entry.jsx')
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 (fs.existsSync(jsx_paf) || fs.existsSync(html_paf) || !fs.existsSync(css_paf)) return
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(namespace, path.basename(css_paf, path.extname(css_paf)))
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.sync(path.join(appPath, "views/**/*.{css,js}")).forEach(paf => {
14
- const namespace = path.relative(appPath, path.dirname(paf));
15
- const name = path.join(namespace, path.basename(paf, path.extname(paf)));
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
- has(result, name) ? result[name].push(paf) : (result[name] = [paf]);
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.0
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-04 00:00:00.000000000 Z
11
+ date: 2019-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri