fluby 0.5.6 → 0.6.1

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/README.mdown ADDED
@@ -0,0 +1,134 @@
1
+ # fluby
2
+
3
+ A simple command to create an empty ActionScript project for MTASC + SWFMILL + Rake
4
+
5
+ ## Installation
6
+
7
+ gem install fluby
8
+
9
+ Fluby requires the 'mtasc' and 'swfmill' executables somewhere on your path.
10
+
11
+
12
+ ## Usage
13
+
14
+ ### New project
15
+
16
+ To create a new project:
17
+
18
+ fluby ProjectName
19
+
20
+
21
+ ### Compilation
22
+
23
+ To compile your brand new project:
24
+
25
+ cd ProjectName
26
+ rake
27
+
28
+ That should generate a 'ProjectName.swf' file on the 'deploy' folder. The SWF file is debug-enabled (i.e: you can see the trace() output if you have a debug Flash Player). If you want to release your project without debug information, run
29
+
30
+ rake release
31
+
32
+
33
+ ### More Rake tasks
34
+
35
+ There are other rake tasks available:
36
+
37
+ rake package # Creates a ZIP file containing your SWF file on the 'pkg' folder
38
+ rake test # Opens a HTML file with your SWF for testing on your default browser (available on Mac only)
39
+
40
+
41
+ ### script/generate
42
+
43
+ Starting from version 0.6, fluby installs a 'generate' script in the 'scripts' folder that you can use to speed up the creation of new classes.
44
+
45
+ Right now there are 3 template types:
46
+
47
+ #### **class**
48
+
49
+ Use it to create a generic class by running:
50
+
51
+ script/generate class your.class.path.ClassName attribute:Type attribute:Type (...)
52
+
53
+ For example: if you want to create a "Car" class with attributes "make" and "model" of type String and an attribute "year" of type Number, you'd run:
54
+
55
+ script/generate class com.yourdomain.Car make:String model:String year:Number
56
+
57
+ This will create a file in com/yourdomain/Car.as with this content:
58
+
59
+ class com.yourdomain.Car {
60
+ var make:String;
61
+ var model:String;
62
+ var year:Number;
63
+ function Car(){
64
+ // Init class
65
+ }
66
+ }
67
+
68
+
69
+ #### **xml_loader**
70
+
71
+ Use to create a simple XML loader class by running:
72
+
73
+ script/generate xml_loader your.class.path.ClassName
74
+
75
+ Example: if you run
76
+
77
+ script/generate xml_loader com.bomberstudios.xml.Loader
78
+
79
+ you'll get a com/bomberstudios/xml/Loader.as file containing:
80
+
81
+ class com.bomberstudios.xml.Loader {
82
+ var _path:String;
83
+ var raw_data:XML;
84
+ function Loader(path:String,callback:Function){
85
+ _path = path;
86
+ raw_data = new XML();
87
+ raw_data.ignoreWhite = true;
88
+ raw_data.onLoad = callback;
89
+ }
90
+ function give_me(node_name){
91
+ if (raw_data.firstChild.nodeName == node_name) {
92
+ return raw_data.firstChild;
93
+ }
94
+ for(var i=raw_data.firstChild.childNodes.length; i>=0; i--){
95
+ if(raw_data.firstChild.childNodes[i].nodeName == node_name){
96
+ return raw_data.firstChild.childNodes[i];
97
+ }
98
+ }
99
+ }
100
+ public function load(){
101
+ raw_data.load(_path);
102
+ }
103
+ }
104
+
105
+
106
+ #### **delegate**
107
+
108
+ To generate a MTASC-compatible Delegate class, run
109
+
110
+ script/generate delegate your.class.path.Delegate
111
+
112
+ This will produce a your/class/path/Delegate.as file containing:
113
+
114
+ /**
115
+ *
116
+ * Delegate Class, MTASC compatible
117
+ *
118
+ **/
119
+ class your.class.path.Delegate {
120
+ public static function create(scope:Object,method:Function):Function{
121
+ var params:Array = arguments.splice(2,arguments.length-2);
122
+ var proxyFunc:Function = function():Void{
123
+ method.apply(scope,arguments.concat(params));
124
+ }
125
+ return proxyFunc;
126
+ }
127
+ public static function createR(scope:Object,method:Function):Function{
128
+ var params:Array = arguments.splice(2,arguments.length-2);
129
+ var proxyFunc:Function = function():Void{
130
+ method.apply(scope,params.concat(arguments));
131
+ }
132
+ return proxyFunc;
133
+ }
134
+ }
data/Rakefile CHANGED
@@ -28,7 +28,7 @@ spec = Gem::Specification.new do |s|
28
28
  s.required_ruby_version = '>= 1.8.5'
