fronton 0.3.0 → 0.4.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
  SHA1:
3
- metadata.gz: d8c91394908a4f20e90e8c257a5b26072bc1f547
4
- data.tar.gz: 1a04c819b80d78702d67fd5b79195105467aa6d0
3
+ metadata.gz: 7137692de297bf2d434dfa04d901458b1ba817a2
4
+ data.tar.gz: 0e370701e42502692d1f4520dcda2f4e286f50ab
5
5
  SHA512:
6
- metadata.gz: 848900d19a40c9cc50609cf954aaf1871ce2ee3ddf7600190afc5f72527b4ae4fb4c8d8a4cc44530ee38c4d4da3e46ce855bf840c529d42767e4196c5719d882
7
- data.tar.gz: ef8c1a3bebbc35b8b9e2b84cec6c0c1f2b0eb75405a743d023da4a7a64217dfc54198c06f83143c5dd6b1fefa7f1cb31e9e7a367194883033615aeb98e931d94
6
+ metadata.gz: 421be3479ef525f1ed45d41a2d9e58df611c71f559fa9ed968089cfada432278f863243dcaa98f51898f4e51e021b8d8f081c48ec2e5833d99d1ba617e101d02
7
+ data.tar.gz: 3f7830b8cbd2504440a517e75eb0ea8dfc37d21a4fee516bb92a980b4cce16684f208b47233dac9035ec29e0c2bfcc383f610b3aa33c9779f70e28cb630b9e54
data/README.md CHANGED
@@ -39,13 +39,12 @@ $ gem install fronton
39
39
  ### Config file
40
40
 
41
41
  Configuration options are readed from a `fronton.yml` file located in project
42
- top folder.
42
+ top folder. `application.js`, `application.css` and all non js&css files in
43
+ *assets_paths* are already added.
43
44
 
