Skip to content

Commit

Permalink
Merge pull request sproutcore#76 from ChadEubanks/master
Browse files Browse the repository at this point in the history
Statecharts by default when running sc-init.  Use sc-init app --statechart
  • Loading branch information
publickeating committed Dec 20, 2011
2 parents f71f37b + 7522ed5 commit 5f10178
Show file tree
Hide file tree
Showing 20 changed files with 298 additions and 16 deletions.
1 change: 0 additions & 1 deletion lib/frameworks/sproutcore
Submodule sproutcore deleted from d79e36
36 changes: 36 additions & 0 deletions lib/gen/statechart_app/Buildfile
@@ -0,0 +1,36 @@
# ==========================================================================
# Generator: APP
# Copyright: ©2006-2011 Strobe Inc. and contributors
# portions copyright ©2009 Apple Inc.
# ==========================================================================

namespace :generator do

# Require a project then make sure the build root is always the project
# root.
task :prepare do
GENERATOR.requires! :target_project

# if the target name has a slash in it, then we are trying to create a
# nested target. extract the final part (since this is the target name)
# and then set the build root to the parent target.
if GENERATOR.target_name && GENERATOR.target_name =~ /\//
parent_target_name = GENERATOR.target_name.split('/')
GENERATOR.target_name = parent_target_name.pop

parent_target_name = parent_target_name * "/"
project = GENERATOR.target_project

GENERATOR.parent_target_name = parent_target_name
GENERATOR.parent_target = project.target_for(parent_target_name)
GENERATOR.requires! :parent_target, :parent_target_name

GENERATOR.build_root = GENERATOR.parent_target.source_root

# otherwise just use project_root
else
GENERATOR.build_root = GENERATOR.target_project.project_root
end
end

end
1 change: 1 addition & 0 deletions lib/gen/statechart_app/README
@@ -0,0 +1 @@
Your application target is now ready to use!
13 changes: 13 additions & 0 deletions lib/gen/statechart_app/USAGE
@@ -0,0 +1,13 @@
statechart_app - Create a new SproutCore application target using statecharts.

USAGE:

sc-gen app AppName [--filename=FILENAME] [--target=TARGET_NAME]

DISCUSSION:

This generator will create a new SproutCore application with statecharts by default for a particular project. You should pass as the first parameter your AppName you want to create followed by the --statechart switch. For example:

sc-gen app Todos --statechart

This defines a new application called Todos in the file apps/todos/. Within the apps/Todos/resources directory you will have a statechart.js file and a states directory with the ready_state.js file. The statechart.js file sets the initial state of your app to ready. As your app grows. You will create new states within the statechart.js file. In your states folder you will describe the states declared in the statechart.js.
9 changes: 9 additions & 0 deletions lib/gen/statechart_app/templates/apps/@target_name@/Buildfile
@@ -0,0 +1,9 @@
<%= copyright_block(namespace, :ruby) %>

# This is your Buildfile for your app, <%= namespace %>. This tells SproutCore
# how to build your app. These settings override those in your project
# Buildfile, which contains default settings for all apps in your project.

# It is better to add :required targets here than in the global Buildfile.
config :<%= target_name %>, :required => :sproutcore

24 changes: 24 additions & 0 deletions lib/gen/statechart_app/templates/apps/@target_name@/core.js
@@ -0,0 +1,24 @@
<%= copyright_block(namespace) %>
/*globals <%= namespace %> */

/** @namespace
My cool new app. Describe your application.
@extends SC.Object
*/
<%= namespace %> = SC.Application.create(
/** @scope <%= namespace %>.prototype */ {

NAMESPACE: '<%= namespace %>',
VERSION: '0.1.0',

// This is your application store. You will use this store to access all
// of your model data. You can also set a data source on this store to
// connect to a backend server. The default setup below connects the store
// to any fixtures you define.
store: SC.Store.create().from(SC.Record.fixtures)

// TODO: Add global constants or singleton objects needed by your app here.

}) ;
26 changes: 26 additions & 0 deletions lib/gen/statechart_app/templates/apps/@target_name@/main.js
@@ -0,0 +1,26 @@
<%= copyright_block(namespace) %>
/*globals <%= namespace %> */