29
29
 
30
30
  s.has_rdoc = false
31
- s.files = FileList.new("README","Rakefile","bin/**/*","lib/**/*").to_a
31
+ s.files = FileList.new("README.mdown","Rakefile","bin/**/*","lib/**/*").to_a
32
32
  s.executables = [ 'fluby' ]
33
33
  s.require_path = 'lib'
34
34
  s.bindir = 'bin'
@@ -56,4 +56,16 @@ Rake::TestTask.new(:test) do |test|
56
56
  test.test_files = Dir['test/test_*.rb']
57
57
  end
58
58
 
59
- task :default => [ :install ]
59
+ task :github do
60
+ require 'rubygems/specification'
61
+ data = File.read('fluby.gemspec')
62
+ github_spec = nil
63
+ Thread.new { github_spec = eval("$SAFE = 3\n#{data}") }.join
64
+ puts github_spec
65
+ end
66
+
67
+ task :test do
68
+ %x(ruby test/test_fluby.rb)
69
+ end
70
+
71
+ task :default => [ :test ]
data/lib/fluby.rb CHANGED
@@ -1,21 +1,40 @@
1
+ require "erb"
2
+ require "fileutils"
3
+
1
4
  module Fluby
2
5
  NAME = 'fluby'
3
- VERSION = '0.5.6'
6
+ VERSION = '0.6.1'
7
+
8
+ COLORS = {
9
+ :black => "\033[0;30m",
10
+ :red => "\033[0;31m",
11
+ :green => "\033[0;32m",
12
+ :yellow => "\033[0;33m",
13
+ :blue => "\033[0;34m",
14
+ :purple => "\033[0;35m",
15
+ :cyan => "\033[0;36m",
16
+ :white => "\033[0;37m",
17
+ :whitebold => "\033[1;37m"
18
+ }
19
+ PATH = File.expand_path(__FILE__)
4
20
 
5
21
  def self.create_project(name)
6
22
  require "fileutils"
7
23
  require "erb"
8
24
 
25
+ # TODO: Support project creation in subfolders (i.e: fluby test/project)
9
26
  @project_name = name
10
27
  @project_folder = FileUtils.pwd + "/" + @project_name
11
28
 
29
+ puts "\n#{COLORS[:green]}Creating project #{@project_name}"
30
+
12
31
  # Make folders
13
32
  if File.exist? @project_folder
14
- puts "Folder #{@project_name} already exists,"
15
- puts "please choose a different name for your project"
33
+ puts "#{COLORS[:red]}Folder #{@project_name} already exists,"
34
+ puts "#{COLORS[:red]}please choose a different name for your project"
16
35
  exit
17
36
  end
18
- FileUtils.mkdir [@project_folder,"#{@project_folder}/deploy","#{@project_folder}/assets"]
37
+ FileUtils.mkdir [@project_folder,"#{@project_folder}/deploy","#{@project_folder}/assets","#{@project_folder}/script"]
19
38
 
20
39
  # Make files
21
40
  ["Rakefile","README"].each do |file|
@@ -30,6 +49,13 @@ module Fluby
30
49
  # Main Class
31
50
  render_template "ASClass.as", "#{@project_name}.as"
32
51
 
52
+ # script/generate
53
+ render_template "generate", "script/generate"
54
+ %x(chmod 755 "#{@project_folder}/script/generate")
55
+
56
+ if in_textmate?
57
+ puts "Oh, my, what a nice editor you're using"
58
+ end
33
59
  end
34
60
 
35
61
  def self.copy_template source, destination=nil
@@ -37,6 +63,7 @@ module Fluby
37
63
  destination = source
38
64
  end
39
65
  FileUtils.cp "#{File.dirname(__FILE__)}/templates/#{source}", "#{@project_folder}/#{destination}"
66
+ log "create", "#{@project_name}/#{destination}"
40
67
  end
41
68
 
42
69
  def self.render_template source, destination=nil
@@ -46,5 +73,62 @@ module Fluby
46
73
  open("#{@project_folder}/#{destination}","w") do |f|
47
74
  f << ERB.new(IO.read("#{File.dirname(__FILE__)}/templates/#{source}")).result(binding)
