motion-util 0.1.0

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 ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .DS_Store
6
+ *.xcworkspace
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in motion-util.gemspec
4
+ gemspec
data/LICENCE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012, ITO SOFT DESIGN Inc.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
14
+ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
16
+ SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
17
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
18
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
19
+ OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
20
+ IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
21
+ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
22
+ OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ Motion Uitl
2
+ ===
3
+
4
+ Convenient command set for Ruby Motion.
5
+
6
+ Installation
7
+ ===
8
+
9
+ >gem install motion-util
10
+
11
+
12
+ Usage
13
+ ===
14
+
15
+ >motion-util generate model Foo
16
+ >motion-util generate controller Foo
17
+ >motion-util generate view Foo
18
+ >motion-util generate view_controller Foo
19
+ >motion-util generate table_view_controller Foo
20
+ >motion-util generate navigation_controller Foo
21
+ >motion-util generate tab_bar_controller Foo
22
+
23
+ You can also describe like this:
24
+ >motion-util g model Foo
25
+ >motion-util generation model Foo
26
+
27
+ Licence
28
+ ===
29
+ BSD Licence
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList['test/test*.rb']
7
+ t.verbose = true
8
+ end
data/bin/motion-util ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require 'rubygems'
5
+ require 'motion-util'
6
+
7
+
8
+ Version = Motion::Util::VERSION
9
+
10
+ opt = OptionParser.new
11
+
12
+ opt.banner = Motion::Util::Dispatcher::usage
13
+
14
+
15
+ argv = opt.parse(ARGV)
16
+
17
+ if argv.size == 0
18
+ argv.unshift "--help"
19
+ argv = opt.parse(argv)
20
+ exit
21
+ end
22
+
23
+ Motion::Util::Dispatcher.dispatcher.run
@@ -0,0 +1,111 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Motion
3
+ module Util
4
+
5
+ class Generator
6
+
7
+ def initialize
8
+ d = File.dirname(__FILE__).split("/")[0..-4]
9
+ d << "template"
10
+ @project_path = Dir.pwd
11
+ @template_dir = File.join d
12
+ end
13
+
14
+ def destination_dir
15
+ case file_type.to_s
16
+ when "general"
17
+ "app"
18
+ when /controller/
19
+ "app/controller"
20
+ else
21
+ "app/#{file_type}"
22
+ end
23
+ end
24
+
25
+ def destination_path
26
+ case file_type
27
+ when /controller/
28
+ "#{destination_dir}/#{class_file_name}_#{file_type}.rb"
29
+ else
30
+ "#{destination_dir}/#{class_file_name}.rb"
31
+ end
32
+ end
33
+
34
+ def spec_destination_path
35
+ d = destination_path.gsub /^app/, "spec"
36
+ d.gsub /\.rb$/, "_spec.rb"
37
+ end
38
+
39
+ def context
40
+ c = File.read File.join(@template_dir, "class", file_type + ".rb")
41
+ c.gsub! /#\{class_name\}/, class_name
42
+ c
43
+ end
44
+
45
+ def spec_context
46
+ c = File.read File.join(@template_dir, "spec", "spec.rb")
47
+ c.gsub! /#\{class_name\}/, class_name
48
+ c
49
+ end
50
+
51
+
52
+ def run
53
+ make_file
54
+ make_spec_file
55
+ end
56
+
57
+ private
58
+
59
+ def make_file
60
+ d = File.join @project_path, destination_path
61
+ unless File.exist? d
62
+ FileUtils.mkdir_p File.dirname(d)
63
+ File.open(d, "w") do |f|
64
+ f.write context
65
+ end
66
+ $stdout.puts "\tcreate: #{destination_path}"
67
+ else
68
+ $stderr.puts "#{destination_path} is already created!"
69
+ end
70
+ end
71
+
72
+ def make_spec_file
73
+ d = File.join @project_path, spec_destination_path
74
+ unless File.exist? d
75
+ FileUtils.mkdir_p File.dirname(d)
76
+ File.open(d, "w") do |f|
77
+ f.write spec_context
78
+ end
79
+ $stdout.puts "\tcreate: #{spec_destination_path}"
80
+ else
81
+ $stderr.puts "#{spec_destination_path} is already created!"
82
+ end
83
+ end
84
+
85
+ def file_type
86
+ case ARGV[1]
87
+ when /model/i, /controller/i, /view/i
88
+ @file_type = ARGV[1].downcase
89
+ else
90
+ @file_type = "general"
91
+ end if @file_type.nil?
92
+ @file_type
93
+ end
94
+
95
+ def class_name
96
+ case file_type
97
+ when :general
98
+ @class_name = ARGV[1].capitalize
99
+ else
100
+ @class_name = ARGV[2].capitalize
101
+ end if @class_name.nil?
102
+ @class_name
103
+ end
104
+
105
+ def class_file_name
106
+ class_name.downcase
107
+ end
108
+
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,45 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Motion
3
+ module Util
4
+
5
+ class Dispatcher
6
+
7
+ # --- class methods
8
+ class << self
9
+
10
+ def dispatcher
11
+ @@despatcher ||= self.new
12
+ end
13
+
14
+ def usage
15
+ <<-EOF
16
+ Usage:
17
+ motion-util: command [options]
18
+
19
+ Usage:
20
+
21
+ EOF
22
+ end
23
+
24
+ end
25
+
26
+
27
+ # --- instance methoods
28
+ def run
29
+ cmd = nil
30
+ case ARGV[0]
31
+ when "generate", "generator", "g"
32
+ cmd = Generator.new
33
+ end
34
+ if cmd
35
+ cmd.run
36
+ else
37
+ $stderr.puts self.class.usage
38
+ exit
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,6 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Motion
3
+ module Util
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "optparse"
3
+ require "fileutils"
4
+
5
+ require "motion-util/version"
6
+ require "motion-util/util"
7
+ require "motion-util/command/generator"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "motion-util/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "motion-util"
7
+ s.version = Motion::Util::VERSION
8
+ s.authors = ["Katsuyoshi Ito"]
9
+ s.email = ["kito@itosoft.com"]
10
+ s.homepage = "https://github.com/katsuyoshi/motion-util"
11
+ s.summary = %q{Convenient command set for Ruby Motion.}
12
+ s.description = %q{It generate class and spec files.}
13
+
14
+ s.rubyforge_project = "motion-util"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
@@ -0,0 +1,3 @@
1
+ # -*- coding: utf-8 -*-
2
+ class #{class_name}Controller
3
+ end
@@ -0,0 +1,3 @@
1
+ # -*- coding: utf-8 -*-
2
+ class #{class_name}
3
+ end
@@ -0,0 +1,3 @@
1
+ # -*- coding: utf-8 -*-
2
+ class #{class_name}NavigationController < UINavigationController
3
+ end
@@ -0,0 +1,3 @@
1
+ # -*- coding: utf-8 -*-
2
+ class #{class_name}TabBarController < UITabBarController
3
+ end
@@ -0,0 +1,3 @@
1
+ # -*- coding: utf-8 -*-
2
+ class #{class_name}TableViewController < UITableViewController
3
+ end
@@ -0,0 +1,3 @@
1
+ # -*- coding: utf-8 -*-
2
+ class #{class_name}View < UIView
3
+ end
@@ -0,0 +1,3 @@
1
+ # -*- coding: utf-8 -*-
2
+ class #{class_name}ViewController < UIViewController
3
+ end
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ describe #{class_name} do
3
+
4
+ it "should be successful" do
5
+ true.should be_true
6
+ end
7
+
8
+ end
@@ -0,0 +1,149 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test-unit'
3
+ require 'motion-util'
4
+
5
+
6
+ include Motion::Util
7
+
8
+ class TestGenerate < Test::Unit::TestCase
9
+
10
+ def setup
11
+ ARGV.replace %w(generate)
12
+ @generator = Generator.new
13
+ end
14
+
15
+ test "destination_dir path shoudle be 'app'" do
16
+ assert_equal "app", @generator.destination_dir
17
+ end
18
+
19
+ test "destination_path shoudle be 'app/model/foo.rb' with model, foo" do
20
+ ARGV.replace %w(generate model foo)
21
+ assert_equal "app/model/foo.rb", @generator.destination_path
22
+ end
23
+
24
+ test "destination_path shoudle be 'app/view/foo.rb' with view, foo" do
25
+ ARGV.replace %w(generate view foo)
26
+ assert_equal "app/view/foo.rb", @generator.destination_path
27
+ end
28
+
29
+ test "destination_path shoudle be 'app/controller/foo_controller.rb' with controller, foo" do
30
+ ARGV.replace %w(generate controller foo)
31
+ assert_equal "app/controller/foo_controller.rb", @generator.destination_path
32
+ end
33
+
34
+ test "destination_path shoudle be 'app/controller/foo_view_controller.rb' with view_controller, foo" do
35
+ ARGV.replace %w(generate view_controller foo)
36
+ assert_equal "app/controller/foo_view_controller.rb", @generator.destination_path
37
+ end
38
+
39
+ test "destination_path shoudle be 'app/controller/foo_table_view_controller.rb' with table_view_controller, foo" do
40
+ ARGV.replace %w(generate table_view_controller foo)
41
+ assert_equal "app/controller/foo_table_view_controller.rb", @generator.destination_path
42
+ end
43
+
44
+ test "destination_path shoudle be 'app/controller/foo_navigation_controller.rb' with table_view_controller, foo" do
45
+ ARGV.replace %w(generate navigation_controller foo)
46
+ assert_equal "app/controller/foo_navigation_controller.rb", @generator.destination_path
47
+ end
48
+
49
+ test "destination_path shoudle be 'app/controller/foo_tab_bar_controller.rb' with tab_bar_view_controller, foo" do
50
+ ARGV.replace %w(generate tab_bar_controller foo)
51
+ assert_equal "app/controller/foo_tab_bar_controller.rb", @generator.destination_path
52
+ end
53
+
54
+ test "spec_destination_path shoudle be 'spec/controller/foo_tab_bar_controller.rb' with tab_bar_view_controller, foo" do
55
+ ARGV.replace %w(generate tab_bar_controller foo)
56
+ assert_equal "spec/controller/foo_tab_bar_controller_spec.rb", @generator.spec_destination_path
57
+ end
58
+
59
+
60
+ # --- context
61
+ test "check model file context" do
62
+ ARGV.replace %w(generate model foo)
63
+ expected = <<-EOF
64
+ # -*- coding: utf-8 -*-
65
+ class Foo
66
+ end
67
+ EOF
68
+ assert_equal expected, @generator.context
69
+ end
70
+
71
+ test "check controller file context" do
72
+ ARGV.replace %w(generate controller foo)
73
+ expected = <<-EOF
74
+ # -*- coding: utf-8 -*-
75
+ class FooController
76
+ end
77
+ EOF
78
+ assert_equal expected, @generator.context
79
+ end
80
+
81
+
82
+ test "check view file context" do
83
+ ARGV.replace %w(generate view foo)
84
+ expected = <<-EOF
85
+ # -*- coding: utf-8 -*-
86
+ class FooView < UIView
87
+ end
88
+ EOF
89
+ assert_equal expected, @generator.context
90
+ end
91
+
92
+ test "check view_controller file context" do
93
+ ARGV.replace %w(generate view_controller foo)
94
+ expected = <<-EOF
95
+ # -*- coding: utf-8 -*-
96
+ class FooViewController < UIViewController
97
+ end
98
+ EOF
99
+ assert_equal expected, @generator.context
100
+ end
101
+
102
+ test "check table_view_controller file context" do
103
+ ARGV.replace %w(generate table_view_controller foo)
104
+ expected = <<-EOF
105
+ # -*- coding: utf-8 -*-
106
+ class FooTableViewController < UITableViewController
107
+ end
108
+ EOF
109
+ assert_equal expected, @generator.context
110
+ end
111
+
112
+ test "check navigation_controller file context" do
113
+ ARGV.replace %w(generate navigation_controller foo)
114
+ expected = <<-EOF
115
+ # -*- coding: utf-8 -*-
116
+ class FooNavigationController < UINavigationController
117
+ end
118
+ EOF
119
+ assert_equal expected, @generator.context
120
+ end
121
+
122
+ test "check tab_bar_controller file context" do
123
+ ARGV.replace %w(generate tab_bar_controller foo)
124
+ expected = <<-EOF
125
+ # -*- coding: utf-8 -*-
126
+ class FooTabBarController < UITabBarController
127
+ end
128
+ EOF
129
+ assert_equal expected, @generator.context
130
+ end
131
+
132
+ # --- spec context
133
+ test "check model spec file context" do
134
+ ARGV.replace %w(generate model foo)
135
+ expected = <<-EOF
136
+ # -*- coding: utf-8 -*-
137
+ describe Foo do
138
+
139
+ it "should be successful" do
140
+ true.should be_true
141
+ end
142
+
143
+ end
144
+ EOF
145
+ assert_equal expected, @generator.spec_context
146
+ end
147
+
148
+ end
149
+
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion-util
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Katsuyoshi Ito
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-19 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: It generate class and spec files.
15
+ email:
16
+ - kito@itosoft.com
17
+ executables:
18
+ - motion-util
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - LICENCE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - bin/motion-util
28
+ - lib/motion-util.rb
29
+ - lib/motion-util/command/generator.rb
30
+ - lib/motion-util/util.rb
31
+ - lib/motion-util/version.rb
32
+ - motion-util.gemspec
33
+ - template/class/controller.rb
34
+ - template/class/model.rb
35
+ - template/class/navigation_controller.rb
36
+ - template/class/tab_bar_controller.rb
37
+ - template/class/table_view_controller.rb
38
+ - template/class/view.rb
39
+ - template/class/view_controller.rb
40
+ - template/spec/spec.rb
41
+ - test/test_generator.rb
42
+ homepage: https://github.com/katsuyoshi/motion-util
43
+ licenses: []
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project: motion-util
62
+ rubygems_version: 1.8.10
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Convenient command set for Ruby Motion.
66
+ test_files:
67
+ - test/test_generator.rb