gator-as3 0.0.7.pre → 0.0.9.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/Gemfile +3 -2
  2. data/Rakefile +7 -4
  3. data/VERSION +1 -1
  4. data/gator-as3.gemspec +73 -28
  5. data/lib/gator/as3.rb +3 -0
  6. data/lib/gator/as3/as3_configuration.rb +38 -0
  7. data/lib/gator/as3/generators/{collection.rb → as3/collection.rb} +5 -1
  8. data/lib/gator/as3/generators/as3/event.rb +14 -0
  9. data/lib/gator/as3/generators/as3/generator.rb +95 -0
  10. data/lib/gator/as3/generators/as3/interface.rb +14 -0
  11. data/lib/gator/as3/generators/as3/klass.rb +15 -0
  12. data/lib/gator/as3/generators/as3/test/asunit3.rb +3 -0
  13. data/lib/gator/as3/generators/as3/test/asunit3/collection.rb +21 -0
  14. data/lib/gator/as3/generators/as3/test/asunit3/klass.rb +32 -0
  15. data/lib/gator/as3/generators/as3/test/asunit3/runner.rb +28 -0
  16. data/lib/gator/as3/generators/as3/test/asunit3/suite.rb +38 -0
  17. data/lib/gator/as3/generators/{test → as3/test}/asunit4.rb +0 -0
  18. data/lib/gator/as3/generators/{test → as3/test}/asunit4/collection.rb +5 -1
  19. data/lib/gator/as3/generators/as3/test/asunit4/klass.rb +31 -0
  20. data/lib/gator/as3/generators/as3/test/asunit4/runner.rb +29 -0
  21. data/lib/gator/as3/generators/as3/test/asunit4/suite.rb +39 -0
  22. data/lib/gator/as3/generators/{test → as3/test}/flexunit4.rb +0 -0
  23. data/lib/gator/as3/generators/{test → as3/test}/flexunit4/collection.rb +1 -1
  24. data/lib/gator/as3/generators/as3/test/flexunit4/klass.rb +34 -0
  25. data/lib/gator/as3/generators/mxml/application.rb +16 -0
  26. data/lib/gator/as3/generators/mxml/collection.rb +20 -0
  27. data/lib/gator/as3/generators/mxml/component.rb +16 -0
  28. data/lib/gator/as3/generators/mxml/generator.rb +20 -0
  29. data/lib/gator/as3/generators/mxml/skin.rb +21 -0
  30. data/lib/gator/as3/templates/as3/event.as.tt +12 -0
  31. data/lib/gator/as3/templates/as3/interface.as.tt +6 -0
  32. data/lib/gator/as3/{generators → templates/as3}/klass.as.tt +0 -0
  33. data/lib/gator/as3/templates/as3/test/asunit3/klass.as.tt +37 -0
  34. data/lib/gator/as3/templates/as3/test/asunit3/runner.as.tt +13 -0
  35. data/lib/gator/as3/templates/as3/test/asunit3/suite.as.tt +17 -0
  36. data/lib/gator/as3/{generators → templates/as3}/test/asunit4/klass.as.tt +0 -0
  37. data/lib/gator/as3/templates/as3/test/asunit4/runner.as.tt +17 -0
  38. data/lib/gator/as3/templates/as3/test/asunit4/suite.as.tt +14 -0
  39. data/lib/gator/as3/{generators → templates/as3}/test/flexunit4/klass.as.tt +0 -0
  40. data/lib/gator/as3/templates/mxml/application.mxml.tt +30 -0
  41. data/lib/gator/as3/templates/mxml/component.mxml.tt +13 -0
  42. data/lib/gator/as3/templates/mxml/skin.mxml.tt +53 -0
  43. data/lib/gator/mxml/generators.rb +5 -0
  44. data/lib/gator/utils/as3_util.rb +45 -0
  45. data/rake/jeweler.rb +17 -0
  46. data/rake/jeweler_prerelease_tasks.rb +50 -0
  47. data/rake/pre_release_gemspec.rb +80 -0
  48. data/rake/pre_release_to_git.rb +59 -0
  49. data/spec/as3/generators/collection_spec.rb +46 -0
  50. data/spec/as3/generators/event_spec.rb +40 -0
  51. data/spec/as3/generators/interface_spec.rb +40 -0
  52. data/spec/as3/generators/klass_spec.rb +40 -0
  53. data/spec/as3/generators/test/asunit3/klass_spec.rb +43 -0
  54. data/spec/as3/generators/test/asunit3/runner_spec.rb +43 -0
  55. data/spec/as3/generators/test/asunit3/suite_spec.rb +43 -0
  56. data/spec/as3/generators/test/asunit4/klass_spec.rb +43 -0
  57. data/spec/as3/generators/test/asunit4/runner_spec.rb +43 -0
  58. data/spec/as3/generators/test/asunit4/suite_spec.rb +43 -0
  59. data/spec/mxml/generators/application_spec.rb +42 -0
  60. data/spec/mxml/generators/component_spec.rb +42 -0
  61. data/spec/mxml/generators/skin_spec.rb +42 -0
  62. data/spec/spec_helper.rb +36 -3
  63. metadata +86 -35
  64. data/lib/gator/as3/generators.rb +0 -3
  65. data/lib/gator/as3/generators/klass.rb +0 -53
  66. data/lib/gator/as3/generators/test/asunit4/klass.rb +0 -61
  67. data/lib/gator/as3/generators/test/flexunit4/klass.rb +0 -57
  68. data/spec/generators/collection_spec.rb +0 -11
  69. data/spec/generators/klass_spec.rb +0 -5
