simpacker 0.2.1 → 0.3.0

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: 19fc629b0f347b8160978738f12a04a454e058f94a4495a54746c29331f65858
4
- data.tar.gz: f9f27e87b24584439f8565b4ba960117c999ddfec9b3332bac4c1d85d6e16963
3
+ metadata.gz: 444b754848602fa63f5531bc7beb0d50714a686ff63bd58192373bac6c66c40f
4
+ data.tar.gz: 1fca8576ce3d3d982ab9b23ca043757e98d3bc5af35522cff0f4e2615323b4e6
5
5
  SHA512:
6
- metadata.gz: b798ec5ac44e5d64f5daa0e5da10b78a97fa91149202b7ed9c9b92851dcb2e5f74ddbd4e498c924f6345cadf369bac13aba7560891fe6a0f784b62c607cce4a5
7
- data.tar.gz: 68f8e76ccf7d0ae88d5ecd862533f5e71af32850f11d5ba0a6c6cd58aa3a761959af677fe6a2e14d67e51fe4dbf6677d833292c81e56f6b42d264d4850596ef5
6
+ metadata.gz: 84a3dfc8d926d60e407e0b6c34527e4ba153165f6143f2a5d406cf02d276e69bb19c2b9112c01e89b5c200ce2676d2bc0f9349d203f805c8804cad6599fb35b2
7
+ data.tar.gz: 6fa86aa1d886cdc732a94b9c90ca3961d427472ef98a30eb67931ef0fd78d5914dd591a3f0ac9fe0ba32a8049fd678b4d7e603e693860ba23870b5995acf9f75
data/README.md CHANGED
@@ -31,7 +31,7 @@ Add `javascript_pack_tag` in view.
31
31
  Run the folloing command to build JavaScript.
32
32
 
33
33
  ```
34
- $ npx wabpack --watch
34
+ $ ./node_modules/.bin/wabpack --watch
35
35
  ```
36
36
 
37
37
  ## Integrations
@@ -44,7 +44,7 @@ Simpacker does not provide feature for deployment. Just run the following comman
44
44
 
45
45
  ```
46
46
  $ npm install
47
- $ NODE_ENV=production npx webpack
47
+ $ NODE_ENV=production ./node_modules/.bin/webpack
48
48
  ```
49
49
 
50
50
  ## Contributing
@@ -1,14 +1,11 @@
1
+ require "simpacker/context"
1
2
  require "simpacker/configuration"
2
3
  require "simpacker/manifest"
3
4
  require "simpacker/helper"
4
5
  require "simpacker/railtie"
5
6
 
6
7
  module Simpacker
7
- def self.config
8
- @config ||= Simpacker::Configuration.new
9
- end
10
-
11
- def self.manifest
12
- @manifest ||= Simpacker::Manifest.new(config)
8
+ def self.default_context
9
+ @default_context ||= Simpacker::Context.new
13
10
  end
14
11
  end
@@ -4,8 +4,8 @@ module Simpacker
4
4
  class Configuration
5
5
  attr_accessor :root_path, :config_path, :env
6
6
 
7
- def initialize
8
- @root_path = Rails.root
7
+ def initialize(root_path:)
8
+ @root_path = root_path
9
9
  @config_path = @root_path.join("config/simpacker.yml")
10
10
  @env = Rails.env
11
11
  end
@@ -0,0 +1,10 @@
1
+ module Simpacker
2
+ class Context
3
+ attr_reader :config, :manifest
4
+
5
+ def initialize(root_path: Rails.root)
6
+ @config = Simpacker::Configuration.new(root_path: root_path)
7
+ @manifest = Simpacker::Manifest.new(self)
8
+ end
9
+ end
10
+ end
@@ -2,28 +2,32 @@ module Simpacker
2
2
  module Helper
3
3
  def javascript_pack_tag(*names, **options)
4
4
  sources = names.map do |name|
5
- Simpacker.manifest.lookup!("#{name}#{compute_asset_extname(name.to_s, type: :javascript)}")
5
+ simpacker_context.manifest.lookup!("#{name}#{compute_asset_extname(name.to_s, type: :javascript)}")
6
6
  end
7
7
  javascript_include_tag(*sources, **options)
8
8
  end
9
9
 
10
10
  def stylesheet_pack_tag(*names, **options)
11
11
  sources = names.map do |name|
12
- Simpacker.manifest.lookup!("#{name}#{compute_asset_extname(name.to_s, type: :stylesheet)}")
12
+ simpacker_context.manifest.lookup!("#{name}#{compute_asset_extname(name.to_s, type: :stylesheet)}")
13
13
  end
14
14
  stylesheet_link_tag(*sources, **options)
15
15
  end
16
16
 
17
17
  def asset_pack_path(name, **options)
18
- asset_path(Simpacker.manifest.lookup!(name), **options)
18
+ asset_path(simpacker_context.manifest.lookup!(name), **options)
19
19
  end
20
20
 
21
21
  def asset_pack_url(name, **options)
22
- asset_url(Simpacker.manifest.lookup!(name), **options)
22
+ asset_url(simpacker_context.manifest.lookup!(name), **options)
23
23
  end
24
24
 
25
25
  def image_pack_tag(name, **options)
26
- image_tag(asset_path(Simpacker.manifest.lookup!(name)), **options)
26
+ image_tag(asset_path(simpacker_context.manifest.lookup!(name)), **options)
27
+ end
28
+
29
+ def simpacker_context
30
+ Simpacker.default_context
27
31
  end
28
32
  end
29
33
  end
@@ -2,10 +2,10 @@ module Simpacker
2
2
  class Manifest
3
3
  class MissingEntryError < StandardError; end
4
4
 
5
- attr_reader :config
5
+ attr_reader :context
6
6
 
7
- def initialize(config)
8
- @config = config
7
+ def initialize(context)
8
+ @context = context
9
9
  end
10
10
 
11
11
  def lookup(name)
@@ -23,7 +23,7 @@ module Simpacker
23
23
  end
24
24
 
25
25
  def data
26
- if config.cache_manifest?
26
+ if context.config.cache_manifest?
27
27
  @data ||= load
28
28
  else
29
29
  load
@@ -31,8 +31,8 @@ module Simpacker
31
31
  end
32
32
 
33
33
  def load
34
- if config.manifest_path.exist?
35
- JSON.parse(config.manifest_path.read)
34
+ if context.config.manifest_path.exist?
35
+ JSON.parse(context.config.manifest_path.read)
36
36
  else
37
37
  {}
38
38
  end
@@ -1,3 +1,3 @@
1
1
  module Simpacker
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simpacker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuhito Hokamura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-24 00:00:00.000000000 Z
11
+ date: 2019-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -102,6 +102,7 @@ files:
102
102
  - lib/install/template.rb
103
103
  - lib/simpacker.rb
104
104
  - lib/simpacker/configuration.rb
105
+ - lib/simpacker/context.rb
105
106
  - lib/simpacker/helper.rb
106
107
  - lib/simpacker/manifest.rb
107
108
  - lib/simpacker/railtie.rb