Skip to content

Commit

Permalink
motion-kit templates! initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
colinta committed Jun 15, 2014
0 parents commit 94bf5b8
Show file tree
Hide file tree
Showing 25 changed files with 345 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
/pkg/
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in foobar.gemspec
gemspec
22 changes: 22 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2014 Colin T.A. Gray

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Empty file added README.md
Empty file.
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "bundler/gem_tasks"
13 changes: 13 additions & 0 deletions ext/extconf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'fileutils'

dest_templates_dir = File.expand_path('~/Library/RubyMotion/template/')
FileUtils.mkdir_p(dest_templates_dir) unless File.exist?(dest_templates_dir)

src_templates_dir = File.expand_path(File.join(File.dirname(__FILE__), '../templates'))
template_dirs = %w(mk-ios mk-osx)
template_dirs.each do |template|
src = File.join(src_templates_dir, template)
dest_dir = File.join(dest_templates_dir, template)

FileUtils.ln_s src, dest_dir, :force => true
end
5 changes: 5 additions & 0 deletions lib/motion-kit-templates/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module MotionKit
module Templates
VERSION = '1.0.0'
end
end
21 changes: 21 additions & 0 deletions motion-kit-templates.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- encoding: utf-8 -*-
require File.expand_path('../lib/motion-kit-templates/version.rb', __FILE__)

Gem::Specification.new do |gem|
gem.name = 'motion-kit-templates'
gem.version = MotionKit::Templates::VERSION
gem.licenses = ['BSD']

gem.authors = ['Colin T.A. Gray']
gem.email = ['[email protected]']
gem.summary = %{Create projects with the `motion create --template=motion-kit-...` command.}
gem.description = ''

gem.homepage = 'https://github.com/rubymotion/motion-kit-templates'
gem.extensions = ['ext/extconf.rb']

gem.files = Dir.glob('ext/**/*.rb') + Dir.glob('templates/**/*')
gem.files << 'README.md'