@@ -0,0 +1,14 @@
1
+ package
2
+ {
3
+ <% all_tests.each do |test| %>
4
+ <%= "#{test[:package_name]}.#{test[:class_name]};".sub(/(?<!\w)\./, "").insert(0, 'import ') %>
5
+ <% end %>
6
+
7
+ [Suite]
8
+ public class AllTests
9
+ {
10
+ <% all_tests.each_with_index do |test, index| %>
11
+ <%= "public var #{test[:class_name].gsub(/\B[A-Z]/, '_\&').downcase}_#{index}:#{test[:package_name]}.#{test[:class_name]};".sub(/(?<!\w)\./, "") %>
12
+ <% end %>
13
+ }
14
+ }
@@ -0,0 +1,30 @@
1
+ <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
2
+ xmlns:s="library://ns.adobe.com/flex/spark"
3
+ xmlns:mx="library://ns.adobe.com/flex/mx"
4
+ minWidth="800"
5
+ minHeight="600"
6
+ width="1024"
7
+ height="768"
8
+ backgroundColor="0xFFFFFF"
9
+ pageTitle="<%= class_name %>"
10
+ usePreloader="true"
11
+ applicationComplete="on<%= class_name %>Complete()">
12
+ <fx:Style>
13
+ @namespace s "library://ns.adobe.com/flex/spark";
14
+ </fx:Style>
15
+ <fx:Declarations>
16
+ <!-- You have to put all non-visual object declarations here -->
17
+ </fx:Declarations>
18
+ <s:layout>
19
+ <s:BasicLayout/>
20
+ </s:layout>
21
+ <fx:Script>
22
+ <![CDATA[
23
+ protected function on<%= class_name %>Complete():void
24
+ {
25
+ trace("<%= class_name %>.mxml :: on<%= class_name %>Complete()");
26
+ }
27
+ ]]>
28
+ </fx:Script>
29
+ </s:Application>
30
+
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
3
+ xmlns:s="library://ns.adobe.com/flex/spark">
4
+
5
+ <s:layout>
6
+ <s:BasicLayout/>
7
+ </s:layout>
8
+
9
+ <fx:Script><![CDATA[
10
+ //
11
+ ]]></fx:Script>
12
+
13
+ </s:Group>
@@ -0,0 +1,53 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009"
3
+ xmlns:s="library://ns.adobe.com/flex/spark">
4
+
5
+ <fx:Metadata>
6
+ <![CDATA[
7
+ // TODO add host component e.g. [HostComponent("spark.components.Button")]
8
+ ]]>
9
+ </fx:Metadata>
10
+
11
+ <fx:Script>
12
+ <![CDATA[
13
+ override protected function initializationComplete():void
14
+ {
15
+ super.initializationComplete();
16
+ }
17
+
18
+ override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number) : void
19
+ {
20
+ super.updateDisplayList(unscaledWidth, unscaledHeight);
21
+ }
22
+ ]]>
23
+ </fx:Script>
24
+
25
+ <s:states>
26
+ <s:State name="up" />
27
+ <s:State name="over" />
28
+ <s:State name="down" />
29
+ <s:State name="disabled" />
30
+ </s:states>
31
+
32
+ <s:Rect id="bgFill"
33
+ left="0"
34
+ right="0"
35
+ top="0"
36
+ bottom="0">
37
+ <s:fill>
38
+ <s:LinearGradient rotation="90">
39
+ <s:GradientEntry color="0xFFFFFF"
40
+ alpha="1"/>
41
+ <s:GradientEntry color="0xE4E4E4"
42
+ alpha="1"/>
43
+ </s:LinearGradient>
44
+ </s:fill>
45
+ </s:Rect>
46
+
47
+ <s:Group id="contentGroup"
48
+ left="0"
49
+ right="0"
50
+ top="0"
51
+ bottom="0"/>
52
+
53
+ </s:SparkSkin>
@@ -0,0 +1,5 @@
1
+ require File.dirname(__FILE__) + '/../as3/utils/as3_util'
2
+ require File.dirname(__FILE__) + '/generators/generator'
3
+ require File.dirname(__FILE__) + '/generators/collection'
4
+
5
+ Gator::GenerateCommand.register_subcommand Gator::MXML::GeneratorCollection
@@ -0,0 +1,45 @@
1
+ class Gator
2
+ module AS3
3
+ class AS3Util
4
+ class << self
5
+ def find_test_files( source, package_name="" )
6
+ Dir["#{File.join(source,package_to_dir(package_name))}**/*Test.as"]
7
+ end
8
+
9
+ def package_to_dir(package)
10
+ package.split(".").join(File::SEPARATOR)
11
+ end
12
+
13
+ def file_to_package_and_class(file,source=nil)
14
+ file.gsub!(source+"/","") if source
15
+ class_name = File.basename(file,".as")
16
+ package_name = file.split(File::SEPARATOR).join(".").chomp("#{class_name}.as").chomp(".")
17
+ return :class_name => class_name, :package_name => package_name
18
+ end
19
+
20
+ def split_package_and_class(class_name)
21
+ pieces = class_name.split "."
22
+ class_name = pieces.pop
23
+ package_name = pieces.join "."
24
+ return package_name, class_name
25
+ end
26
+
27
+ # Taken from https://github.com/lukebayes/project-sprouts/blob/master/lib/sprout/string.rb
28
+ # "FooBar".snake_case #=> "foo_bar"
29
+ def snake_case
30
+ gsub(/\B[A-Z]/, '_\&').downcase
31
+ end
32
+
33
+ # "foo_bar".camel_case #=> "FooBar"
34
+ def camel_case
35
+ str = gsub(/^[a-z]|_+[a-z]/) { |a| a.upcase }
36
+ str.gsub(/_/, '')
37
+ end
38
+
39
+ def dash_case
40
+ self.snake_case.gsub('_', '-')
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,17 @@
1
+ class Jeweler
2
+ require File.dirname(__FILE__)+'/pre_release_to_git'
3
+ require File.dirname(__FILE__)+'/pre_release_gemspec'
4
+
5
+ def prerelease_to_git
6
+ Jeweler::Commands::PreReleaseToGit.build_for(self).run
7
+ end
8
+
9
+ def prerelease_gemspec
10
+ Jeweler::Commands::PreReleaseGemspec.build_for(self).run
11
+ end
12
+
13
+ def is_prerelease_version?
14
+ version.end_with? ".pre"
15
+ end
16
+
17
+ end
@@ -0,0 +1,50 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+ require File.dirname(__FILE__)+"/jeweler"
4
+
5
+ class Jeweler
6
+ class PrereleaseTasks < Rake::TaskLib
7
+ attr_accessor :jeweler
8
+
9
+ def initialize
10
+ yield self if block_given?
11
+
12
+ define
13
+ end
14
+
15
+ def jeweler
16
+ @jeweler ||= Rake.application.jeweler
17
+ end
18
+
19
+ def define
20
+ namespace :git do
21
+ desc "Tag and push prerelease to git. (happens by default with `rake prerelease`)"
22
+ task :prerelease do
23
+ jeweler.prerelease_to_git
24
+ end
25
+ end
26
+
27
+ namespace :gemspec do
28
+ desc "Regenerate and validate gemspec, and then commits and pushes to git on develop branch"
29
+ task :prerelease do
30
+ jeweler.prerelease_gemspec
31
+ end
32
+ end
33
+
34
+ desc "Verifies that it is a prerelease version."
35
+ task :is_prerelease_version => :version_required do
36
+ abort "it's not a prerelease version" unless jeweler.is_prerelease_version?
37
+ end
38
+
39
+ namespace :rubygems do
40
+ desc "Release gem to Gemcutter"
41
+ task :release => [:gemspec, :build] do
42
+ jeweler.release_gem_to_rubygems
43
+ end
44
+ end
45
+
46
+ desc "Make a prerelease to rubygems."
47
+ task :prerelease => [:is_prerelease_version, 'gemspec:prerelease', 'git:prerelease', 'rubygems:release']
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,80 @@
1
+ class Jeweler
2
+ module Commands
3
+ class PreReleaseGemspec
4
+ attr_accessor :gemspec, :version, :repo, :output, :gemspec_helper, :base_dir
5
+
6
+ def initialize(attributes = {})
7
+ self.output = $stdout
8
+
9
+ attributes.each_pair do |key, value|
10
+ send("#{key}=", value)
11
+ end
12
+ end
13
+
14
+ def run
15
+ unless clean_staging_area?
16
+ system "git status"
17
+ raise "Unclean staging area! Be sure to commit or .gitignore everything first. See `git status` above."
18
+ end
19
+
20
+ repo.checkout('develop')
21
+
22
+ regenerate_gemspec!
23
+ commit_gemspec! if gemspec_changed?
24
+
25
+ output.puts "Pushing develop to origin"
26
+ repo.push
27
+ end
28
+
29
+ def clean_staging_area?
30
+ # surprisingly simpler than ruby-git
31
+ `git ls-files --deleted --modified --others --exclude-standard` == ""
32
+ end
33
+
34
+ def commit_gemspec!
35
+ gemspec_gitpath = working_subdir.join(gemspec_helper.path)
36
+ repo.add(gemspec_gitpath.to_s)
37
+ output.puts "Committing #{gemspec_gitpath}"
38
+ repo.commit "Regenerate gemspec for version #{version}"
39
+ end
40
+
41
+ def regenerate_gemspec!
42
+ gemspec_helper.update_version(version)
43
+ gemspec_helper.write
44
+ end
45
+
46
+ def gemspec_changed?
47
+ # OMGHAX. ruby-git status always ends up being 'M', so let's do it a crazy way
48
+ system "git status -s #{working_subdir.join(gemspec_helper.path)} | grep #{working_subdir.join(gemspec_helper.path)} > /dev/null 2>/dev/null"
49
+ end
50
+
51
+ def gemspec_helper
52
+ @gemspec_helper ||= Jeweler::GemSpecHelper.new(self.gemspec, self.base_dir)
53
+ end
54
+
55
+ def working_subdir
56
+ return @working_subdir if @working_subdir
57
+ cwd = base_dir_path
58
+ @working_subdir = cwd.relative_path_from(Pathname.new(repo.dir.path))
59
+ @working_subdir
60
+ end
61
+
62
+ def base_dir_path
63
+ Pathname.new(base_dir).realpath
64
+ end
65
+
66
+ def self.build_for(jeweler)
67
+ command = self.new
68
+
69
+ command.base_dir = jeweler.base_dir
70
+ command.gemspec = jeweler.gemspec
71
+ command.version = jeweler.version
72
+ command.repo = jeweler.repo
73
+ command.output = jeweler.output
74
+ command.gemspec_helper = jeweler.gemspec_helper
75
+
76
+ command
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,59 @@
1
+ class Jeweler
2
+ module Commands
3
+ class PreReleaseToGit
4
+ attr_accessor :gemspec, :version, :repo, :output, :gemspec_helper, :base_dir
5
+
6
+ def initialize(attributes = {})
7
+ self.output = $stdout
8
+
9
+ attributes.each_pair do |key, value|
10
+ send("#{key}=", value)
11
+ end
12
+ end
13
+
14
+ def run
15
+ unless clean_staging_area?
16
+ system "git status"
17
+ raise "Unclean staging area! Be sure to commit or .gitignore everything first. See `git status` above."
18
+ end
19
+
20
+ repo.checkout('develop')
21
+ repo.push
22
+
23
+ if release_not_tagged?
24
+ output.puts "Tagging #{release_tag}"
25
+ repo.add_tag(release_tag)
26
+
27
+ output.puts "Pushing #{release_tag} to origin"
28
+ repo.push('origin', release_tag)
29
+ end
30
+ end
31
+
32
+ def clean_staging_area?
33
+ `git ls-files --deleted --modified --others --exclude-standard` == ""
34
+ end
35
+
36
+ def release_tag
37
+ "v#{version}"
38
+ end
39
+
40
+ def release_not_tagged?
41
+ tag = repo.tag(release_tag) rescue nil
42
+ tag.nil?
43
+ end
44
+
45
+ def self.build_for(jeweler)
46
+ command = self.new
47
+
48
+ command.base_dir = jeweler.base_dir
49
+ command.gemspec = jeweler.gemspec
50
+ command.version = jeweler.version
51
+ command.repo = jeweler.repo
52
+ command.output = jeweler.output
53
+ command.gemspec_helper = jeweler.gemspec_helper
54
+
55
+ command
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,46 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Gator::AS3::GeneratorCollection do
4
+
5
+ before(:each) do
6
+ FileUtils.mkdir_p SANDBOX_LOCATION
7
+ end
8
+
9
+ after(:each) do
10
+ FileUtils.rm_r(SANDBOX_LOCATION) if File.directory? SANDBOX_LOCATION
11
+ end
12
+
13
+ it "should have the correct definition" do
14
+ gator = GatorProcess.new SANDBOX_LOCATION
15
+ gator.should_receive(:fork) do |&block|
16
+ block.call
17
+ require File.dirname(__FILE__) + "/../../../lib/gator/as3/generators"
18
+ Gator::AS3::GeneratorCollection.definition[:command].should == "as3"
19
+ end
20
+ gator.run_with_default_mock
21
+ end
22
+
23
+ it "should be registered as a subcommand on Gator::GenerateCommand" do
24
+ gator = GatorProcess.new SANDBOX_LOCATION
25
+ gator.should_receive(:fork) do |&block|
26
+ block.call
27
+ require File.dirname(__FILE__) + "/../../../lib/gator/as3/generators"
28
+ Gator::GenerateCommand.get_subcommand("as3").should == Gator::AS3::GeneratorCollection
29
+ end
30
+ gator.run_with_default_mock
31
+ end
32
+
33
+ it "should have the correct generators registered" do
34
+ gator = GatorProcess.new SANDBOX_LOCATION
35
+ gator.should_receive(:fork) do |&block|
36
+ block.call
37
+ require File.dirname(__FILE__) + "/../../../lib/gator/as3/generators"
38
+ Gator::AS3::GeneratorCollection.get_subcommand("klass").should == Gator::AS3::ClassGenerator
39
+ Gator::AS3::GeneratorCollection.get_subcommand("event").should == Gator::AS3::EventGenerator
40
+ Gator::AS3::GeneratorCollection.get_subcommand("interface").should == Gator::AS3::InterfaceGenerator
41
+ end
42
+ gator.run_with_default_mock
43
+ end
44
+
45
+
46
+ end
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Gator::AS3::EventGenerator do
4
+
5
+ before(:each) do
6
+ FileUtils.mkdir_p SANDBOX_LOCATION
7
+ end
8
+
9
+ after(:each) do
10
+ FileUtils.rm_r(SANDBOX_LOCATION) if File.directory? SANDBOX_LOCATION
11
+ end
12
+
13
+ it "should create a file in the correct location" do
14
+ gator = GatorProcess.new SANDBOX_LOCATION
15
+ gator.should_receive(:fork) do |&block|
16
+ block.call
17
+ require File.dirname(__FILE__) + "/../../../lib/gator/as3/generators"
18
+ Gator::AS3::EventGenerator.start("org.devboy.MyShinyClass".split(" "))
19
+ File.exist?(File.join(Gator::Project.project.path(:source, :main, :as3), "org/devboy/MyShinyClass.as")).should == true
20
+ end
21
+ gator.run_with_default_mock
22
+ end
23
+
24
+ it "should have the correct values" do
25
+ gator = GatorProcess.new SANDBOX_LOCATION
26
+ gator.should_receive(:fork) do |&block|
27
+ block.call
28
+ require File.dirname(__FILE__) + "/../../../lib/gator/as3/generators"
29
+ generator = Gator::AS3::EventGenerator.new("org.devboy.MyShinyClass".split(" "))
30
+ generator.invoke_all
31
+ generator.package_name.should == "org.devboy"
32
+ generator.class_name.should == "MyShinyClass"
33
+ generator.template_file.should == "as3/event.as.tt"
34
+
35
+ end
36
+ gator.run_with_default_mock
37
+ end
38
+
39
+
40
+ end