hype_assets 0.1.3 → 0.2.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: b00ade57237e52fa9d1e5d825d26764fb2db8608
4
- data.tar.gz: d1a88def8bf8b20ae2f3701daebf9337037b342d
3
+ metadata.gz: 5e73d28dec85b95e5a21604c67afbbee50165cf0
4
+ data.tar.gz: 2641f8ae58b6e025a6d8c7f7aff0fa43a7639da5
5
5
  SHA512:
6
- metadata.gz: f44868b120e819bf472f0eec3c08c47511b68fc55c0beffbaa5c011ff6c84c49874543300b17b2eb040c9453177574dc5a9a5963b75f8b06617f114e1d4dc502
7
- data.tar.gz: b3cf8254661f932d77f0d4abe4b645159627463f2595202a0f53079c27568966d215492d253729ebd759abd66a53be9cbeb776243b7248a17e60dad7f8326e7e
6
+ metadata.gz: 776362fdb6abc047284f35f4cce7ea2bfe7e9c45dd9ea0f5870b30bc0fd27f7f103cd3367ebd5b89035fe3c5189476070dd1efe965b5b3419ca448f1c01ea64f
7
+ data.tar.gz: 58f724f9b1c2008e1f36dd211e409c7b2e5bf83a86aba9aa3e2415b73a76168706f8d00d1868b242b60c287e485c1e6309d485fbef8b310cea3016e072d90efa
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.2.0 2016-04-03
4
+ * Issue #3: Support HYPE-5xx scripts. i.e. Avoid relying on specific
5
+ variable names in the hype_generated_script
6
+ * Issue #1: Support embedded fonts
7
+
8
+
3
9
  ## 0.1.3 2016-03-28
4
10
  * Issue #4: Don't hardcode `assets`. Get it dynamically from the config.
5
11
  OK, we're using Sprockets directly now (not Rails). The docs
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # HypeAssets
2
2
 
3
- HypeAssets provides Rails Asset Pipeline integration for Tumult Hype animations.
3
+ HypeAssets provides Rails Asset Pipeline integration for Tumult Hype 3 animations.
4
4
 
5
5
  [Tumult Hype](http://tumult.com/hype/) is a tool for producing animations and
6
6
  interactive content implemented as HTML5 javascripts and images. Integrating these
@@ -19,6 +19,12 @@ that are each concatenated client-side onto a single base URL.
19
19
  HypeAssets makes Rails Asset Pipeline integration easy by automatically modifying the foo_hype_generated_script.js file with the correct file references.
20
20
 
21
21
 
22
+ ## Requirements
23
+ HypeAssets is designed to work with animations built with Tumult Hype version 3, using HYPE-4xx or HYPE-5xx runtime scripts. (It has been tested with HYPE-456, HYPE-466, and HYPE-526.)
24
+
25
+ It also requires Sprockets 3.x, as they redesigned their asset processor API.
26
+
27
+
22
28
  ## Installation
23
29
 
24
30
  Add this line to your application‘s Gemfile:
@@ -60,6 +66,8 @@ And then execute:
60
66
 
61
67
  Bug reports, pull requests, and general feedback are welcome on GitHub at https://github.com/nmagedman/hype_assets/issues.
62
68
 
69
+ If your hype animation works when run from a static page but fails when run via HypeAssets, please send me a zip of the `foo.hyperesources` folder and a `foo.html` container page. Attach it to the github issue or email it to `nmagedman+hype@gmail.com`.
70
+
63
71
 
64
72
  ## License
65
73
 
data/hype_assets.gemspec CHANGED
@@ -19,10 +19,10 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.11"
23
- spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_development_dependency "rspec", "~> 3.0"
22
+ spec.add_development_dependency "bundler", ">= 1.11"
23
+ spec.add_development_dependency "rake", ">= 10.0"
24
+ spec.add_development_dependency "rspec", ">= 3.0"
25
25
 
26
- spec.add_runtime_dependency 'sprockets', '~> 3.0'
26
+ spec.add_runtime_dependency 'sprockets', '~> 3.0' # 2.x used the Tilt interface
27
27
  spec.add_runtime_dependency 'rails', '~> 4.0'
28
28
  end
@@ -24,7 +24,8 @@ class HypeAssets::HypeTemplate
24
24
  hype_script = input[:data]
25
25
  sprockets = input[:environment]
26
26
  dependencies = Set.new(input[:metadata][:dependencies]) # may be nil
27
- folder = nil
27
+ folder = nil # => animation_name.hyperesources
28
+ base_url = nil # => https://my.cdn.com/assets/animation_name.hyperesources
28
29
 
29
30
  sprockets.logger.info "HypeAssets: Processing #{input[:name]} @ #{Time.now}"
30
31
 
@@ -32,45 +33,82 @@ class HypeAssets::HypeTemplate
32
33
  ## THE BASE URL:
33
34
  ## Replace: var f="animation_name.hyperesources"
34
35
  ## With: var f="https://my.cdn.com/assets/animation_name.hyperesources"
35
- hype_script.sub!(/var f="([^"]+)"/) {
36
+ ## NOTE: In HYPE-4xx this variable was called f. In HYPE-5xx it's called h.
37
+ ## We should be varname agnostic. In any case, it is the first (and only?)
38
+ ## instance of a string ending in `.hyperesources`.
39
+ ## We can assume that it will continue to be a variable assignment.
40
+ hype_script.sub!(/="([^"]+\.hyperesources)"/) {
36
41
  folder = $1