gem.require_paths = ['lib']
end
17 changes: 17 additions & 0 deletions templates/mk-ios/files/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.repl_history
build
tags
app/pixate_code.rb
resources/*.nib
resources/*.momd
resources/*.storyboardc
.DS_Store
nbproject
.redcar
#*#
*~
*.sw[po]
.eprj
.sass-cache
.idea
.dat*.*
4 changes: 4 additions & 0 deletions templates/mk-ios/files/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

gem 'rake'
gem 'motion-kit'
14 changes: 14 additions & 0 deletions templates/mk-ios/files/Rakefile.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project/template/ios'

begin
require 'bundler'
Bundler.require
rescue LoadError
end

Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings.
app.name = '<%= name %>'
end
11 changes: 11 additions & 0 deletions templates/mk-ios/files/app/app_delegate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class AppDelegate
def application(application, didFinishLaunchingWithOptions: options)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
main_ctlr = MainController.new
nav_ctlr = UINavigationController.alloc.initWithRootViewController(main_ctlr)
@window.rootViewController = nav_ctlr
@window.makeKeyAndVisible

true
end
end
11 changes: 11 additions & 0 deletions templates/mk-ios/files/app/main/main_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class MainController < UIViewController

def layout
@layout ||= MainLayout.new
end

def loadView
self.view = layout.view
end

end
15 changes: 15 additions & 0 deletions templates/mk-ios/files/app/main/main_layout.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class MainLayout < MK::Layout

def layout
add UILabel, :remove_me
end

def remove_me_style
text 'Hello!'
text_color UIColor.whiteColor
size_to_fit
center ['50%', '50%']
autoresizing_mask :pin_to_center
end

end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions templates/mk-ios/files/spec/main_spec.rb.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
describe "Application '<%= name %>'" do
before do
@app = UIApplication.sharedApplication
end

it "has one window" do
@app.windows.size.should == 1
end
end
17 changes: 17 additions & 0 deletions templates/mk-osx/files/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.repl_history
build
tags
app/pixate_code.rb
resources/*.nib
resources/*.momd
resources/*.storyboardc
.DS_Store
nbproject
.redcar
#*#
*~
*.sw[po]
.eprj
.sass-cache
.idea
.dat*.*
4 changes: 4 additions & 0 deletions templates/mk-osx/files/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

gem 'rake'
gem 'motion-kit'
14 changes: 14 additions & 0 deletions templates/mk-osx/files/Rakefile.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project/template/osx'

begin
require 'bundler'
Bundler.require
rescue LoadError
end

Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings.
app.name = '<%= name %>'
end
13 changes: 13 additions & 0 deletions templates/mk-osx/files/app/app_delegate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class AppDelegate
attr :main_menu_layout

def applicationDidFinishLaunching(notification)
@main_menu_layout = MainMenu.new
NSApp.mainMenu = @main_menu_layout.menu

@main_controller = MainWindowController.alloc.init
@main_controller.showWindow(self)
@main_controller.window.orderFrontRegardless
end

end
13 changes: 13 additions & 0 deletions templates/mk-osx/files/app/main/main_window_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class MainWindowController < NSWindowController

def layout
@layout ||= MainWindowLayout.new
end

def init
super.tap do
self.window = layout.window
end
end

end
27 changes: 27 additions & 0 deletions templates/mk-osx/files/app/main/main_window_layout.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class MainWindowLayout < MK::WindowLayout
MAIN_WINDOW_IDENTIFIER = 'MAIN_WINDOW'

def layout
frame [[335, 390], [402, 114]], MAIN_WINDOW_IDENTIFIER
styleMask NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask
contentMinSize [402, 92]

add NSTextField, :remove_me
end

def remove_me_style
size [37, 16]
center ['50%', '50%']
autoresizing_mask :pin_to_center
background_color NSColor.clearColor
opaque false

editable false
selectable true
bordered false
bezeled false

string_value 'Hello!'
end

end
55 changes: 55 additions & 0 deletions templates/mk-osx/files/app/main_menu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
class MainMenu < MK::MenuLayout

def layout
add app_menu
add file_menu

add 'Edit' do
add item('Undo', action: 'undo:', keyEquivalent: 'z')
add item('Redo', action: 'redo:', keyEquivalent: 'Z')
add NSMenuItem.separatorItem
add item('Cut', action: 'cut:', keyEquivalent: 'x')
add item('Copy', action: 'copy:', keyEquivalent: 'c')
add item('Paste', action: 'paste:', keyEquivalent: 'v')
item = add item('Paste and Match Style', action: 'pasteAsPlainText:', keyEquivalent: 'V')
item.keyEquivalentModifierMask = NSCommandKeyMask|NSAlternateKeyMask
add item('Delete', action: 'delete:', keyEquivalent: '')
add item('Select All', action: 'selectAll:', keyEquivalent: 'a')
end

add 'Format' do
add 'Font' do
add item('Show Fonts', action: 'orderFrontFontPanel:', keyEquivalent: 't')
add item('Bold', action: 'addFontTrait:', keyEquivalent: 'b')
add item('Italic', action: 'addFontTrait:', keyEquivalent: 'i')
add item('Underline', action: 'underline:', keyEquivalent: 'u')
add NSMenuItem.separatorItem
add item('Bigger', action: 'modifyFont:', keyEquivalent: '+')
add item('Smaller', action: 'modifyFont:', keyEquivalent: '-')
end

add 'Text' do
add item('Align Left', action: 'alignLeft:', keyEquivalent: '{')
add item('Center', action: 'alignCenter:', keyEquivalent: '|')
add item('Justify', action: 'alignJustified:', keyEquivalent: '')
add item('Align Right', action: 'alignRight:', keyEquivalent: '}')
add NSMenuItem.separatorItem
add item('Show Ruler', action: 'toggleRuler:', keyEquivalent: '')
item = add item('Copy Ruler', action: 'copyRuler:', keyEquivalent: 'c')
item.keyEquivalentModifierMask = NSCommandKeyMask|NSControlKeyMask
item = add item('Paste Ruler', action: 'pasteRuler:', keyEquivalent: 'v')
item.keyEquivalentModifierMask = NSCommandKeyMask|NSControlKeyMask
end
end

add 'View' do
item = add item('Show Toolbar', action: 'toggleToolbarShown:', keyEquivalent: 't')
item.keyEquivalentModifierMask = NSCommandKeyMask|NSAlternateKeyMask
add item('Customize Toolbar…', action: 'runToolbarCustomizationPalette:', keyEquivalent: '')
end

NSApp.windowsMenu = add window_menu
NSApp.helpMenu = add help_menu
end

end
29 changes: 29 additions & 0 deletions templates/mk-osx/files/resources/Credits.rtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;}
{\colortbl;\red255\green255\blue255;}
\paperw9840\paperh8400
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural

\f0\b\fs24 \cf0 Engineering:
\b0 \
Some people\
\

\b Human Interface Design:
\b0 \
Some other people\
\

\b Testing:
\b0 \
Hopefully not nobody\
\

\b Documentation:
\b0 \
Whoever\
\

\b With special thanks to:
\b0 \
Mom\
}
9 changes: 9 additions & 0 deletions templates/mk-osx/files/spec/main_spec.rb.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
describe "Application '<%= name %>'" do
before do
@app = NSApplication.sharedApplication
end

it "has one window" do
@app.windows.size.should == 1
end
end

0 comments on commit 94bf5b8

Please sign in to comment.