// This is the function that will start your app running. The default
// implementation will load any fixtures you have created then instantiate
// your controllers and awake the elements on your page.
//
// As you develop your application you will probably want to override this.
// See comments for some pointers on what to do next.
//
<%= namespace %>.main = function main() {

// Step 1: Tell your app it will load via states
var statechart = <%= namespace %>.statechart;
SC.RootResponder.responder.set('defaultResponder', statechart);
statechart.initStatechart();

// Step 2. Set the content property on your primary controller.
// This will make your app come alive!

// TODO: Set the content property on your primary controller
// ex: MyApp.contactsController.set('content', MyApp.contacts);

} ;

function main() { <%= namespace %>.main(); }
@@ -0,0 +1,18 @@
/*
This defines the global $theme variable for use inside your CSS.
The $theme variable holds the CSS class names for your theme.
You can then theme your app by using CSS like this:
$theme.button {
color: blue;
@include slices('white-button.png', $left: 3, $right: 3);
}
Any _theme.css file is prepended to all files inside its directory,
and any subdirectories that don't define their own _theme.css file.
This allows you to give different directories different values for
$theme if you wish.
*/
$theme: '.ace.<%= css_name %>';
@@ -0,0 +1,9 @@
<%% content_for :loading do %>
<%% # Any HTML in this file will be visible on screen while your page loads
# its application JavaScript. SproutCore applications are optimized for
# caching and startup very fast, so your users will often only see this
# content for a brief moment on their first app load, if at all.
%>
<p class="loading">Loading...<p>

<%% end %>
@@ -0,0 +1,21 @@
<%= copyright_block("#{namespace} - mainPage") %>
/*globals <%= namespace %> */

// This page describes the main user interface for your application.
<%= namespace %>.mainPage = SC.Page.design({

// The main pane is made visible on screen as soon as your app is loaded.
// Add childViews to this pane for views to display immediately on page
// load.
mainPane: SC.MainPane.design({
childViews: 'labelView'.w(),

labelView: SC.LabelView.design({
layout: { centerX: 0, centerY: 0, width: 200, height: 18 },
textAlign: SC.ALIGN_CENTER,
tagName: "h1",
value: "Welcome to SproutCore!"
})
})

});
@@ -0,0 +1,8 @@
<%= namespace %>.statechart = SC.Statechart.create({

initialState: 'readyState',

readyState: SC.State.plugin('<%= namespace %>.ReadyState'),
// someOtherState: SC.State.plugin('<%= namespace %>.SomeOtherState')

});
@@ -0,0 +1,12 @@
<%= namespace %>.ReadyState = SC.State.extend({

enterState: function() {
<%= namespace %>.getPath('mainPage.mainPane').append();
},

exitState: function() {
<%= namespace %>.getPath('mainPage.mainPane').remove();
}

});

24 changes: 24 additions & 0 deletions lib/gen/statechart_app/templates/apps/@target_name@/theme.js
@@ -0,0 +1,24 @@
<%= copyright_block(namespace) %>
/*globals <%= namespace %> */

// This is the theme that defines how your app renders.
//
// Your app is given its own theme so it is easier and less
// messy for you to override specific things just for your
// app.
//
// You don't have to create the whole theme on your own, though:
// your app's theme is based on SproutCore's Ace theme.
//
// NOTE: if you want to change the theme this one is based on, don't
// forget to change the :css_theme property in your buildfile.
<%= namespace %>.Theme = SC.AceTheme.create({
name: '<%= css_name %>'
});

// SproutCore needs to know that your app's theme exists
SC.Theme.addTheme(<%= namespace %>.Theme);

// Setting it as the default theme makes every pane SproutCore
// creates default to this theme unless otherwise specified.
SC.defaultTheme = '<%= css_name %>';
45 changes: 45 additions & 0 deletions lib/gen/statechart_project/Buildfile
@@ -0,0 +1,45 @@
# ==========================================================================
# Generator: PROJECT
# Copyright: ©2006-2011 Strobe Inc. and contributors
# portions copyright ©2009 Apple Inc.
# ==========================================================================

namespace :generator do

# Accept the following types of arguments:
#
# project . #=> Make current working directory. like sc-init
# project project_name #=> Create project_name, namespace: ProjectName
# project ProjectName #=> Create project_name, namespace: ProjectName
# project NameSpace path/to/project #=> Create path/to/project, NameSpace
#
task :prepare do
# get arguments & normalize
gen = GENERATOR
namespace = gen.arguments[1]
project_path = gen.arguments[2]

