coffee-processing 0.0.4 → 0.0.5
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.
- data/.gitignore +1 -0
- data/CHANGELOG.md +4 -0
- data/README.md +23 -0
- data/coffee-processing.gemspec +1 -1
- data/examples/lines.coffee +1 -1
- data/lib/coffee-processing/boilerplate.coffee.erb +38 -16
- data/lib/coffee-processing/version.rb +1 -1
- metadata +3 -7
- data/test/bin_helper.rb +0 -10
- data/test/test_coffee_processing.rb +0 -46
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -53,6 +53,29 @@ And the HTML page.
|
|
53
53
|
</script>
|
54
54
|
```
|
55
55
|
|
56
|
+
Preloading (Experimental)
|
57
|
+
-------------------------
|
58
|
+
|
59
|
+
Asynchronous nature of Javascript requires preloading of images and fonts.
|
60
|
+
Processing.js allows you to preload assets with [@pjs directives](http://processingjs.org/reference/pjs%20directive/).
|
61
|
+
However they are only applied during the compilation of Processing syntax,
|
62
|
+
and there's currenty no direct way to preload in Javascript-only Processing.js code.
|
63
|
+
|
64
|
+
If you define `preload` object in your coffee-processing code as the following example,
|
65
|
+
coffee-processing will delay the execution until those assets are ready.
|
66
|
+
(Although the way it does so seems quite hacky.)
|
67
|
+
|
68
|
+
```coffee
|
69
|
+
preload =
|
70
|
+
images: ['/images/image1.png', '/images/image2.png']
|
71
|
+
fonts: ['/fonts/font.ttf']
|
72
|
+
|
73
|
+
setup = ->
|
74
|
+
font = createFont '/fonts/font.ttf', 0
|
75
|
+
img1 = loadImage '/images/image1.png'
|
76
|
+
img2 = loadImage '/images/image2.png'
|
77
|
+
```
|
78
|
+
|
56
79
|
coffee-processing script
|
57
80
|
------------------------
|
58
81
|
|
data/coffee-processing.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.summary = %q{Helps writing Processing.js sketches in Coffeescript}
|
9
9
|
gem.homepage = "https://github.com/junegunn/coffee-processing"
|
10
10
|
|
11
|
-
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.files = `git ls-files | grep -v 'test/'`.split($\)
|
12
12
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
13
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
14
|
gem.name = "coffee-processing"
|
data/examples/lines.coffee
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
<%= javascript_object %> = (__processing) ->
|
1
|
+
<%= javascript_object %> = new Processing.Sketch (__processing) ->
|
2
2
|
for __sym of __processing when eval("typeof #{__sym} === 'undefined'")
|
3
3
|
if typeof __processing[__sym] == 'function'
|
4
4
|
eval "var #{__sym} = function() { return __processing.#{__sym}.apply(__processing, arguments) }"
|
@@ -15,19 +15,41 @@
|
|
15
15
|
|
16
16
|
<%= code %>
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
eval
|
18
|
+
__inject = ->
|
19
|
+
for callback in [
|
20
|
+
'setup',
|
21
|
+
'draw',
|
22
|
+
'mouseClicked',
|
23
|
+
'mouseDragged',
|
24
|
+
'mouseMoved',
|
25
|
+
'mouseOut',
|
26
|
+
'mouseOver',
|
27
|
+
'mousePressed',
|
28
|
+
'mouseReleased',
|
29
|
+
'keyPressed',
|
30
|
+
'keyReleased',
|
31
|
+
'keyTyped'
|
32
|
+
] when !eval("typeof #{__sym} === 'undefined'")
|
33
|
+
eval "__processing.#{callback} = #{callback}"
|
34
|
+
|
35
|
+
__polling = ->
|
36
|
+
interval = 100
|
37
|
+
if __processing.externals.sketch.imageCache.pending or __processing.PFont.preloading.pending(interval)
|
38
|
+
window.setTimeout __polling, interval
|
39
|
+
else
|
40
|
+
__inject()
|
41
|
+
setup() if (typeof setup)?
|
42
|
+
|
43
|
+
if preload?
|
44
|
+
if preload.fonts?
|
45
|
+
for __font in preload.fonts
|
46
|
+
__processing.PFont.preloading.add __font
|
47
|
+
if preload.images?
|
48
|
+
for __image in preload.images
|
49
|
+
__processing.externals.sketch.imageCache.add __image
|
50
|
+
|
51
|
+
__processing.setup = -> __polling()
|
52
|
+
__processing.draw = -> null
|
53
|
+
else
|
54
|
+
__inject()
|
33
55
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coffee-processing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: coffee-script
|
@@ -82,8 +82,6 @@ files:
|
|
82
82
|
- lib/coffee-processing/boilerplate.coffee.erb
|
83
83
|
- lib/coffee-processing/template.html.erb
|
84
84
|
- lib/coffee-processing/version.rb
|
85
|
-
- test/bin_helper.rb
|
86
|
-
- test/test_coffee_processing.rb
|
87
85
|
homepage: https://github.com/junegunn/coffee-processing
|
88
86
|
licenses: []
|
89
87
|
post_install_message:
|
@@ -108,6 +106,4 @@ rubygems_version: 1.8.24
|
|
108
106
|
signing_key:
|
109
107
|
specification_version: 3
|
110
108
|
summary: Helps writing Processing.js sketches in Coffeescript
|
111
|
-
test_files:
|
112
|
-
- test/bin_helper.rb
|
113
|
-
- test/test_coffee_processing.rb
|
109
|
+
test_files: []
|
data/test/bin_helper.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
# gunn@daumcorp.com
|
4
|
-
|
5
|
-
# DISCLAIMER:
|
6
|
-
# Not a real test!
|
7
|
-
# Just a helper script for running scripts with local source
|
8
|
-
|
9
|
-
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '../lib')
|
10
|
-
load File.join(File.dirname(__FILE__), '../bin/', File.basename(ARGV.shift))
|
@@ -1,46 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '../lib')
|
4
|
-
require 'test-unit'
|
5
|
-
require 'coffee-processing'
|
6
|
-
|
7
|
-
class TestCoffeeProcessing < Test::Unit::TestCase
|
8
|
-
def test_indentation
|
9
|
-
without_indentation = "
|
10
|
-
setup = ->
|
11
|
-
null
|
12
|
-
|
13
|
-
draw = ->
|
14
|
-
null"
|
15
|
-
|
16
|
-
with_space_indentation = "
|
17
|
-
setup = ->
|
18
|
-
null
|
19
|
-
|
20
|
-
draw = ->
|
21
|
-
null
|
22
|
-
"
|
23
|
-
|
24
|
-
with_tab_indentation = "
|
25
|
-
setup = ->
|
26
|
-
null
|
27
|
-
|
28
|
-
draw = ->
|
29
|
-
null
|
30
|
-
"
|
31
|
-
|
32
|
-
assert_equal 1,
|
33
|
-
[without_indentation, with_space_indentation, with_tab_indentation].map { |code|
|
34
|
-
CoffeeProcessing.compile 'this.sketch', code
|
35
|
-
}.uniq.length
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_error
|
39
|
-
begin
|
40
|
-
CoffeeProcessing.compile 'this.sketch', %w[1 2 3 ? 5].join($/)
|
41
|
-
assert false, 'Exception should have been raised'
|
42
|
-
rescue ExecJS::ProgramError => e
|
43
|
-
assert e.to_s =~ /line 4:/, 'Unadjusted line number'
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|