42
+
37
43
  asset_host = sprockets.context_class.config.asset_host # shouldn't end in /
38
44
  prefix = sprockets.context_class.assets_prefix # begins with /
39
-
40
- url = "#{asset_host}#{prefix}/#{folder}"
41
- %Q[var f="#{url}"]
45
+ base_url = "#{asset_host}#{prefix}/#{folder}"
46
+ %Q[="#{base_url}"]
42
47
  }
43
48
 
44
49
 
45
50
  ## The HYPE Library:
46
- ## Replace: "HYPE-466.full.min.js":"HYPE-466.thin.min.js"
47
- ## With: "HYPE-466.full.min-1234567890abcdef.js":"HYPE-466.thin.min-1234567890abcdef.js"
48
- hype_script.sub!(/"(HYPE-\d+.full.min.js)":"(HYPE-\d+.thin.min.js)"/) {
49
- full = digested_asset_filename "#{folder}/#{$1}", dependencies, sprockets
50
- thin = digested_asset_filename "#{folder}/#{$2}", dependencies, sprockets
51
- %Q["#{full}":"#{thin}"]
51
+ ## Replace: ?"HYPE-466.full.min.js":"HYPE-466.thin.min.js"
52
+ ## With: ?"HYPE-466.full.min-1234567890abcdef.js":"HYPE-466.thin.min-1234567890abcdef.js"
53
+ hype_script.sub!(/\?"(HYPE-\d+.full.min.js)":"(HYPE-\d+.thin.min.js)"/) {
54
+ full = digested_asset_filename $1, folder, dependencies, sprockets
55
+ thin = digested_asset_filename $2, folder, dependencies, sprockets
56
+ %Q[?"#{full}":"#{thin}"]
52
57
  }
53
58
 
54
59
 
55
60
  ## INDIVIDUAL FILENAMES:
56
61
  ## Replace: n:"my_image.png"
57
62
  ## With: n:"my_image-1234567890abcdef.png"
58
- ## TODO: A big difficulty here is choosing which instances of `n:""` to modify:
59
- ## n is used both for filenames and for free-form, scene names.
60
- ## Currently, I assume the filenames have a dot (reasonable, because they have extensions)
61
- ## and that scene names do not (not so reasonable, since a human types them in).
62
- ## With tighter pattern matching, we may be able to support scene-names containing dots.
63
- ## For example, all the filenames are grouped together in a hash which is the third
64
- ## argument to `new HYPE_466()`. Of course, that could change from version to version
65
- ## of Hype!
66
- hype_script.gsub!(/\bn:"([^"]+\.[^"]+)"/) {
67
- n = digested_asset_filename "#{folder}/#{$1}", dependencies, sprockets
68
- %Q[n:"#{n}"]
63
+ ##
64
+ ## We should be varname agnostic, as Tumult might rename the hash keys.
65
+ ## That means we will be checking every hash value string to see if it's
66
+ ## a file. Only consider strings that _look_ like filenames.
67
+ ## And tolerate failed lookups gracefully -- treat them as non-file strings.
68
+ hype_script.gsub!(/(^|[,{])(\w+):"([\w\-%]++\.[\w\-%.]++)"/) {
69
+ preamble = $1 # a hashkey will only follow a curly brace, comma, or newline
70
+ hashkey = $2
71
+ filename = $3 # Hype URL-encodes pretty agressively. Must have 1+ dots.
72
+
73
+ daf = digested_asset_filename filename, folder, dependencies, sprockets
74
+ if daf
75
+ %Q[#{preamble}#{hashkey}:"#{daf}"]
76
+ else
77
+ $& # if anything goes wrong, just leave everything untouched.
78
+ end
69
79
  }
70
80
 
71
- hype_script = "// Pre-Processed with HypeAssets v#{::HypeAssets::VERSION} @ #{Time.now}\n #{hype_script}"
81
+ ## CSS FONT-FACE DATA:
82
+ ## Replace: url('animation_name.hyperesources/custom_font.svg#fontname')
83
+ ## With: url('https://my.cdn.com/assets/animation_name.hyperesources/custom_font-12345.svg#fontname')
84
+ ## The CSS `<style>` tag and its content are inserted into the page dynamically.
85
+ ## The code is apparently typed into the Hype editor manually
86
+ ## (although I couldn't find it).
87
+ ## So realize that the syntax will be more inconsistent than the rest of the file.
88
+ ## e.g. url() strings may be single-quoted, double-quoted, or not quoted at all.
89
+ ## Nonetheless, the entire injected content is stored as a double-quoted string,
90
+ ## so "whitespace" (other than spaces) will appear as \t, \n, or \r.
91
+ ##
92
+ ## For now, the only URL path we will support is `foo.hyperesources/filename`
93
+ hype_script.gsub!(
94
+ /(\b|\\[tnr])url\(('|\\")?#{Regexp.quote folder}\/([\w\-%.]++)([?#].*?)?\2\)/
95
+ ) {
96
+ preamble = $1 # leading whitespace
97
+ quote = $2 # single, double, or nothing
98
+ filename = $3 # URL-encoded?
99
+ extra_junk = $4 # svg fonts need a #fontname fragment. And IE needs a hack, of course.
100
+
101
+ daf = digested_asset_filename filename, folder, dependencies, sprockets
102
+ if daf
103
+ %Q[#{preamble}url(#{quote}#{base_url}/#{daf}#{extra_junk}#{quote})]
104
+ else
105
+ $& # if anything goes wrong, just leave everything untouched.
106
+ end
107
+ }
72
108
 
73
109
 
110
+ hype_script = "// Pre-Processed with HypeAssets v#{::HypeAssets::VERSION} @ #{Time.now}\n#{hype_script}"
111
+
74
112
  {
75
113
  data: hype_script,
76
114
  dependencies: dependencies,
@@ -78,7 +116,7 @@ class HypeAssets::HypeTemplate
78
116
  end
79
117
 
80
118
 
81
- def self.digested_asset_filename (resource, dependencies, sprockets)
119
+ def self.digested_asset_filename (filename, folder, dependencies, sprockets)
82
120
  ### @param resource [String] uri-encoded asset, e.g. "folder/file%402x.jpg"
83
121
  ### @param dependencies [Set] (mutated) resource is added to the set
84
122
  ### @param sprockets [Sprockets::Environment] needed for its helper functions
@@ -90,8 +128,10 @@ class HypeAssets::HypeTemplate
90
128
  ### Incidentally, it encodes `@`, even though this is a safe character, AFAICT.
91
129
  ### URI.encode does *not* re-encode the `@`, but that doesn't seem to break things.
92
130
 
93
- decoded_resource = URI.decode resource
94
- digested_path = digest_path decoded_resource
131
+
132
+ decoded_filename = URI.decode filename
133
+ resource = "#{folder}/#{decoded_filename}"
134
+ digested_path = digest_path resource
95
135
  basename = File.basename digested_path
96
136
  re_encoded_name = URI.encode basename
97
137
 
@@ -104,17 +144,20 @@ class HypeAssets::HypeTemplate
104
144
  ## "foo.hyperesources/file"
105
145
  ## "file-digest:///foo.hyperesources/file"
106
146
  ## "/absolute/path/to/foo.hyperesources/file"
107
- absolute_path = sprockets.resolve(decoded_resource)
147
+ absolute_path = sprockets.resolve(resource)
108
148
  file_digest_uri = sprockets.build_file_digest_uri(absolute_path)
109
149
  ## NOTE: build_file_digest_uri just tacks on a file-digest:// prefix.
110
150
  ## It does //not// generate a digest hashcode.
111
151
  dependencies << file_digest_uri
112
152
 
113
153
  re_encoded_name
154
+ rescue NoMethodError => e
155
+ puts "HypeAssets: Unable to locate/process asset: #{resource}"
114
156
  end
115
157
 
116
158
 
117
159
  def self.asset_url (resource)
160
+ ### UNUSED. I'm generating the base URL via the context_class now.
118
161
  ### Wrapper function around the Sprockets helper,
119
162
  ### since it's not clear how best to invoke it.
120
163
  ApplicationController.helpers.asset_url resource
@@ -1,3 +1,3 @@
1
1
  module HypeAssets
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hype_assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.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-29 00:00:00.000000000 Z
11
+ date: 2016-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.11'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.11'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  - !ruby/object:Gem::Dependency