48
75
  end
76
+ log "create", "#{@project_name}/#{destination}"
77
+ end
78
+
79
+ def self.log type, string
80
+ case type
81
+ when "alert"
82
+ puts "\t#{COLORS[:red]}Alert:\t#{string}#{COLORS[:white]}"
83
+ when "create"
84
+ puts "\t#{COLORS[:white]}Created:\t#{COLORS[:cyan]}#{string}#{COLORS[:white]}"
85
+ end
86
+ end
87
+
88
+ def self.in_textmate?
89
+ begin
90
+ if TextMate
91
+ return true
92
+ end
93
+ rescue
94
+ return false
95
+ end
96
+ end
97
+
98
+ def self.is_mac?
99
+ return RUBY_PLATFORM =~ /darwin/
100
+ end
101
+
102
+ def self.has_growl?
103
+ return is_mac? && !`which "growlnotify"`.empty?
104
+ end
105
+
106
+ # these functions are used by script/generate
107
+ def self.generate(type, name, options={})
108
+ target_path = File.dirname(name.split(".").join("/").to_s)
109
+ target_file = name.split(".").join("/") + ".as".to_s
110
+ if File.exist?(target_file)
111
+ log "alert", "File #{target_file} already exists!"
112
+ return
113
+ end
114
+ FileUtils.mkdir_p target_path unless File.exist? target_path
115
+ @classpath = target_path.split("/").join(".")
116
+ @classname = name.split(".").last
117
+ options = options.map { |i| i = i.split(":") } unless options == {}
118
+ @opts = options
119
+ File.open(target_file,"w") do |file|
120
+ file << ERB.new(File.read("#{template_path}/generators/#{type}")).result(binding)
121
+ end
122
+ log "create", "#{target_path}/#{@classname}.as"
123
+ end
124
+
125
+ def self.path
126
+ File.dirname(PATH)
127
+ end
128
+ def self.template_path
129
+ path + "/templates"
130
+ end
131
+ def self.available_templates
132
+ return Dir["#{template_path}/generators/**"].map { |i| i = File.basename(i) }
49
133
  end
50
134
  end
data/lib/templates/README CHANGED
@@ -48,4 +48,4 @@ Then, in your code, you'd use the fonts like this:
48
48
  txtest.text = "This is italics";
49
49
 
50
50
  ---
51
- Created: <%= Time.now %>
51
+ Created: <%= Time.now.strftime("%Y%m%d") %>
@@ -1,3 +1,6 @@
1
+ require "erb"
2
+ require 'rake/packagetask'
3
+
1
4
  WIDTH = 725
2
5
  HEIGHT = 480
3
6
  FPS = 31
@@ -5,8 +8,6 @@ PLAYER = 8
5
8
  BGCOLOR = "#ffffff"
6
9
  APP = "<%= @project_name %>"
7
10
 
8
- require "erb"
9
-
10
11
  def render_template(file)
11
12
  filename = File.basename(file).split(".")[0]
12
13
  case File.basename(file).split(".")[1]
@@ -36,18 +37,24 @@ task :compile do
36
37
  end
37
38
  end
