nanoc-opal 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/NEWS.md +6 -0
- data/README.md +36 -0
- data/lib/nanoc/opal/filter.rb +55 -0
- data/lib/nanoc/opal/version.rb +7 -0
- data/lib/nanoc/opal.rb +11 -0
- data/lib/nanoc-opal.rb +3 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5fd8ae9f6e8a263d05f9afd31fc38f491c2cdd63fd1dd06ffc1817de79ae6a1e
|
4
|
+
data.tar.gz: 05ee7181c1995d0d68c47fcfe7721dc8649ca70675d9032a4e37d91e72b041fb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f28bee9886bd6b47269043f56bdc02c4d730b7a7098372a8979dd5b1b2ec1a9f8f2d20c5e2190318ae0157e8f363878d2723d6506482aa1b822ee3f6767bb24e
|
7
|
+
data.tar.gz: 49c64094b95c72e8572a471d058cb942cf333f72a7922d5a38c11e941bf0f431e48ca9977adae4891e7f5faaae760bbec5337f088785454dd7715afb27647b5a
|
data/NEWS.md
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# nanoc-opal
|
2
|
+
|
3
|
+
This provides a filter that allows [Nanoc](https://nanoc.app) to process content via [Opal](https://opalrb.com).
|
4
|
+
|
5
|
+
This gem is based on nanoc's own nanoc-dart-sass.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add `nanoc-opal` to the `nanoc` group of your Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
group :nanoc do
|
13
|
+
gem 'nanoc-opal'
|
14
|
+
end
|
15
|
+
```
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
Call the `:opal` filter. For example:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require "nanoc-opal"
|
23
|
+
compile '/script.rb' do
|
24
|
+
filter :opal
|
25
|
+
|
26
|
+
write item.identifier.without_ext + '.js'
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
Options passed to this filter will be passed on to Opal. For example:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
filter :opal, arity_check: true
|
34
|
+
```
|
35
|
+
|
36
|
+
See `example` directory for a sample how to use Nanoc with Opal and Opal-Browser.
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Nanoc
|
4
|
+
module Opal
|
5
|
+
class Filter < Nanoc::Filter
|
6
|
+
identifier :opal
|
7
|
+
|
8
|
+
# Runs the content through [Opal](https://opalrb.com).
|
9
|
+
# Parameters passed as `:args` will be passed on to Opal..
|
10
|
+
#
|
11
|
+
# @param [String] content The content to filter
|
12
|
+
#
|
13
|
+
# @return [String] The filtered content
|
14
|
+
def run(string, params = {})
|
15
|
+
params = params.dup
|
16
|
+
|
17
|
+
# Add current directory to the load path or something else if `load_path`
|
18
|
+
# param is provided.
|
19
|
+
ident = item.identifier.to_s
|
20
|
+
fn = item.raw_filename
|
21
|
+
dirname = File.dirname(fn)
|
22
|
+
paths = params.delete(:load_path) || [dirname]
|
23
|
+
paths = ::Opal.paths + paths
|
24
|
+
params[:path_reader] = ::Opal::PathReader.new(
|
25
|
+
paths,
|
26
|
+
::Opal::Builder.extensions.map { |e| [".#{e}", ".js.#{e}"] }.flatten
|
27
|
+
)
|
28
|
+
|
29
|
+
builder = ::Opal::Builder.new(**params)
|
30
|
+
builder.build_str(string, fn)
|
31
|
+
code = builder.to_s
|
32
|
+
|
33
|
+
prefix = File.dirname(item.identifier.to_s)
|
34
|
+
prefix += '/' unless prefix.end_with? '/'
|
35
|
+
|
36
|
+
# Build a dependency chain
|
37
|
+
dependencies = builder.dependent_files
|
38
|
+
# Select only those required files that are present in our filesystem
|
39
|
+
dependencies = dependencies.select { |i| i.start_with?(dirname) }
|
40
|
+
# Remove the directory part up to a location of our asset
|
41
|
+
dependencies = dependencies.map { |i| i.gsub(/\A#{dirname}\//, '') }
|
42
|
+
# Add a prefix of our main asset (eg. /assets/js/)
|
43
|
+
dependencies = dependencies.map { |i| prefix + i }
|
44
|
+
# Convert that to Nanoc items
|
45
|
+
dependencies = dependencies.map { |i| items[i] }.compact
|
46
|
+
# Reject itself
|
47
|
+
dependencies = dependencies.reject { |i| i == item }
|
48
|
+
|
49
|
+
depend_on dependencies
|
50
|
+
|
51
|
+
code
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/nanoc/opal.rb
ADDED
data/lib/nanoc-opal.rb
ADDED
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nanoc-opal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- hmdne
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-01-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nanoc-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.12'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: opal
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.8'
|
41
|
+
description: Provides an :opal filter for Nanoc
|
42
|
+
email:
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- NEWS.md
|
48
|
+
- README.md
|
49
|
+
- lib/nanoc-opal.rb
|
50
|
+
- lib/nanoc/opal.rb
|
51
|
+
- lib/nanoc/opal/filter.rb
|
52
|
+
- lib/nanoc/opal/version.rb
|
53
|
+
homepage: https://github.com/hmdne/nanoc-opal/
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
metadata:
|
57
|
+
rubygems_mfa_required: 'true'
|
58
|
+
source_code_uri: https://github.com/hmdne/nanoc-opal/tree/nanoc-opal-v0.1.0/nanoc-opal
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '2.7'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubygems_version: 3.4.10
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: Opal filter for Nanoc
|
78
|
+
test_files: []
|