44
45
  ```yaml
45
46
  assets:
46
- - application.js
47
- - application.css
48
- - "*.png"
47
+ - otherfile.js
49
48
  assets_paths:
50
49
  - assets/javascripts
51
50
  - assets/stylesheets
@@ -72,7 +71,7 @@ pages_paths:
72
71
 
73
72
  | Attribute | Type | Description |
74
73
  | ------------- | ------ | ---------------------------------------------------------- |
75
- | assets | Array | List of assets to compile (only js and css files) |
74
+ | assets | Array | List of assets to compile |
76
75
  | assets_paths | Array | List of directories where Sprockets find files for require |
77
76
  | assets_url | String | URL for assets in production |
78
77
  | compressors | Hash | Hash with selected compressors by type |
data/fronton.gemspec CHANGED
@@ -28,9 +28,10 @@ Gem::Specification.new do |spec|
28
28
  #
29
29
  ## DEPENDENCIES
30
30
  #
31
- spec.add_dependency 'thor', '~> 0.19'
32
- spec.add_dependency 'rack', '~> 2.0'
33
- spec.add_dependency 'sprockets', '~> 3.7'
31
+ spec.add_dependency 'activesupport', '~> 5.0'
32
+ spec.add_dependency 'rack', '~> 2.0'
33
+ spec.add_dependency 'sprockets', '~> 3.7'
34
+ spec.add_dependency 'thor', '~> 0.19'
34
35
 
35
36
  #
36
37
  ## DEVELOPMENT DEPENDENCIES
@@ -2,7 +2,7 @@ module Fronton
2
2
  class AssetsHelpers
3
3
  def initialize(options = {})
4
4
  @use_digest = options.fetch(:digest, false)
5
- @prefix = options.fetch(:prefix, 'assets')
5
+ @prefix = options.fetch(:prefix, '/assets')
6
6
  @manifest = options.fetch(:manifest)
7
7
  end
8
8
 
@@ -18,7 +18,7 @@ module Fronton
18
18
 
19
19
  def asset_path(name)
20
20
  asset_name = @use_digest && @manifest.assets[name] ? @manifest.assets[name] : name
21
- "/#{@prefix}/#{asset_name}"
21
+ File.join(@prefix, asset_name)
22
22
  end
23
23
  end
24
24
  end
data/lib/fronton/cli.rb CHANGED
@@ -48,17 +48,8 @@ module Fronton
48
48
  config.require_dependencies
49
49
 
50
50
  # assets helpers
51
- config.environment.context_class.class_eval do
52
- def asset_path(path, _options = {})
53
- "/assets/#{path}"
54
- end
55
- alias_method :'asset-path', :asset_path
56
-
57
- def asset_url(path, _options = {})
58
- "url(#{asset_path(path)})"
59
- end
60
- alias_method :'asset-url', :asset_url
61
- end
51
+ config.environment.context_class.digest_assets = false
52
+ config.environment.context_class.assets_prefix = '/assets'
62
53
 
63
54
  conf = config
64
55
 
@@ -93,24 +84,9 @@ module Fronton
93
84
  end
94
85
 
95
86
  # assets helpers
96
- config.environment.context_class.class_eval do
97
- class << self
98
- attr_accessor :fronton_config
99
- end
100
-
101
- def asset_path(path, _options = {})
102
- path = self.class.superclass.fronton_config.manifest.assets[path]
103
- "#{self.class.superclass.fronton_config.assets_url}/#{path}"
104
- end
105
- alias_method :'asset-path', :asset_path
106
-
107
- def asset_url(path, _options = {})
108
- "url(#{asset_path(path)})"
109
- end
110
- alias_method :'asset-url', :asset_url
111
- end
112
-
113
- config.environment.context_class.fronton_config = config
87
+ prefix = "#{config.assets_url}/assets"
88
+ config.environment.context_class.digest_assets = true
89
+ config.environment.context_class.assets_prefix = prefix
114
90
 
115
91
  # compile assets
116
92
  config.manifest.compile(config.assets)
@@ -3,11 +3,16 @@ require 'logger'
3
3
  require 'yaml'
4
4
  require 'sprockets'
5
5
  require 'fronton/dependency'
6
+ require 'fronton/context'
6
7
 
7
8
  module Fronton
8
9
  class Config
9
10
  class YAMLNotFound < StandardError; end
10
11
 
12
+ PRECOMPILE_CRITERIA = lambda do |logical_path, filename|
13
+ filename.start_with?(Dir.pwd) && !['.js', '.css', ''].include?(File.extname(logical_path))
14
+ end
15
+
11
16
  def self.load!
12
17
  file = Pathname.pwd.join('fronton.yml')
13
18
 
@@ -29,7 +34,10 @@ module Fronton
29
34
  #
30
35
 
31
36
  def assets
32
- @assets ||= @config['assets'].is_a?(Array) ? @config['assets'] : []
37
+ @assets ||= begin
38
+ assets_conf = @config['assets'].is_a?(Array) ? @config['assets'] : []
39
+ [PRECOMPILE_CRITERIA, /(?:\/|\\|\A)application\.(css|js)$/] + assets_conf
40
+ end
33
41
  end
34
42
 
35
43
  def assets_paths
@@ -43,7 +51,7 @@ module Fronton
43
51
  end
44
52
 
45
53
  def assets_url
46
- @config['assets_url'] || '/assets'
54
+ @config['assets_url']
47
55
  end
48
56
 
49
57
  def output
@@ -109,6 +117,9 @@ module Fronton
109
117
  RailsAssets.load_paths.each { |path| env.append_path path }
110
118
  end
111
119
 
120
+ # context helpers
121
+ env.context_class.send :include, ::Fronton::Context
122
+
112
123
  env
113
124
  end
114
125
  end
@@ -0,0 +1,22 @@
1
+ module Fronton
2
+ module Context
3
+ def self.included(klass)
4
+ klass.class_eval do
5
+ class_attribute :assets_prefix, :digest_assets
6
+ end
7
+ end
8
+
9
+ def asset_url(path, _options = {})
10
+ "url(#{asset_path(path)})"
11
+ end
12
+ alias_method :'asset-url', :asset_url
13
+
14
+ def asset_path(path, _options = {})
15
+ asset = link_asset(path)
16
+ digest_path = asset.digest_path
17
+ path = digest_path if digest_assets
18
+ File.join(assets_prefix || "/", path)
19
+ end
20
+ alias_method :'asset-path', :asset_path
21
+ end
22
+ end
@@ -1,8 +1,8 @@
1
1
  module Fronton
2
2
  module VERSION
3
3
  MAJOR = 0
4
- MINOR = 3
5
- TINY = 0
4
+ MINOR = 4
5
+ TINY = 1
6
6
  PRE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
data/lib/fronton.rb CHANGED
@@ -1,2 +1,3 @@
1
+ require 'active_support/core_ext/class/attribute'
1
2
  require 'fronton/version'
2
3
  require 'fronton/cli'
data/template/fronton.yml CHANGED
@@ -1,7 +1,5 @@
1
1
  assets:
2
- - application.js
3
- - application.css
4
- - "*.png"
2
+ - otherfile.js
5
3
  assets_paths:
6
4
  - assets/javascripts
7
5
  - assets/stylesheets
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fronton
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Aranda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-22 00:00:00.000000000 Z
11
+ date: 2016-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: thor
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.19'
19
+ version: '5.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.19'
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rack
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.19'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.19'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: coveralls
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -139,6 +153,7 @@ files:
139
153
  - lib/fronton/assets_helpers.rb
140
154
  - lib/fronton/cli.rb
141
155
  - lib/fronton/config.rb
156
+ - lib/fronton/context.rb
142
157
  - lib/fronton/dependency.rb
143
158
  - lib/fronton/html_server.rb
144
159
  - lib/fronton/page.rb
@@ -175,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
190
  version: '0'
176
191
  requirements: []
177
192
  rubyforge_project:
178
- rubygems_version: 2.6.6
193
+ rubygems_version: 2.5.1
179
194
  signing_key:
180
195
  specification_version: 4
181
196
  summary: A command-line tool for build frontend apps in Ruby