38
39
  puts %x(swfmill simple #{APP}.xml #{APP}.swf)
39
- rm "#{APP}.xml"
40
+ rm "#{APP}.xml", {:verbose => false}
40
41
  puts %x(mtasc -swf #{APP}.swf -main -mx -version #{PLAYER} #{trace} #{APP}.as)
41
42
  @end = Time.now
42
43
 
43
44
  ["*.html","*.swf"].each do |list|
44
45
  Dir[list].each do |file|
45
- mv file, "deploy/#{file}"
46
+ mv file, "deploy/#{file}", {:verbose => false}
46
47
  end
47
48
  end
48
49
  end
49
50
 
50
- <% if RUBY_PLATFORM =~ /darwin/ %>
51
+ Rake::PackageTask.new(APP, :noversion) do |p|
52
+ p.need_zip = true
53
+ p.name = Time.now.strftime("%Y%m%d") + "-" + APP
54
+ p.package_files.include("README",Dir["deploy/*"])
55
+ end
56
+
57
+ <% if Fluby.has_growl? %>
51
58
  task :notify do
52
59
  msg = "Finished compiling in #{@end - @start}s."
53
60
  if @nodebug
@@ -61,12 +68,14 @@ task :nodebug do
61
68
  @nodebug = true
62
69
  end
63
70
 
71
+ <% if Fluby.is_mac? %>
64
72
  desc "Test the SWF file in your default browser"
65
73
  task :test => [:compile] do
66
74
  %x(open deploy/index.html)
67
75
  end
76
+ <% end %>
68
77
 
69
- <% if RUBY_PLATFORM =~ /darwin/ %>
78
+ <% if Fluby.has_growl? %>
70
79
  desc "Build a release version of <%= @project_name %> (with trace() disabled)"
71
80
  task :release => [:nodebug,:compile,:notify]
72
81
 
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ require "rubygems"
3
+ require "fluby"
4
+
5
+ commandline = ARGV
6
+ if commandline.size < 2
7
+ puts "Usage: script/generate type classpath [options]"
8
+ puts "where type is one of"
9
+ Fluby.available_templates.each do |t|
10
+ puts "\t#{t}"
11
+ end
12
+ else
13
+ type = commandline.shift
14
+ name = commandline.shift
15
+ options = commandline
16
+ Fluby.generate(type,name,options)
17
+ end
@@ -0,0 +1,7 @@
1
+ class <%= @classpath %>.<%= @classname %> {
2
+ <% @opts.each do |option| %> var <%= option[0] %>:<%= option[1] %>;
3
+ <% end %>
4
+ function <%= @classname %>(){
5
+ // Init class
6
+ }
7
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ *
3
+ * Delegate Class, MTASC compatible
4
+ *
5
+ **/
6
+
7
+ class <%= @classpath %>.<%= @classname %> {
8
+ public static function create(scope:Object,method:Function):Function{
9
+ var params:Array = arguments.splice(2,arguments.length-2);
10
+ var proxyFunc:Function = function():Void{
11
+ method.apply(scope,arguments.concat(params));
12
+ }
13
+ return proxyFunc;
14
+ }
15
+ public static function createR(scope:Object,method:Function):Function{
16
+ var params:Array = arguments.splice(2,arguments.length-2);
17
+ var proxyFunc:Function = function():Void{
18
+ method.apply(scope,params.concat(arguments));
19
+ }
20
+ return proxyFunc;
21
+ }
22
+ }
@@ -0,0 +1,24 @@
1
+ class <%= @classpath %>.<%= @classname %> {
2
+ var _path:String;
3
+ var raw_data:XML;
4
+
5
+ function <%= @classname %>(path:String,callback:Function){
6
+ _path = path;
7
+ raw_data = new XML();
8
+ raw_data.ignoreWhite = true;
9
+ raw_data.onLoad = callback;
10
+ }
11
+ function give_me(node_name){
12
+ if (raw_data.firstChild.nodeName == node_name) {
13
+ return raw_data.firstChild;
14
+ }
15
+ for(var i=raw_data.firstChild.childNodes.length; i>=0; i--){
16
+ if(raw_data.firstChild.childNodes[i].nodeName == node_name){
17
+ return raw_data.firstChild.childNodes[i];
18
+ }
19
+ }
20
+ }
21
+ public function load(){
22
+ raw_data.load(_path);
23
+ }
24
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Ale Mu\xC3\xB1oz"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-04-19 00:00:00 +02:00
12
+ date: 2008-11-04 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -22,12 +22,17 @@ extensions: []
22
22
  extra_rdoc_files: []
23
23
 
24
24
  files:
25
- - README
25
+ - README.mdown
26
26
  - Rakefile
27
27
  - bin/fluby
28
28
  - lib/fluby.rb
29
29
  - lib/templates
30
30
  - lib/templates/ASClass.as
31
+ - lib/templates/generate
32
+ - lib/templates/generators
33
+ - lib/templates/generators/class
34
+ - lib/templates/generators/delegate
35
+ - lib/templates/generators/xml_loader
31
36
  - lib/templates/index.rhtml
32
37
  - lib/templates/project.rxml
33
38
  - lib/templates/Rakefile
@@ -55,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
60
  requirements: []
56
61
 
57
62
  rubyforge_project: fluby
58
- rubygems_version: 1.0.1
63
+ rubygems_version: 1.3.0
59
64
  signing_key:
60
65
  specification_version: 2
61
66
  summary: A simple command to create an empty project for MTASC + SWFMILL + Rake
data/README DELETED
@@ -1,4 +0,0 @@
1
- fluby
2
- =====
3
-
4
- A simple command to create an empty project for MTASC + SWFMILL + Rake