assertTrue is the professional blog of Luke Bayes and Ali Mills

Using External Libraries with Sprouts

Posted by Luke Bayes Wed, 10 Sep 2008 01:26:00 GMT

Sprouts has quite a wide variety of different libraries available that you can instantly include in your project.

as3crypto
as3flickrlib-src
as3flickrlib
as3mapprlib-src
as3mapprlib
as3syndicationlib-src
as3syndicationlib
as3youtubelib-src
as3youtubelib
asunit25
asunit3
bulkloader
cairngorm-src
cairngorm
corelib-src
corelib
degrafa
facebook-api
flexlib-src
flexlib
flexunit-src
flexunit
fuse
papervision
swx
tweener
tweeneras2
yahoomapsas3

You can include any of these libraries by simply adding them as a symbol to your project_model.

1
2
3
4
5
6
7
8
9
project_model :model do |m|
  m.project_name            = 'SomeProject'
  m.language                = 'mxml'
  m.background_color        = '#FFFFFF'
  m.width                   = 970
  m.height                  = 550
  m.libraries               << :corelib
  m.libraries               << :papervision
end

This will automatically download and install these libraries into your project and update your compilation tasks to make these targets available!

If you find that the downloaded libraries aren’t working or are out of date, please send us an email with a link to the latest files.

Read on to learn more about packaging up your own libraries!

Of course the first thing everyone wants to know, is how to package up their project as a Sprout library.

It’s still a little bit hacky right now because our implementation only supports external, downloaded libraries – meaning we can’t actually stuff the library code or SWC into the gem – yet. If you’d like to contribute a patch that makes this work, I’ll be forever in your debt!

As it stands right now, you’ll need to post your library to a web server somewhere and add the following to a rakefile:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
desc 'Package gem of the library'
task :package => :coolestever

gem_wrap :coolestever do |t|
  # version is a dot-delimited, 3 digit 
  # string, that should be incremented
  # with each release.
  t.version       = '0.1.0'
  # Short summary of your library or project
  t.summary       = 'My library cures whatever ails you'
  t.author        = 'My Big Name'
  # Your email or project group address
  t.email         = 'coolestlib@googlegroups.com'
  # The homepage of your library
  t.homepage      = 'http://www.thecoolestlibraryever.com'
  t.sprout_spec   =<<EOF
- !ruby/object:Sprout::RemoteFileTarget 
  platform: universal
  url: http://www.thecoolestlibraryever.com/files/library-1.3.0.zip
  archive_path: 'src'
EOF
end

That archive_path parameter is a relative target from within your zip archive to the library source path. The folder targeted there will be used to set source_path for the compilers that point at this library.

In the example above, if you extracted the zip file, there would be a directory named ‘src’ that had library source code in it.

If you want to package up your library as a SWC file, just set the archive_path to point directly at the SWC. In the example above, that might be something more like, archive_path: 'bin/coolestever.swc'.

Once you’ve got this all set up, just run rake package.

Thanks to the desc, you should also see a description when you run rake -T.

This task will create a new folder called ‘pkg’ and put a new gem in there. If you publish this gem to RubyForge, and if the name is unused, everyone can get it.

You can also just install the gem manually with gem install pkg/sprout-coolestever-library-0.1.0.gem, and then refer to it in any sprout projects as :coolestever.

Hope this helps someone out there!

Tags ,  | 1 comment

Comments

  1. Nathan Fisher replied: Avatar "add the following to a rakefile". Sounds cool, but which one? I assume the rakefile located in the root of your sprouts project?
    Posted: 8 days later.

Your Reply

Comment Form.

Fields denoted with an "*" are required.