hype_assets 0.0.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62ec5f515f9341a1f3e50f24dda60caf22b6de88
4
- data.tar.gz: b0163cd6546514e59de9bd6870ba663691aa8c3e
3
+ metadata.gz: c7acb9c7f81fbd8a18575cbb371437c47c7c4fb4
4
+ data.tar.gz: a804499a07bb63c5617beb2d7389018c55a01cc1
5
5
  SHA512:
6
- metadata.gz: 940d55c356cac5484ecb04b13ffcf272a35510a3803b29ba320eb3ca59619097d17fe29f13ee6f8261f2036369d85520d7e838e77dca6851904763b32eaeb6a7
7
- data.tar.gz: e16e279278724026325a28e9d956a2da2875c0351462954e8ccba98bd23806b47eab9e51d4e354a514bc40c8587bb4a53c64a07bc185195d1d7c24b950a7f6f0
6
+ metadata.gz: f6ce05ab03ad7e33140f2f35c9796552263231adc7e6bfecc52d0e2a4a53a197610e7ab7c9cc6dce2bc037cae566659d425c21588af1767d4ddac5c1e20eea7e
7
+ data.tar.gz: 3846db8d4ca2b883c868609174bc6fa7de36fafa6c54c5c5df47441544b0b4c32dd29722cf9133ed5c98fe60aa835dc3121a4dd7225db0cef9aa66f91a5bf89f
data/CHANGELOG.md ADDED
@@ -0,0 +1,30 @@
1
+ # CHANGELOG
2
+
3
+
4
+ ## 0.1.0 2016-03-20
5
+ * Milestone: The basic idea is implemented!
6
+ You can now add your .hyperesource folders into the assets folder,
7
+ renaming the hype_generated_script.js to hype_generated_script.js.hype,
8
+ and we handle the rest: precompiling, registering the handler, and
9
+ Rails pipelining the hype_generated_script.js image references.
10
+
11
+
12
+ ## 0.0.3 2016-03-20
13
+ * Add the Hype scripts to the the Rails assets precompile array.
14
+ This unfortunately binds us to Rails. I was hoping to be
15
+ Framework-agnostic, being generically Sprockets, but Sprockets
16
+ alone doesn't seem to have a pre-compile concept, AFAICT.
17
+
18
+
19
+ ## 0.0.2 2016-03-17
20
+ * Ensure we have the digested version of the filename, by calling find_asset()
21
+
22
+
23
+ ## 0.0.1 2016-03-16
24
+ * Switch from Sprockets 2.x-style Tilt interface to 3.x-style Rack interface
25
+ * Record the version/timestamp in the .js output and the logs
26
+
27
+
28
+ ## 0.0.0 2016-03-15
29
+ * initial implementation of preprocessor
30
+ * registers .hype files with Sprockets
data/LICENSE.txt ADDED
@@ -0,0 +1,25 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Noach Magedman
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+ Text copied from http://choosealicense.com/licenses/mit/
25
+ See also https://opensource.org/licenses/MIT
data/README.md CHANGED
@@ -1,8 +1,12 @@
1
1
  # HypeAssets
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/hype_assets`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ HypeAssets provides Rails Asset Pipeline integration for Tumult Hype animations.
4
+
5
+ [Tumult Hype] (http://tumult.com/hype/) is a tool for producing animations and interactive content implemented as HTML5 javascripts and images. Integrating these into the Rails Asset Pipeline (aka Sprockets) would enable serving these resources from a CDN and versioning them with Digest Fingerprinting. That integration is, unfortunately, difficult to do. Rails expects that all file references be encapsulated with asset_path() calls within ERB tags, while Tumult Hype produces a minified javascript file containing image filenames that are concatenated onto a base URL.
6
+
7
+ HypeAssets makes Rails Asset Pipeline integration easy by automatically modifying the foo_hype_generated_script.js file with the correct file references.
8
+
4
9
 
5
- TODO: Delete this and the text above, and describe your gem
6
10
 
7
11
  ## Installation
8
12
 
@@ -16,21 +20,32 @@ And then execute:
16
20
 
17
21
  $ bundle
18
22
 
19
- Or install it yourself as:
20
23
 
21
- $ gem install hype_assets
22
24
 
23
25
  ## Usage
24
26
 
25
- TODO: Write usage instructions here
27
+ 1. Create a folder for your hype animations. I recommend `app/assets/hype`, but any folder in your assets search path will do.
28
+
29
+ 2. Copy your `foo.hyperesources` folders into that folder.
30
+
31
+ 3. Append a `.hype` extension to your hype scripts:
26
32
 
27
- ## Development
33
+ $ cd app/assets/hype/foo.hyperesources
34
+ $ mv foo_hype_generated_script.js foo_hype_generated_script.js.hype
35
+
36
+ NOTE: Do NOT rename your other javascript files, e.g. HYPE-123.full.min.js.
37
+
38
+ 4. In your HTML, reference your hype animation script with
39
+
40
+ <%= javascript_include_tag "foo.hyperesources/foo_hype_generated_script.js" %>
28
41
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
42
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
43
 
33
44
  ## Contributing
34
45
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hype_assets.
46
+ Bug reports, pull requests, and general feedback are welcome on GitHub at https://github.com/nmagedman/hype_assets/issues.
47
+
48
+
49
+ ## License
36
50
 
51
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/hype_assets.gemspec CHANGED
@@ -9,9 +9,10 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Noach Magedman"]
10
10
  spec.email = ["nmagedman@gmail.com"]
11
11
 
12
- spec.summary = %q{Integrate Tumult Hype animation files into the Asset Pipeline}
12
+ spec.summary = %q{Integrate Tumult Hype animation files into the Rails Asset Pipeline}
13
13
  spec.description = %q{Append `.hype` to your hype_generated_script.js and we take care of the rest!}
14
14
  spec.homepage = "https://github.com/nmagedman/hype_assets"
15
+ spec.license = "MIT"
15
16
 
16
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
18
  spec.bindir = "exe"
@@ -22,8 +23,6 @@ Gem::Specification.new do |spec|
22
23
  spec.add_development_dependency "rake", "~> 10.0"
23
24
  spec.add_development_dependency "rspec", "~> 3.0"
24
25
 
25
- ### Tilt has been DEPRECATED. NOW they tell me.....
26
- spec.add_runtime_dependency 'tilt', '~> 2.0' # baseclass for Sprockets preprocessors
27
-
28
26
  spec.add_runtime_dependency 'sprockets', '~> 3.0'
27
+ spec.add_runtime_dependency 'rails', '~> 4.0'
29
28
  end
@@ -1,32 +1,19 @@
1
- require 'tilt'
2
-
3
- class HypeAssets::HypeTemplate < ::Tilt::Template
4
-
5
- def asset_url (resource)
6
- ### Wrapper function around the Sprockets helper,
7
- ### since it's not clear how best to invoke it.
8
- ApplicationController.helpers.asset_url resource
9
- end
10
-
11
-
12
- def prepare
13
- ## Apparently this *must* be defined explicitly.
14
- ## There is no default no-op implementation.
15
- end
16
-
17
-
18
- def evaluate (scope, locals)
19
- ## The original *_hype_generated_script.js.hype file is
20
- ## slurped into `data`, defined by ::Tilt::Template.
21
- ## Massage it to include the digested/CDN'd filenames,
22
- ## and return it.
23
-
1
+ class HypeAssets::HypeTemplate
2
+
3
+ def self.call (input)
4
+ ### Massage the raw foo.hyperesources/foo_hype_generated_script.js.hype file
5
+ ### to use digested filenames, stored potentially on a CDN.
6
+ ### @input [Hash] See http://www.rubydoc.info/gems/sprockets/3.5.2#Processor_Interface
7
+ ### for a description of input's fields.
8
+ ### @returns [String or Hash] see sprockets README
9
+ puts "HypeAssets: Processing #{input[:name]} @ #{Time.now}"
10
+ hype_script = input[:data]
24
11
  folder = nil
25
12
 
26
13
  ## THE BASE URL:
27
14
  ## Replace: var f="animation_name.hyperesources"
28
15
  ## With: var f="https://my.cdn.com/assets/animation_name.hyperesources"
29
- data.sub!(/var f="([^"]+)"/) {
16
+ hype_script.sub!(/var f="([^"]+)"/) {
30
17
  folder = $1
31
18
  ## TODO: Don't hardcode `assets`. Get it dynamically from the config.
32
19
  path = asset_url "assets/#{folder}"
@@ -37,7 +24,7 @@ class HypeAssets::HypeTemplate < ::Tilt::Template
37
24
  ## The HYPE Library:
38
25
  ## Replace: "HYPE-466.full.min.js":"HYPE-466.thin.min.js"
39
26
  ## With: "HYPE-466.full.min-1234567890abcdef.js":"HYPE-466.thin.min-1234567890abcdef.js"
40
- data.sub!(/"(HYPE-\d+.full.min.js)":"(HYPE-\d+.thin.min.js)"/) {
27
+ hype_script.sub!(/"(HYPE-\d+.full.min.js)":"(HYPE-\d+.thin.min.js)"/) {
41
28
  full = digested_asset_filename "#{folder}/#{$1}"
42
29
  thin = digested_asset_filename "#{folder}/#{$2}"
43
30
  %Q["#{full}":"#{thin}"]
@@ -55,16 +42,16 @@ class HypeAssets::HypeTemplate < ::Tilt::Template
55
42
  ## For example, all the filenames are grouped together in a hash which is the third
56
43
  ## argument to `new HYPE_466()`. Of course, that could change from version to version
57
44
  ## of Hype!
58
- data.gsub!(/\bn:"([^"]+\.[^"]+)"/) {
45
+ hype_script.gsub!(/\bn:"([^"]+\.[^"]+)"/) {
59
46
  n = digested_asset_filename "#{folder}/#{$1}"
60
47
  %Q[n:"#{n}"]
61
48
  }
62
49
 
63
- "// Pre-Processed with HypeAssets::HypeTemplate\n" + data
50
+ "// Pre-Processed with HypeAssets v#{::HypeAssets::VERSION} @ #{Time.now}\n#{hype_script}"
64
51
  end
65
52
 
66
53
 
67
- def digested_asset_filename (resource)
54
+ def self.digested_asset_filename (resource)
68
55
  ### @returns the digested version of an asset's filename.
69
56
  ### It returns *just* the filename itself (i.e. the basename),
70
57
  ### since Hype's script internally concatenates the filename
@@ -73,18 +60,25 @@ class HypeAssets::HypeTemplate < ::Tilt::Template
73
60
  ### Incidentally, it encodes `@`, even though this is a safe character, AFAICT.
74
61
  ### URI.encode does *not* re-encode the `@`, but that doesn't seem to break things.
75
62
 
76
- ## Not sure which code arrangement is easiest to read:
63
+ decoded_resource = URI.decode resource
64
+ digested_path = digest_path decoded_resource
65
+ basename = File.basename digested_path
66
+ re_encoded_name = URI.encode basename
67
+ end
77
68
 
78
- ## Individual steps:
79
- # decoded_resource = URI.decode resource
80
- # path = ApplicationHelper.asset_path decoded_resource
81
- # basename = File.basename path
82
- # re_encoded_name = URI.encode basename
83
69
 
84
- ## Chained:
85
- # URI.encode(File.basename(asset_url(URI.decode(resource))))
70
+ def self.asset_url (resource)
71
+ ### Wrapper function around the Sprockets helper,
72
+ ### since it's not clear how best to invoke it.
73
+ ApplicationController.helpers.asset_url resource
74
+ end
75
+
86
76
 
87
- ## Chained without parens:
88
- URI.encode File.basename asset_url URI.decode resource
77
+ def self.digest_path (resource)
78
+ ### Wrapper function around the Sprockets helper,
79
+ ### since it's not clear how best to invoke it.
80
+ ## To ensure we have the digested version of the filename,
81
+ ## we have to load the Sprockets::Asset into memory.
82
+ Rails.application.assets.find_asset(resource).digest_path
89
83
  end
90
84
  end
@@ -1,3 +1,6 @@
1
1
  module HypeAssets
2
- VERSION = "0.0.0"
2
+ VERSION = "0.1.0"
3
3
  end
4
+
5
+
6
+ ## TODO: Find a way to force a recompile of the *.hype files whenever HypeAssets::VERSION is bumped
data/lib/hype_assets.rb CHANGED
@@ -1,6 +1,14 @@
1
1
  require "hype_assets/version"
2
2
  require "hype_assets/hype_template"
3
3
  require "sprockets"
4
+ require "rails"
4
5
 
5
- Sprockets::Engines #force autoloading. Necessary?
6
+
7
+ ## Register *_hype_generated_script.js.hype files to be processed by us
6
8
  Sprockets.register_engine '.hype', ::HypeAssets::HypeTemplate
9
+
10
+ ## Add hype files (`*.hyperesources/*.js`) to assets precompile array
11
+ Rails::Application.initializer "hype_assets" do
12
+ Rails.logger.info "HypeAssets: Adding hype files (`*.hyperesources/*.js`) to assets precompile array"
13
+ Rails.application.config.assets.precompile += %w[ *.hyperesources/*.js ]
14
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hype_assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noach Magedman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-15 00:00:00.000000000 Z
11
+ date: 2016-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,33 +53,33 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: tilt
56
+ name: sprockets
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.0'
61
+ version: '3.0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '2.0'
68
+ version: '3.0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: sprockets
70
+ name: rails
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '3.0'
75
+ version: '4.0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '3.0'
82
+ version: '4.0'
83
83
  description: Append `.hype` to your hype_generated_script.js and we take care of the
84
84
  rest!
85
85
  email:
@@ -91,7 +91,9 @@ files:
91
91
  - ".gitignore"
92
92
  - ".rspec"
93
93
  - ".travis.yml"
94
+ - CHANGELOG.md
94
95
  - Gemfile
96
+ - LICENSE.txt
95
97
  - README.md
96
98
  - Rakefile
97
99
  - bin/console
@@ -101,7 +103,8 @@ files:
101
103
  - lib/hype_assets/hype_template.rb
102
104
  - lib/hype_assets/version.rb
103
105
  homepage: https://github.com/nmagedman/hype_assets
104
- licenses: []
106
+ licenses:
107
+ - MIT
105
108
  metadata: {}
106
109
  post_install_message:
107
110
  rdoc_options: []
@@ -122,5 +125,5 @@ rubyforge_project:
122
125
  rubygems_version: 2.5.1
123
126
  signing_key:
124
127
  specification_version: 4
125
- summary: Integrate Tumult Hype animation files into the Asset Pipeline
128
+ summary: Integrate Tumult Hype animation files into the Rails Asset Pipeline
126
129
  test_files: []