bomberstudios-fluby 0.5.8 → 0.6

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/lib/fluby.rb CHANGED
@@ -1,6 +1,9 @@
1
+ require "erb"
2
+ require "fileutils"
3
+
1
4
  module Fluby
2
5
  NAME = 'fluby'
3
- VERSION = '0.5.8'
6
+ VERSION = '0.6'
4
7
 
5
8
  COLORS = {
6
9
  :black => "\033[0;30m",
@@ -13,6 +16,7 @@ module Fluby
13
16
  :white => "\033[0;37m",
14
17
  :whitebold => "\033[1;37m"
15
18
  }
19
+ PATH = File.expand_path(__FILE__)
16
20
 
17
21
  def self.create_project(name)
18
22
  require "fileutils"
@@ -30,7 +34,7 @@ module Fluby
30
34
  puts "#{COLORS[:red]}please choose a different name for your project"
31
35
  exit
32
36
  end
33
- FileUtils.mkdir [@project_folder,"#{@project_folder}/deploy","#{@project_folder}/assets"]
37
+ FileUtils.mkdir [@project_folder,"#{@project_folder}/deploy","#{@project_folder}/assets","#{@project_folder}/script"]
34
38
 
35
39
  # Make files
36
40
  ["Rakefile","README"].each do |file|
@@ -45,6 +49,13 @@ module Fluby
45
49
  # Main Class
46
50
  render_template "ASClass.as", "#{@project_name}.as"
47
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
48
59
  end
49
60
 
50
61
  def self.copy_template source, destination=nil
@@ -52,7 +63,7 @@ module Fluby
52
63
  destination = source
53
64
  end
54
65
  FileUtils.cp "#{File.dirname(__FILE__)}/templates/#{source}", "#{@project_folder}/#{destination}"
55
- log "#{@project_name}/#{destination}"
66
+ log "create", "#{@project_name}/#{destination}"
56
67
  end
57
68
 
58
69
  def self.render_template source, destination=nil
@@ -62,11 +73,16 @@ module Fluby
62
73
  open("#{@project_folder}/#{destination}","w") do |f|
63
74
  f << ERB.new(IO.read("#{File.dirname(__FILE__)}/templates/#{source}")).result(binding)
64
75
  end
65
- log "#{@project_name}/#{destination}"
76
+ log "create", "#{@project_name}/#{destination}"
66
77
  end
67
78
 
68
- def self.log string
69
- puts " #{COLORS[:white]}Creating #{COLORS[:cyan]}#{string}#{COLORS[:white]}"
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
70
86
  end
71
87
 
72
88
  def self.in_textmate?
@@ -86,4 +102,33 @@ module Fluby
86
102
  def self.has_growl?
87
103
  return is_mac? && !`which "growlnotify"`.empty?
88
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.split(" ").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) }
133
+ end
89
134
  end
@@ -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,9 +8,6 @@ PLAYER = 8
5
8
  BGCOLOR = "#ffffff"
6
9
  APP = "<%= @project_name %>"
7
10
 
8
- require "erb"
9
- require 'rake/packagetask'
10
-
11
11
  def render_template(file)
12
12
  filename = File.basename(file).split(".")[0]
13
13
  case File.basename(file).split(".")[1]
@@ -37,13 +37,13 @@ task :compile do
37
37
  end
38
38
  end
39
39
  puts %x(swfmill simple #{APP}.xml #{APP}.swf)
40
- rm "#{APP}.xml"
40
+ rm "#{APP}.xml", {:verbose => false}
41
41
  puts %x(mtasc -swf #{APP}.swf -main -mx -version #{PLAYER} #{trace} #{APP}.as)
42
42
  @end = Time.now
43
43
 
44
44
  ["*.html","*.swf"].each do |list|
45
45
  Dir[list].each do |file|
46
- mv file, "deploy/#{file}"
46
+ mv file, "deploy/#{file}", {:verbose => false}
47
47
  end
48
48
  end
49
49
  end
@@ -0,0 +1,18 @@
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.to_s
16
+
17
+ Fluby.generate(type,name,options)
18
+ end
@@ -0,0 +1,7 @@
1
+ class <%= @classpath %>.<%= @classname %> {
2
+ <% @opts.each do |option| %>
3
+ var <%= option[0] %>:<%= option[1] %>;
4
+ <% end %>
5
+ function <%= @classname %>(){
6
+ }
7
+ }
@@ -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: bomberstudios-fluby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.8
4
+ version: "0.6"
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Ale Mu\xC3\xB1oz"
@@ -32,6 +32,9 @@ files:
32
32
  - lib/templates/Rakefile
33
33
  - lib/templates/README
34
34
  - lib/templates/swfobject.js
35
+ - lib/templates/generate
36
+ - lib/templates/generators/class
37
+ - lib/templates/generators/xml_loader
35
38
  has_rdoc: false
36
39
  homepage: http://github.com/bomberstudios/fluby/
37
40
  post_install_message: