chester 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Tom Wilson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "chester"
8
+ gem.summary = %Q{MVC for Titanium Developer}
9
+ gem.description = %Q{This project use coffeescript and MVC to create an awesome framework for the Titanium system!}
10
+ gem.email = "tom@jackhq.com"
11
+ gem.homepage = "http://github.com/twilson63/chester"
12
+ gem.authors = ["Tom Wilson"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_dependency "erubis", ">= 2.6.5"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "chester #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/chester ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+
5
+
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
7
+
8
+ require 'chester'
9
+ require 'chester/command'
10
+
11
+ args = ARGV.dup
12
+ ARGV.clear
13
+ command = args.shift.strip rescue 'help'
14
+
15
+ Chester::Command.run(command, args)
@@ -0,0 +1,21 @@
1
+ require 'helpers'
2
+ require 'commands/base'
3
+
4
+ Dir["#{File.dirname(__FILE__)}/commands/*"].each { |c| require c }
5
+
6
+ module Chester
7
+ module Command
8
+ class << self
9
+ def run(command, args)
10
+ run_internal(command, args)
11
+ end
12
+
13
+ def run_internal(command, args)
14
+ klass = eval("Chester::Command::#{command.capitalize}")
15
+ runner = klass.new(args)
16
+ runner.send(:index)
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ module Chester::Command
2
+ class Base
3
+ include Chester::Helpers
4
+
5
+ attr_accessor :args
6
+ def initialize(args)
7
+ @args = args
8
+ end
9
+
10
+ def display(msg, newline=true)
11
+ if newline
12
+ puts(msg)
13
+ else
14
+ print(msg)
15
+ STDOUT.flush
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ module Chester::Command
2
+ class Brew < Base
3
+ def index
4
+ display "Start Brewing"
5
+ Dir.glob("#{File.pwd}/**/*.coffee").each do |f|
6
+ system "coffee -c #{f}"
7
+ display "Brewed #{f}..."
8
+ end
9
+ display "Finished Brewing...."
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,43 @@
1
+ require 'erubis'
2
+
3
+ module Chester::Command
4
+ class Generate < Base
5
+ def index
6
+ if args.length < 2
7
+ display 'Please enter [controller|model|view] [name]'
8
+ elsif args.first =~ /^(controller|model|view)$/
9
+ create_folder args.first + 's'
10
+ name = args[1].capitalize
11
+ action = args[2] || 'index'
12
+
13
+ input = File.read(File.dirname(__FILE__) + "/../templates/#{args.first}.coffee.erb")
14
+ File.open get_filename(args.first, name, action), 'w' do |f|
15
+ f.write Erubis::Eruby.new(input).result(:name => name, :action => action)
16
+ end
17
+
18
+ display 'modify app.coffee'
19
+ else
20
+ display "#{args.first} not valid command"
21
+ end
22
+ end
23
+
24
+ def create_folder(folder_name)
25
+ display 'create folder ' + args.first + 's if does not exist'
26
+ FileUtils.mkdir_p args.first + 's'
27
+ end
28
+
29
+ def get_filename(file_type, filename, action = 'index')
30
+ result = "#{FileUtils.pwd}/#{file_type + 's'}/#{filename.downcase}"
31
+ if file_type == 'controller'
32
+ result += "_#{args.first}.coffee"
33
+ elsif file_type == 'view'
34
+ FileUtils.mkdir_p result + 's'
35
+ result += "s/#{action}.coffee"
36
+ else
37
+ result += ".coffee"
38
+ end
39
+ end
40
+
41
+
42
+ end
43
+ end
@@ -0,0 +1,8 @@
1
+ module Chester::Command
2
+ class Install < Base
3
+ def index
4
+ FileUtils.cp File.dirname(__FILE__) + '/../templates/chester.coffee', FileUtils.pwd
5
+ display 'installed chester.coffee in to the working directory....'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,23 @@
1
+ module Chester
2
+ module Helpers
3
+ def home_directory
4
+ running_on_windows? ? ENV['USERPROFILE'] : ENV['HOME']
5
+ end
6
+
7
+ def running_on_windows?
8
+ RUBY_PLATFORM =~ /mswin32|mingw32/
9
+ end
10
+
11
+ def running_on_a_mac?
12
+ RUBY_PLATFORM =~ /-darwin\d/
13
+ end
14
+ end
15
+ end
16
+
17
+ unless String.method_defined?(:shellescape)
18
+ class String
19
+ def shellescape
20
+ empty? ? "''" : gsub(/([^A-Za-z0-9_\-.,:\/@\n])/n, '\\\\\\1').gsub(/\n/, "'\n'")
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,42 @@
1
+ class Base
2
+ name: "Base"
3
+ children: []
4
+ find: (name) ->
5
+ for child in this.children
6
+ if child.name == name
7
+ result: child
8
+ break
9
+ result
10
+
11
+ add: (child) ->
12
+ this.children[this.children.length]: child
13
+
14
+
15
+ class Application extends Base
16
+ version: "0.0.1"
17
+ run: (options) ->
18
+ this.find(options.controller)[options.action ?= 'index'](options.params ?= {} )
19
+
20
+
21
+
22
+ class Controller extends Base
23
+ name: "Controller"
24
+
25
+
26
+ class View extends Base
27
+ name: "View"
28
+ data: ->
29
+ result = {}
30
+ for child in this.children
31
+ result[child.name] = child.value
32
+ result
33
+
34
+ render: ->
35
+ print "Not Implemented"
36
+
37
+ Chester.View = View;
38
+ Chester.Controller = Controller;
39
+ Chester.Application = new Application();
40
+ Chester.Application.Models = new Base();
41
+
42
+
@@ -0,0 +1,5 @@
1
+ class <%= name %>Controller extends Chester.Controller
2
+ name: '<%= name %>Controller'
3
+
4
+ # Register Controller to application
5
+ Chester.Application.add(new <%= name %>Controller())
@@ -0,0 +1,5 @@
1
+ class <%= name %>
2
+ name: '<%= name %>'
3
+ # Insert your code here
4
+
5
+ Chester.Application.Models.add(new <%= name %>())
@@ -0,0 +1,7 @@
1
+ class <%= name %><%= action.capitalize %> extends Chester.View
2
+ name: "<%= action %>"
3
+ render: ->
4
+ # TODO: add your presentation code here.
5
+
6
+ # Register view to Patients Controller
7
+ Chester.Application.find("<%= name %>Controller").add(new <%= name %><%= action.capitalize %>())
data/lib/chester.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'fileutils'
2
+ require 'erubis'
3
+
4
+ module Chester; end
5
+
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/chester')
7
+
8
+ #require 'client'
data/readme.md ADDED
@@ -0,0 +1,143 @@
1
+ # Chester
2
+
3
+ A MVC framework for Titanium Developer.
4
+
5
+ The purpose of this framework is to organize your Titanium Developer projects in a model-view-controller pattern.
6
+
7
+ # Why
8
+
9
+ Titanium Developer is an awesome javascript sdk for building mobile applications, but there is no conventions on how to organize your code. We build web applications using Ruby on Rails, and being able to organize our iPad applications using the same patterns will enable us to process and maintain our software projects more effectively.
10
+
11
+ # Requirements
12
+
13
+ * node.js
14
+ * coffeescript
15
+
16
+ # Install
17
+
18
+ <pre>
19
+ <code>
20
+ gem install chester
21
+ </code>
22
+ </pre>
23
+
24
+ # Add to any Titanium Developer Project
25
+
26
+ Just run chester install, and it will create the chester.coffee file in your Resources folder.
27
+
28
+ <pre>
29
+ <code>
30
+ chester install ./Resources
31
+ </code>
32
+ </pre>
33
+
34
+ # Easy to compile the coffee files to javascript
35
+
36
+ <pre>
37
+ <code>
38
+ cd ./Resources
39
+ chester brew
40
+ </code>
41
+ </pre>
42
+
43
+
44
+ # Easy to generate models|views|controllers
45
+
46
+ <pre>
47
+ <code>
48
+ cd ./Resources
49
+ chester generate model person
50
+ chester generate controller people
51
+ chester generate view people index
52
+ </code>
53
+ </pre>
54
+
55
+ These generators will make the following objects:
56
+
57
+ - models
58
+ - person.coffee
59
+
60
+ <pre>
61
+ <code>
62
+ class Person
63
+ name: 'Person'
64
+ # Insert your code here
65
+
66
+ Chester.Application.Models.add(new Person())
67
+ </code>
68
+ </pre>
69
+
70
+ Just a quick run down on what is going on here, inorder for chester to know your model, you must have an attribute called name, which should act as a name that chester can understand, then the model needs to be registered to the application object so that chester can find your model when you request it.
71
+
72
+
73
+ - controllers
74
+ - people.coffee
75
+
76
+ <pre>
77
+ <code>
78
+ class PeopleController extends Chester.Controller
79
+ name: 'PeopleController'
80
+
81
+ # Register Controller to application
82
+ Chester.Application.add(new PeopleController())
83
+
84
+ </code>
85
+ </pre>
86
+
87
+ Same as the model the controller needs to have an attribute called name that is the actual name used for chester to recognize the controller.
88
+
89
+ - views
90
+ - people
91
+ - index.coffee
92
+
93
+ <pre>
94
+ <code>
95
+ class PeopleIndex extends Chester.View
96
+ name: "index"
97
+ render: ->
98
+ # TODO: add your presentation code here.
99
+
100
+ # Register view to Patients Controller
101
+ Chester.Application.find("PeopleController").add(new PeopleIndex())
102
+
103
+ </code>
104
+ </pre>
105
+
106
+
107
+ # Framework
108
+
109
+ The object hierarchy is very straight forward. Chester has a base object that has a collection called children, and a add method that adds a object to the children array and a find method that locates and returns the object based on the name of the object.
110
+
111
+ ## Base
112
+
113
+ This is the core class definition that all other classes share.
114
+
115
+ ## Application
116
+
117
+ This objects children are controllers, with the add method you can add new controller to this object. And with the find method you can locate the controller by the name of the controller. There is another array of objects attached to this class. They are called models, these are basic classes that can added to the Models array.
118
+
119
+ ## Controller
120
+
121
+ This objects children are views, these are not the same as views in titanium, these are simple JavaScript classes that are used to contain the user interface code to manage your mobile application.
122
+
123
+ ## View
124
+
125
+ This will be the most confusing class, because the ui objects in titanium are user views. the Chester views are more like code containers that help isolate your user interface code from your business logic and domain logic.
126
+
127
+ ## Application.run
128
+
129
+ This is the main routing method that makes the whole application work. It takes the following parameters as a JavaScript object.
130
+
131
+ * Controller: string,
132
+ * Action: string,
133
+ * Params: object
134
+
135
+ This method simply finds the controller and executes the action method on the controller , passing the params object as the parameter.
136
+
137
+ Chester is built using coffee, because it is much easier to maintain, but you don't need to use coffeescript to use Chester, you can use JavaScript just fine.
138
+
139
+ # Get Involved
140
+
141
+ * Submit a pull request!
142
+ * Report an issue on twitter.com/jackhq using #Ti.chester
143
+
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Chester" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'chester'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
@@ -0,0 +1,7 @@
1
+ class PatientIndex extends Chester.View
2
+ name: "index"
3
+ render: ->
4
+ # TODO: add your presentation code here.
5
+
6
+ # Register view to Patients Controller
7
+ Chester.Application.find("PatientController").add(new PatientIndex())
@@ -0,0 +1,7 @@
1
+ class PatientNew extends Chester.View
2
+ name: "new"
3
+ render: ->
4
+ # TODO: add your presentation code here.
5
+
6
+ # Register view to Patients Controller
7
+ Chester.Application.find("PatientController").add(new PatientNew())
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chester
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tom Wilson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-05-06 00:00:00 -04:00
13
+ default_executable: chester
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.9
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: erubis
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.6.5
34
+ version:
35
+ description: This project use coffeescript and MVC to create an awesome framework for the Titanium system!
36
+ email: tom@jackhq.com
37
+ executables:
38
+ - chester
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ files:
44
+ - .document
45
+ - .gitignore
46
+ - LICENSE
47
+ - Rakefile
48
+ - VERSION
49
+ - bin/chester
50
+ - lib/chester.rb
51
+ - lib/chester/command.rb
52
+ - lib/chester/commands/base.rb
53
+ - lib/chester/commands/brew.rb
54
+ - lib/chester/commands/generate.rb
55
+ - lib/chester/commands/install.rb
56
+ - lib/chester/helpers.rb
57
+ - lib/chester/templates/chester.coffee
58
+ - lib/chester/templates/controller.coffee.erb
59
+ - lib/chester/templates/model.coffee.erb
60
+ - lib/chester/templates/view.coffee.erb
61
+ - readme.md
62
+ - spec/chester_spec.rb
63
+ - spec/spec.opts
64
+ - spec/spec_helper.rb
65
+ - views/patient/index.coffee
66
+ - views/patient/new.coffee
67
+ has_rdoc: true
68
+ homepage: http://github.com/twilson63/chester
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options:
73
+ - --charset=UTF-8
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ version:
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: "0"
87
+ version:
88
+ requirements: []
89
+
90
+ rubyforge_project:
91
+ rubygems_version: 1.3.5
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: MVC for Titanium Developer
95
+ test_files:
96
+ - spec/chester_spec.rb
97
+ - spec/spec_helper.rb