if project_path
project_path = File.expand_path(project_path)
namespace = File.basename(project_path) if namespace == '.'
elsif namespace == '.'
project_path = Dir.pwd
namespace = File.basename(project_path)
else
project_path = Dir.pwd / gen.snake_case(namespace)
end

# Setup standard options for generating a project
gen.target_name = gen.target = gen.method_name = gen.class_name = nil
gen.build_root = File.dirname(project_path) # dir where project dir lives
gen.filename = File.basename(project_path) # project dir name
gen.namespace = gen.camel_case namespace
end

end

# default behavior for a template is to just copy the contents of the
# templates directory to the end destination. Add any additional configs here.
config :templates,
:root_dir => '_file_path_'

7 changes: 7 additions & 0 deletions lib/gen/statechart_project/INIT
@@ -0,0 +1,7 @@
Your new SproutCore project with StateCharts is ready!

To get started, you can find your initial application in the "apps" directory.

Within the apps/appname directory you will have a statechart.js file and a states directory with the ready_state.js file.

The statechart.js file sets the initial state of your app to ready. And as your app grows. You will create new states within the statechart.js file. In your states folder you will describe the states declared in the statechart.js.
1 change: 1 addition & 0 deletions lib/gen/statechart_project/README
@@ -0,0 +1 @@
Your project is now ready to use!
2 changes: 2 additions & 0 deletions lib/gen/statechart_project/USAGE
@@ -0,0 +1,2 @@
Usage:
sc-gen project project_name
9 changes: 9 additions & 0 deletions lib/gen/statechart_project/templates/@filename@/Buildfile
@@ -0,0 +1,9 @@
<%= copyright_block(namespace, :ruby) %>

# This is your Buildfile, which sets build settings for your project.
# For example, this tells SproutCore's build tools that EVERYTHING
# requires the SproutCore framework.
config :all, :required => :sproutcore

# In addition to this Buildfile, which gives settings for your entire project,
# each of your apps has its own Buildfile with settings specific to that app.
3 changes: 3 additions & 0 deletions lib/gen/statechart_project/templates/@filename@/README
@@ -0,0 +1,3 @@
<%= copyright_block(namespace, false) %>

TODO: Describe Your Project
45 changes: 30 additions & 15 deletions lib/sproutcore/tools/init.rb
Expand Up @@ -10,32 +10,47 @@ class Tools

desc "init PROJECT [APP]",
"Generates a SproutCore project with an initial application"
method_options('--dry-run' => false, :force => false, '--template' => false)
method_options('--dry-run' => false, :force => false, '--template' => false, '--statechart' => false)
def init(project_name, app_name=nil)

# Generate the project
project_type = options[:template] ? 'html_project' : 'project'
project_gen = SC.builtin_project.generator_for project_type,
:arguments => ['project', project_name],
:dry_run => options['dry-run'],
:force => options[:force]

project_gen.prepare!.build!


if project_type = options[:template]
project_type = options[:template] ? 'html_project' : 'project'
elsif project_type = options[:statechart]
project_type = options[:statechart] ? 'statechart_project' : 'project'
else project_type = options[:dry_run]
project_type = options[:dry_run] ? 'project' : 'project'
end


# Generate the project
project_gen = SC.builtin_project.generator_for project_type,
:arguments => ['project', project_name],
:dry_run => options['dry-run'],
:force => options[:force]

project_gen.prepare!.build!

# Next, get the project root & app name
project_root = project_gen.build_root / project_gen.filename
app_name = project_gen.filename if app_name.nil?

# And get the app generator and run it
project = SC::Project.load project_root, :parent => SC.builtin_project

app_type = options[:template] ? 'html_app' : 'app'

if project_type = options[:template]
app_type = options[:template] ? 'html_app' : 'app'
elsif project_type = options[:statechart]
app_type = options[:statechart] ? 'statechart_app' : 'app'
else project_type = options[:dry_run]
app_type = options[:dry_run] ? 'app' : 'app'
end

generator = project.generator_for app_type,
:arguments => ['app', app_name],
:dry_run => options['dry-run'],
:force => options[:force]
generator.prepare!.build!

project_gen.log_file(project_gen.source_root / 'INIT')
return 0
end
Expand Down

0 comments on commit 5f10178

Please sign in to comment.