bankrupt 1.0.1 → 1.1.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: c1066b8121da3f5726a31be61952c112cc2c5d64cf4e91019d909cc9100f75ae
4
- data.tar.gz: 78cbc3ae291c15de955f27ff089f382809554ad833361d2e5dbb2c244400389d
3
+ metadata.gz: 1dca115afeb3234502a119751813a7ae7e0d17ea19a7f0051386544211998eed
4
+ data.tar.gz: c72b72acc9233dbd5e096896c42649953d3c1bc8facf2ceff649d7d5eb6deae7
5
5
  SHA512:
6
- metadata.gz: 26e105875958d34753883d28fdb96d9c91e40b3a7a2757051e5efcf6b76e3de2076266eda8d4ca295fc3200389b90d7fedb5a229e2ee1bee0ee4cd1f920dffbb
7
- data.tar.gz: af535617117071175fcc6c241c72d2874977f0a8c977ef5bd37ea7924f22c5b1857be5713dc8376cc695c5508c5624703e4ca5eca4476c3051c9942b9e11d0ac
6
+ metadata.gz: 3242ca78af837ea8979f1ad3b0ca329a88f1fe10716fa18ad0607173c0648090b1b3824fc58a087b4723277b1f6f1aa7b02806b3015f3ce1c51b054b8895cbf2
7
+ data.tar.gz: 7c9c0c97bb5d5ccf6b7c25d15053d8ea932d3ee6b7f8d728ef51e7e3b117f4003267bbc67ef6aa636d3bc76e7d38cb8b2d38771dce4e07152c8f1e94f070dd92
@@ -20,4 +20,4 @@ Metrics/MethodLength:
20
20
  Max: 15
21
21
 
22
22
  RSpec/NestedGroups:
23
- Max: 5
23
+ Max: 6
@@ -3,6 +3,10 @@
3
3
  This file keeps track of changes between releases for the bankrupt project
4
4
  which adheres to [semantic versioning](https://semver.org).
5
5
 
6
+ ## v1.1.0 2019-06-05
7
+
8
+ Add support for `img` tags along with the ability to add other attributes.
9
+
6
10
  ## v1.0.1 2018-12-30
7
11
 
8
12
  Add support for slim v4.
data/README.md CHANGED
@@ -42,6 +42,29 @@ class App < Sinatra::Base
42
42
  end
43
43
  ```
44
44
 
45
+ Now, in your views you can use the helper methods:
46
+
47
+ ```slim
48
+ == stylesheet('app.css')
49
+ ```
50
+
51
+ In development mode it will load app.css from your local public directory but
52
+ in production it will load the CDN URL and include integrity hashes and
53
+ anonymous crossorigin attributes.
54
+
55
+ There's also a helper for `script` tags:
56
+
57
+ ```slim
58
+ == javascript('app.js')
59
+ ```
60
+
61
+ For images you can optionally pass a hash of options to apply additional
62
+ attributes to the image:
63
+
64
+ ```slim
65
+ == image(img.jpg, alt: 'img')
66
+ ```
67
+
45
68
  ### Rake
46
69
 
47
70
  You can use the bundled rake task to generate the manifest file in the correct
@@ -84,6 +107,34 @@ task default: if ENV['CLOUDBUILD'].to_s.casecmp?('true')
84
107
  end
85
108
  ```
86
109
 
110
+ ### Rspec
111
+
112
+ If you're testing your app with rspec or similar you need to stub the `CDN` and
113
+ `ASSETS` constants.
114
+
115
+ ```ruby
116
+ require 'rack/test'
117
+
118
+ RSpec.describe App do
119
+ include Rack::Test::Methods
120
+
121
+ before do
122
+ stub_const('CDN', '')
123
+ stub_const('ASSETS', {})
124
+ end
125
+
126
+ let(:app) { described_class }
127
+
128
+ describe 'GET /' do
129
+ before { get '/' }
130
+
131
+ it 'returns a 200' do
132
+ expect(last_response).to be_ok
133
+ end
134
+ end
135
+ end
136
+ ```
137
+
87
138
  ## License
88
139
 
89
140
  ```
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2018 Mario Finelli
3
+ # Copyright 2018-2019 Mario Finelli
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -21,6 +21,14 @@ require 'slim'
21
21
  module Bankrupt
22
22
  ASSET = Struct.new(:path, :sri).freeze
23
23
 
24
+ IMAGE_CDN = <<~SLIM
25
+ img crossorigin='anonymous' src=path
26
+ SLIM
27
+
28
+ IMAGE_LOCAL = <<~SLIM
29
+ img src=path
30
+ SLIM
31
+
24
32
  JAVASCRIPT_CDN = <<~SLIM
25
33
  script crossorigin='anonymous' integrity=sri src=path
26
34
  SLIM
@@ -37,6 +45,24 @@ module Bankrupt
37
45
  link href=path rel='stylesheet'
38
46
  SLIM
39
47
 
48
+ # Return an image html tag for the asset.
49
+ #
50
+ # @todo we compute the options on every call, we should do the
51
+ # lookup first and short circuit
52
+ # @todo lookup needs to be based on path _and_ options so that the
53
+ # same asset can be used in multiple places with e.g. different
54
+ # css classes applied
55
+ #
56
+ # @param path [String] relative (from public) path to the img
57
+ # @param options [Hash] additional attributes to add to the img tag
58
+ # @return [String] image html element
59
+ def image(path, options = {})
60
+ o = Hash(options).map { |k, v| "#{k}='#{v}'" }.join(' ')
61
+
62
+ asset_html(path, [IMAGE_CDN.chomp, o].join(' '),
63
+ [IMAGE_LOCAL.chomp, o].join(' '))
64
+ end
65
+
40
66
  # Return a javascript html tag for the asset.
41
67
  #
42
68
  # @param path [String] relative (from public) path to the js
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2018 Mario Finelli
3
+ # Copyright 2018-2019 Mario Finelli
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -15,5 +15,5 @@
15
15
  # limitations under the License.
16
16
 
17
17
  module Bankrupt
18
- VERSION = '1.0.1'
18
+ VERSION = '1.1.0'
19
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bankrupt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Finelli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-30 00:00:00.000000000 Z
11
+ date: 2019-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slim
@@ -196,8 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
196
  - !ruby/object:Gem::Version
197
197
  version: '0'
198
198
  requirements: []
199
- rubyforge_project:
200
- rubygems_version: 2.7.7
199
+ rubygems_version: 3.0.3
201
200
  signing_key:
202
201
  specification_version: 4
203
202
  summary: A sinatra helper to load assets locally and production.