assets-publisher-for-hanami 2.0.0
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 +7 -0
- data/.gitignore +7 -0
- data/.rspec +1 -0
- data/.travis.yml +13 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +257 -0
- data/Rakefile +2 -0
- data/assets-publisher-for-hanami.gemspec +33 -0
- data/bin/setup +7 -0
- data/lib/cabeza-de-termo/assets-publisher/assets/asset.rb +81 -0
- data/lib/cabeza-de-termo/assets-publisher/assets/types/asset-type.rb +41 -0
- data/lib/cabeza-de-termo/assets-publisher/assets/types/javascript-type.rb +20 -0
- data/lib/cabeza-de-termo/assets-publisher/assets/types/stylesheet-type.rb +20 -0
- data/lib/cabeza-de-termo/assets-publisher/clock-cards/clock-card-machine.rb +43 -0
- data/lib/cabeza-de-termo/assets-publisher/clock-cards/clock-card.rb +47 -0
- data/lib/cabeza-de-termo/assets-publisher/compilation-jobs/compilation-job.rb +80 -0
- data/lib/cabeza-de-termo/assets-publisher/compilation-jobs/compilation-jobs-builder.rb +52 -0
- data/lib/cabeza-de-termo/assets-publisher/compilation-jobs/one-file-per-asset-builder.rb +66 -0
- data/lib/cabeza-de-termo/assets-publisher/compilers/command-line-compiler.rb +26 -0
- data/lib/cabeza-de-termo/assets-publisher/compilers/compiler.rb +50 -0
- data/lib/cabeza-de-termo/assets-publisher/compilers/tilt-compiler.rb +47 -0
- data/lib/cabeza-de-termo/assets-publisher/configuration/configuration.rb +66 -0
- data/lib/cabeza-de-termo/assets-publisher/errors/asset-not-found-error.rb +12 -0
- data/lib/cabeza-de-termo/assets-publisher/errors/compilation-job-failed-error.rb +14 -0
- data/lib/cabeza-de-termo/assets-publisher/errors/compilation-job-not-supported-error.rb +14 -0
- data/lib/cabeza-de-termo/assets-publisher/errors/error.rb +6 -0
- data/lib/cabeza-de-termo/assets-publisher/errors/unknown-asset-location-error.rb +12 -0
- data/lib/cabeza-de-termo/assets-publisher/helpers/helper.rb +27 -0
- data/lib/cabeza-de-termo/assets-publisher/locations/absolute-location.rb +25 -0
- data/lib/cabeza-de-termo/assets-publisher/locations/location.rb +54 -0
- data/lib/cabeza-de-termo/assets-publisher/locations/source-location.rb +13 -0
- data/lib/cabeza-de-termo/assets-publisher/publisher.rb +142 -0
- data/lib/cabeza-de-termo/assets-publisher/source-finders/assets-finder.rb +44 -0
- data/lib/cabeza-de-termo/assets-publisher/source-finders/assets-source.rb +31 -0
- data/lib/cabeza-de-termo/assets-publisher/version.rb +7 -0
- metadata +191 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ade9157e66ba76611af970ee42bc61d400ae4dbf
|
4
|
+
data.tar.gz: fab9d08054b310d470ea9145242d05ff97ad93ed
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7c7fc21318151e0f491ad4a3c9e28a0e8fe19cbb40f15bae519cc5e18d3199f9e4e15af02b6bd4a0f7e059bbd6ff102a4d3b3d6e0bc57d03c92994f900c20538
|
7
|
+
data.tar.gz: c1642b1873b33193f38e61a6aa2e66d9bc084b0673ed691069c227dbc61c3645d46bebd0711760a7882e5aff3f6d965f4e4eaae23855792dc83878df6c79803f
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require 'spec-helper'
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Martin Rubi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,257 @@
|
|
1
|
+
# CabezaDeTermo::AssetsPublisher::Helper
|
2
|
+
|
3
|
+
A framework to declare bundles of assets in your Hanami application, compile them into a public folder and add them to your template.
|
4
|
+
|
5
|
+
## Status
|
6
|
+
|
7
|
+
[](https://badge.fury.io/rb/assets-publisher-for-hanami)
|
8
|
+
[](https://travis-ci.org/cabeza-de-termo/assets-publisher-for-hanami)
|
9
|
+
[](https://coveralls.io/github/cabeza-de-termo/assets-publisher-for-hanami?branch=master)
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'assets-publisher-for-hanami', '~> 2.0'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install assets-publisher-for-hanami
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
To declare the asset bundles, add this required file to the application.rb file:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'cabeza-de-termo/assets-publisher/helpers/helper'
|
33
|
+
```
|
34
|
+
|
35
|
+
and then add this to your Application class:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
module Web
|
39
|
+
class Application < Hanami::Application
|
40
|
+
configure do
|
41
|
+
...
|
42
|
+
|
43
|
+
# Define the asset bundles.
|
44
|
+
# See https://github.com/cabeza-de-termo/assets-library-for-hanami for more details.
|
45
|
+
CabezaDeTermo::Assets::Library.definition do
|
46
|
+
# Css
|
47
|
+
bundle :'bootstrap-css' do
|
48
|
+
include '/vendor/bootstrap/css/bootstrap.min.css' # include this asset in the bundle
|
49
|
+
end
|
50
|
+
|
51
|
+
# Js
|
52
|
+
bundle :jquery do
|
53
|
+
include '/vendor/jquery/jquery-1.11.3.min.js'
|
54
|
+
end
|
55
|
+
|
56
|
+
bundle :'bootstrap-js' do
|
57
|
+
require :jquery # declare that this bundle depends on the :jquery bundle
|
58
|
+
include '/vendor/bootstrap/js/bootstrap.min.js'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Configure the AssetsPublisher.
|
63
|
+
CabezaDeTermo::AssetsPublisher::Publisher.configure do
|
64
|
+
# Where we want to publish the compiled assets
|
65
|
+
destination_folder 'apps/web/public'
|
66
|
+
|
67
|
+
# Where to look for assets
|
68
|
+
sources << 'apps/web/assets'
|
69
|
+
|
70
|
+
# Optional, true by default.
|
71
|
+
add_timestamps_to_published_assets true
|
72
|
+
|
73
|
+
# Optionally uncomment to define custom compilers. You can also use :command_line_compiler
|
74
|
+
# stylesheets_compiler { CustomCssCompiler.new }
|
75
|
+
# javascripts_compiler { CustomJsCompiler.new }
|
76
|
+
end
|
77
|
+
|
78
|
+
...
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
```
|
83
|
+
|
84
|
+
To define the assets to be included in the layout, you can add these methods to your Web::Views::ApplicationLayout class:
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
module Web
|
88
|
+
module Views
|
89
|
+
class ApplicationLayout
|
90
|
+
...
|
91
|
+
# Define the stylesheet for this layout
|
92
|
+
def layout_stylesheets(assets_collector)
|
93
|
+
assets_collector.require :'bootstrap-css' # include the bundle :'bootstrap-css'
|
94
|
+
assets_collector.include 'layout/layout.css.scss' # include the asset layout.css.scss'
|
95
|
+
end
|
96
|
+
|
97
|
+
# Define the javascripts for this layout
|
98
|
+
def layout_javascripts(assets_collector)
|
99
|
+
assets_collector.require :'bootstrap-js'
|
100
|
+
end
|
101
|
+
...
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
```
|
106
|
+
|
107
|
+
To define the assets to be included in the view, you can add these methods to your Web::Views::SomeView class:
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
module Web::Views::LandingPage
|
111
|
+
class Index
|
112
|
+
include Web::View
|
113
|
+
|
114
|
+
# Define the stylesheet for this view
|
115
|
+
def view_stylesheets(assets_collector)
|
116
|
+
assets_collector.include 'landing-page/landing-page.css.scss'
|
117
|
+
end
|
118
|
+
|
119
|
+
# Define the javascripts for this view
|
120
|
+
def view_javascripts(assets_collector)
|
121
|
+
assets_collector.include 'landing-page/landing-page.js'
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
```
|
126
|
+
|
127
|
+
To collect the assets, add the AssetsPublisher::Helper to your ApplicationLayout:
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
module Web
|
131
|
+
module Views
|
132
|
+
class ApplicationLayout
|
133
|
+
include Web::Layout
|
134
|
+
include CabezaDeTermo::AssetsPublisher::Helper
|
135
|
+
|
136
|
+
...
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
```
|
141
|
+
|
142
|
+
and then use the assets_publisher from your layout template:
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
doctype html
|
146
|
+
html
|
147
|
+
head
|
148
|
+
meta charset="UTF-8"
|
149
|
+
meta name="viewport" content="width=device-width, initial-scale=1"
|
150
|
+
|
151
|
+
/ This will collect, publish and include all your stylesheets required by your layout and view
|
152
|
+
== assets_publisher.stylesheets_for self
|
153
|
+
|
154
|
+
body
|
155
|
+
...
|
156
|
+
|
157
|
+
/ This will collect, publish and include all your javascripts required by your layout and view
|
158
|
+
== assets_publisher.javascripts_for self
|
159
|
+
```
|
160
|
+
## Using custom assets compilers
|
161
|
+
|
162
|
+
By default, Publisher uses a TiltCompiler to compile the assets. But you can change that to use a custom one.
|
163
|
+
|
164
|
+
If you compile the assets by invoking a command line, there is a `command_line_compiler` you can use. In this example we configure the Publisher to use [lesscss](http://lesscss.org/usage/#command-line-usage-command-line-usage) to compile stylesheets and [uglifyjs](https://github.com/mishoo/UglifyJS2) to compile the javascripts. For this to work you must first install those tools of course.
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
CabezaDeTermo::AssetsPublisher::Publisher.configure do
|
168
|
+
...
|
169
|
+
|
170
|
+
stylesheets_compiler {
|
171
|
+
command_line_compiler do |compiler, compilation_job|
|
172
|
+
files_list = compilation_job.source_filenames.join(' ')
|
173
|
+
include_folders = compilation_job.source_folders.join(';')
|
174
|
+
|
175
|
+
compiler.command_line "lessc",
|
176
|
+
"--include-path=#{include_folders}",
|
177
|
+
"--compress",
|
178
|
+
files_list,
|
179
|
+
compilation_job.destination_filename
|
180
|
+
end
|
181
|
+
}
|
182
|
+
|
183
|
+
javascripts_compiler {
|
184
|
+
command_line_compiler do |compiler, compilation_job|
|
185
|
+
files_list = compilation_job.source_filenames.join(' ')
|
186
|
+
compiler.command_line 'uglifyjs', files_list, '--output', compilation_job.destination_filename
|
187
|
+
end
|
188
|
+
}
|
189
|
+
|
190
|
+
...
|
191
|
+
end
|
192
|
+
```
|
193
|
+
|
194
|
+
If you need to write your own compiler, create a class that inherits from [CabezaDeTermo::AssetsPublisher::Compiler](lib/cabeza-de-termo/assets-publisher/compilers/compiler.rb)
|
195
|
+
|
196
|
+
```ruby
|
197
|
+
require 'cabeza-de-termo/assets-publisher/compilers/compiler'
|
198
|
+
|
199
|
+
class CustomCompiler < CabezaDeTermo::AssetsPublisher::Compiler
|
200
|
+
def compile_assets()
|
201
|
+
# you can access which files to compile with
|
202
|
+
compilation_job.source_filenames
|
203
|
+
|
204
|
+
# you can access which file to compile to with
|
205
|
+
compilation_job.destination_filename
|
206
|
+
|
207
|
+
# you can access the assets source folders with
|
208
|
+
compilation_job.source_folders
|
209
|
+
|
210
|
+
# do compile the assets
|
211
|
+
...
|
212
|
+
end
|
213
|
+
end
|
214
|
+
```
|
215
|
+
|
216
|
+
and then configure Publisher to use your custom compiler
|
217
|
+
|
218
|
+
```ruby
|
219
|
+
CabezaDeTermo::AssetsPublisher::Publisher.configure do
|
220
|
+
...
|
221
|
+
stylesheets_compiler { CustomCompiler.new }
|
222
|
+
|
223
|
+
# and/or
|
224
|
+
|
225
|
+
javascripts_compiler { CustomCompiler.new }
|
226
|
+
...
|
227
|
+
end
|
228
|
+
```
|
229
|
+
|
230
|
+
## See also
|
231
|
+
|
232
|
+
* [**Hanami framework**](http://hanamirb.org/) - A complete web framework for Ruby.
|
233
|
+
* [**CabezaDeTermo::Assets::Library**](https://github.com/cabeza-de-termo/assets-library-for-hanami) - A framework to declare bundles of assets in your Hanami application and collect them resolving the dependencies.
|
234
|
+
|
235
|
+
## Running the tests
|
236
|
+
|
237
|
+
- `bundle install`
|
238
|
+
- `bundle exec rspec`
|
239
|
+
|
240
|
+
## Roadmap for v2.1
|
241
|
+
|
242
|
+
- Allow to define different compiling strategies:
|
243
|
+
- One compiled file per asset (for development)
|
244
|
+
- Maybe one compiled file per Action?
|
245
|
+
- One compiled file per application (for production)
|
246
|
+
|
247
|
+
## Roadmap for v2.2
|
248
|
+
|
249
|
+
- Allow the assets_publisher to publish other asset types (images and fonts)
|
250
|
+
|
251
|
+
## Contributing
|
252
|
+
|
253
|
+
1. Fork it ( https://github.com/cabeza-de-termo/assets-publisher-for-hanami/fork )
|
254
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
255
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
256
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
257
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cabeza-de-termo/assets-publisher/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "assets-publisher-for-hanami"
|
8
|
+
spec.version = CabezaDeTermo::AssetsPublisher::Publisher::VERSION
|
9
|
+
spec.authors = ["Martin Rubi"]
|
10
|
+
spec.email = ["martinrubi@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Framework to define and publish assets on your Hanami application.}
|
13
|
+
spec.description = %q{Framework to define and publish assets on your Hanami application.}
|
14
|
+
spec.homepage = "https://github.com/cabeza-de-termo/assets-publisher-for-hanami"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.required_ruby_version = '>= 2.0'
|
23
|
+
|
24
|
+
spec.add_dependency "cdt-utilities", "~> 0.3"
|
25
|
+
spec.add_dependency "assets-library-for-hanami", "~> 3.0"
|
26
|
+
spec.add_dependency "tilt", "~> 2.0"
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
spec.add_development_dependency "sass"
|
31
|
+
spec.add_development_dependency "coffee-script"
|
32
|
+
spec.add_development_dependency "therubyracer"
|
33
|
+
end
|
data/bin/setup
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'cabeza-de-termo/assets-publisher/locations/location'
|
2
|
+
|
3
|
+
require_relative 'types/stylesheet-type'
|
4
|
+
require_relative 'types/javascript-type'
|
5
|
+
|
6
|
+
module CabezaDeTermo
|
7
|
+
module AssetsPublisher
|
8
|
+
# An assets to be included in a template.
|
9
|
+
class Asset
|
10
|
+
# Answer a new asset on the asset_uri.
|
11
|
+
def self.on_uri(asset_type, asset_uri)
|
12
|
+
new(asset_type, asset_uri, Location.from(asset_uri))
|
13
|
+
end
|
14
|
+
|
15
|
+
# Initialize the instance.
|
16
|
+
def initialize(asset_type, asset_uri, location)
|
17
|
+
@uri = Pathname.new(asset_uri)
|
18
|
+
@type = asset_type
|
19
|
+
@location = location
|
20
|
+
@real_path = nil
|
21
|
+
@uri_parameters = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
# Answer the asset uri.
|
25
|
+
def uri()
|
26
|
+
@uri
|
27
|
+
end
|
28
|
+
|
29
|
+
# Answer the asset uri with optional parameters
|
30
|
+
def uri_with_parameters()
|
31
|
+
return uri.to_s if uri_parameters.nil?
|
32
|
+
|
33
|
+
uri.to_s + '?' + URI.escape(uri_parameters)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Answer the asset type
|
37
|
+
def type()
|
38
|
+
@type
|
39
|
+
end
|
40
|
+
|
41
|
+
# Answer the location of the asset
|
42
|
+
def location()
|
43
|
+
@location
|
44
|
+
end
|
45
|
+
|
46
|
+
# Answer the file path of the asset uri.
|
47
|
+
def real_path()
|
48
|
+
@real_path ||= location.real_path_of(uri)
|
49
|
+
end
|
50
|
+
|
51
|
+
def uri_parameters()
|
52
|
+
@uri_parameters
|
53
|
+
end
|
54
|
+
|
55
|
+
def set_uri_parameters(string)
|
56
|
+
@uri_parameters = string
|
57
|
+
self
|
58
|
+
end
|
59
|
+
|
60
|
+
# Answer the html to include this asset in a template
|
61
|
+
def html()
|
62
|
+
type.html_for uri_with_parameters
|
63
|
+
end
|
64
|
+
|
65
|
+
def validate_real_path()
|
66
|
+
raise_asset_not_found_error unless real_path.exist?
|
67
|
+
end
|
68
|
+
|
69
|
+
def modification_time()
|
70
|
+
return :not_found unless real_path.exist?
|
71
|
+
real_path.mtime
|
72
|
+
end
|
73
|
+
|
74
|
+
protected
|
75
|
+
|
76
|
+
def raise_asset_not_found_error()
|
77
|
+
raise AssetNotFoundError.new(uri)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|