tres 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +67 -0
- data/README.md +50 -0
- data/Rakefile +16 -0
- data/VERSION +1 -0
- data/bin/tres +103 -0
- data/examples/anagen/anagen.coffee +61 -0
- data/examples/anagen/anagen.css +1413 -0
- data/examples/anagen/anagen.js +182 -0
- data/examples/anagen/anagen.scss +20 -0
- data/examples/anagen/backbone-min.js +38 -0
- data/examples/anagen/index.html +50 -0
- data/examples/anagen/jquery-1.8.0.min.js +2 -0
- data/examples/anagen/templates.coffee +6 -0
- data/examples/anagen/templates.js +13 -0
- data/examples/anagen/tres.js +375 -0
- data/examples/anagen/underscore-min.js +32 -0
- data/font/fontawesome-webfont.eot +0 -0
- data/font/fontawesome-webfont.svg +255 -0
- data/font/fontawesome-webfont.ttf +0 -0
- data/font/fontawesome-webfont.woff +0 -0
- data/javascripts/backbone-min.js +38 -0
- data/javascripts/jquery-1.8.0.min.js +2 -0
- data/javascripts/tres.coffee +210 -0
- data/javascripts/underscore-min.js +32 -0
- data/lib/ext/.filemethods.rb.swp +0 -0
- data/lib/ext/filemethods.rb +109 -0
- data/lib/ext/string.rb +33 -0
- data/lib/tres/app.rb +92 -0
- data/lib/tres/asset_packager.rb +45 -0
- data/lib/tres/errors.rb +6 -0
- data/lib/tres/logger.rb +9 -0
- data/lib/tres/rack_logger.rb +37 -0
- data/lib/tres/server.rb +50 -0
- data/lib/tres/template_compiler.rb +113 -0
- data/lib/tres.rb +64 -0
- data/sass/font-awesome.scss +329 -0
- data/sass/tres/base.scss +131 -0
- data/sass/tres/themes/default.scss +71 -0
- data/spec/app_spec.rb +44 -0
- data/spec/asset_packager_spec.rb +74 -0
- data/spec/filemethods_spec.rb +84 -0
- data/spec/fixtures/index.haml +41 -0
- data/spec/fixtures/index.html +50 -0
- data/spec/sample/assets/javascripts/all.coffee +12 -0
- data/spec/sample/assets/javascripts/anagen.coffee +7 -0
- data/spec/sample/assets/javascripts/backbone-min.js +38 -0
- data/spec/sample/assets/javascripts/jquery-1.8.0.min.js +2 -0
- data/spec/sample/assets/javascripts/underscore-min.js +32 -0
- data/spec/sample/assets/stylesheets/app.scss +7 -0
- data/spec/sample/assets/stylesheets/with_imports.scss +10 -0
- data/spec/sample/templates/article.html +0 -0
- data/spec/sample/templates/book.haml +4 -0
- data/spec/sample/templates/books/li.haml +2 -0
- data/spec/sample/templates/index.html +50 -0
- data/spec/server_spec.rb +35 -0
- data/spec/spec_helper.rb +69 -0
- data/spec/template_compiler_spec.rb +96 -0
- data/templates/all.coffee +21 -0
- data/templates/all.scss +11 -0
- data/templates/app.coffee +10 -0
- data/templates/collection_script.coffee.erb +6 -0
- data/templates/config.ru +3 -0
- data/templates/home.coffee +7 -0
- data/templates/home.haml +17 -0
- data/templates/index.html +15 -0
- data/templates/model_script.coffee.erb +3 -0
- data/templates/screen_script.coffee.erb +5 -0
- data/templates/templates.js +2 -0
- data/tres.gemspec +29 -0
- metadata +257 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
chunky_png (1.2.5)
|
5
|
+
coffee-script (2.2.0)
|
6
|
+
coffee-script-source
|
7
|
+
execjs
|
8
|
+
coffee-script-source (1.3.3)
|
9
|
+
colorize (0.5.8)
|
10
|
+
compass (0.12.2)
|
11
|
+
chunky_png (~> 1.2)
|
12
|
+
fssm (>= 0.2.7)
|
13
|
+
sass (~> 3.1)
|
14
|
+
diff-lcs (1.1.3)
|
15
|
+
execjs (1.4.0)
|
16
|
+
multi_json (~> 1.0)
|
17
|
+
ffi (1.0.11)
|
18
|
+
fssm (0.2.9)
|
19
|
+
haml (3.1.6)
|
20
|
+
hike (1.2.1)
|
21
|
+
json_pure (1.7.3)
|
22
|
+
listen (0.4.7)
|
23
|
+
rb-fchange (~> 0.0.5)
|
24
|
+
rb-fsevent (~> 0.9.1)
|
25
|
+
rb-inotify (~> 0.8.8)
|
26
|
+
multi_json (1.3.6)
|
27
|
+
rack (1.4.1)
|
28
|
+
rake (0.9.2.2)
|
29
|
+
rb-fchange (0.0.5)
|
30
|
+
ffi
|
31
|
+
rb-fsevent (0.9.1)
|
32
|
+
rb-inotify (0.8.8)
|
33
|
+
ffi (>= 0.5.0)
|
34
|
+
rspec (2.11.0)
|
35
|
+
rspec-core (~> 2.11.0)
|
36
|
+
rspec-expectations (~> 2.11.0)
|
37
|
+
rspec-mocks (~> 2.11.0)
|
38
|
+
rspec-core (2.11.1)
|
39
|
+
rspec-expectations (2.11.2)
|
40
|
+
diff-lcs (~> 1.1.3)
|
41
|
+
rspec-mocks (2.11.1)
|
42
|
+
rspec-nc (0.0.2)
|
43
|
+
terminal-notifier (~> 1.4.2)
|
44
|
+
sass (3.1.20)
|
45
|
+
sprockets (2.4.5)
|
46
|
+
hike (~> 1.2)
|
47
|
+
multi_json (~> 1.0)
|
48
|
+
rack (~> 1.0)
|
49
|
+
tilt (~> 1.1, != 1.3.0)
|
50
|
+
terminal-notifier (1.4.2)
|
51
|
+
tilt (1.3.3)
|
52
|
+
|
53
|
+
PLATFORMS
|
54
|
+
ruby
|
55
|
+
|
56
|
+
DEPENDENCIES
|
57
|
+
coffee-script
|
58
|
+
colorize
|
59
|
+
compass
|
60
|
+
haml
|
61
|
+
json_pure
|
62
|
+
listen
|
63
|
+
rake
|
64
|
+
rspec
|
65
|
+
rspec-nc
|
66
|
+
sprockets
|
67
|
+
tilt
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Tres
|
2
|
+
|
3
|
+
Tres is (will be) a mobile web development framework based in Backbone.js. The idea is instead of using
|
4
|
+
a bunch of jQuery plugins and whatnot, you'll build your application as you'd build a regular Backbone
|
5
|
+
app: you write the markup, declare the JS classes for each view, and style everything using CSS. A good
|
6
|
+
good looking theme will be provided, as well as transitions.
|
7
|
+
|
8
|
+
# Roadmap
|
9
|
+
|
10
|
+
1. Standalone JS file and CSS includes.
|
11
|
+
2. Console interface, with generators for models, collections, and screens.
|
12
|
+
3. Ruby library, Rails and Sinatra interfaces.
|
13
|
+
|
14
|
+
# Classes
|
15
|
+
|
16
|
+
* `Tres.Device`
|
17
|
+
- Will track events such as orientation change, and keep info such as width/height, supported
|
18
|
+
features, etc.
|
19
|
+
* `Tres.Screen`
|
20
|
+
- A screen, with some features such as a fixed header/footer and momentum scrolling.
|
21
|
+
* `Tres.SwipeSet`
|
22
|
+
- This class wraps a set of `Tres.Screen`s and allows for swipe navigation across them.
|
23
|
+
* `Tres.List`
|
24
|
+
- A simple list, bindable to a `Backbone.Collection`.
|
25
|
+
* `Tres.ListEntry`
|
26
|
+
- Contained by `Tres.List`. You can make it clickable by adding a `click` method to it. Renders
|
27
|
+
differently depending on that.
|
28
|
+
* `Tres.Form`
|
29
|
+
- A <form> wrapper class to capture data from it, and handle submitting and validations. Most
|
30
|
+
likely tied to a `Backbone.Model`. Note: not likely this will generate the form from a model's
|
31
|
+
attributes, since that means we need to define a schema for the model, and in which case we're
|
32
|
+
replicating what Backbone.Forms does. Just go and use it instead.
|
33
|
+
* `Tres.Notifier`
|
34
|
+
- Displays animated notifications, clickable or not.
|
35
|
+
|
36
|
+
Tentative stuff, but could be handled later by plugins.
|
37
|
+
|
38
|
+
* `Tres.Map`
|
39
|
+
- A Google map screen, with some helpers to ease the capture/insertion of data from it.
|
40
|
+
|
41
|
+
# Development Track
|
42
|
+
|
43
|
+
Things will be messy until I make final decisions on things. If you'd like to contribute or hack with this
|
44
|
+
project, give me a shout and I'll help you set up the environment. Until then, this repo won't have any
|
45
|
+
purpose beyond educational.
|
46
|
+
|
47
|
+
# Styles
|
48
|
+
|
49
|
+
As much as the philosophy is "stay out the way" and will remain so, a basic theme will be provided which
|
50
|
+
uses exclusively fonts for icons and CSS3. That's in conformity with the trend of high resolution displays.
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec', 'spec_helper')
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new do |task|
|
6
|
+
task.pattern = 'spec/**/*_spec.rb'
|
7
|
+
task.rspec_opts = ['-c', '--format=doc', '--format=Nc', '-r ./spec/spec_helper']
|
8
|
+
end
|
9
|
+
|
10
|
+
task :package do
|
11
|
+
version = File.read('VERSION')
|
12
|
+
`mkdir tres-#{version}`
|
13
|
+
`cp -r js css tres-#{version}`
|
14
|
+
`zip tres-#{version}.zip tres-#{version}`
|
15
|
+
`rm -rf tres-#{version}`
|
16
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/tres
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# coding: utf-8
|
3
|
+
|
4
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
5
|
+
|
6
|
+
require 'tres'
|
7
|
+
require 'colorize'
|
8
|
+
|
9
|
+
ACTIONS = {
|
10
|
+
:server => %w(server s),
|
11
|
+
:new_at => %w(new),
|
12
|
+
:screen => %w(screen sc),
|
13
|
+
:model => %w(model mo),
|
14
|
+
:collection => %w(collection co),
|
15
|
+
:template => %w(template t)
|
16
|
+
}
|
17
|
+
|
18
|
+
def bail! reason
|
19
|
+
puts reason
|
20
|
+
exit -2
|
21
|
+
end
|
22
|
+
|
23
|
+
def figure_what_to_do!
|
24
|
+
help_and_exit! if ARGV.empty?
|
25
|
+
if ACTIONS.values.flatten.include? ARGV.first
|
26
|
+
action = ACTIONS.select { |action, args| args.include? ARGV.first }.flatten.first
|
27
|
+
send action, *ARGV[1..(ARGV.length - 1)]
|
28
|
+
else
|
29
|
+
help_and_exit!
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def help_and_exit!
|
34
|
+
STDERR.puts <<-HELP
|
35
|
+
|
36
|
+
Tres
|
37
|
+
Usage:
|
38
|
+
tres new <directory>
|
39
|
+
Example:
|
40
|
+
tres new myapp
|
41
|
+
Other commands:
|
42
|
+
help shows this menu
|
43
|
+
version shows the current version of Tres you have installed
|
44
|
+
|
45
|
+
HELP
|
46
|
+
exit -1
|
47
|
+
end
|
48
|
+
|
49
|
+
def new_at dir
|
50
|
+
app = nil
|
51
|
+
Tres.say_progress "Creating Tres app on #{dir.dup.colorize(:yellow)}" do
|
52
|
+
app = Tres::App.new dir
|
53
|
+
end
|
54
|
+
Tres.say_progress "Compiling boilerplate templates" do
|
55
|
+
app.template_compiler.compile_all
|
56
|
+
end
|
57
|
+
Tres.say "All done!"
|
58
|
+
end
|
59
|
+
|
60
|
+
def server
|
61
|
+
Tres.say "Starting server"
|
62
|
+
app = Tres::App.open Dir.pwd
|
63
|
+
Rack::Server.start :app => Tres::Server.new(app).to_rack_app, :Port => 4567
|
64
|
+
end
|
65
|
+
|
66
|
+
def template name
|
67
|
+
app = Tres::App.open Dir.pwd, :deaf => true
|
68
|
+
Tres.say_progress "Creating template #{name.downcase.colorize(:yellow)}" do
|
69
|
+
app.template_compiler.new_template name.downcase
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def screen name
|
74
|
+
app = Tres::App.open Dir.pwd, :deaf => true
|
75
|
+
Tres.say_progress "Creating template #{name.downcase.colorize(:yellow)}" do
|
76
|
+
app.template_compiler.new_template name.downcase
|
77
|
+
end
|
78
|
+
Tres.say_progress "Creating #{name.to_screen_name.colorize(:yellow)} at #{("screens/" + name.downcase).colorize(:yellow)}" do
|
79
|
+
script = Tilt.new(Tres.templates_dir/'screen_script.coffee.erb')
|
80
|
+
script = script.render OpenStruct.new(:name => name)
|
81
|
+
app.asset_packager.new_script "screens/#{name.downcase}", script
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def model name
|
86
|
+
app = Tres::App.open Dir.pwd, :deaf => true
|
87
|
+
Tres.say_progress "Creating #{name.classify.colorize(:yellow)} at #{("models/" + name.downcase).colorize(:yellow)}" do
|
88
|
+
script = Tilt.new(Tres.templates_dir/'model_script.coffee.erb')
|
89
|
+
script = script.render OpenStruct.new(:name => name)
|
90
|
+
app.asset_packager.new_script "models/#{name.downcase}", script
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def collection name, model_name = nil
|
95
|
+
app = Tres::App.open Dir.pwd, :deaf => true
|
96
|
+
Tres.say_progress "Creating #{name.classify.colorize(:yellow)} at #{("collections/" + name).colorize(:yellow)}" do
|
97
|
+
script = Tilt.new(Tres.templates_dir/'collection_script.coffee.erb')
|
98
|
+
script = script.render OpenStruct.new(:name => name, :model_name => model_name)
|
99
|
+
app.asset_packager.new_script "collections/#{name.downcase}", script
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
figure_what_to_do!
|
@@ -0,0 +1,61 @@
|
|
1
|
+
URLs =
|
2
|
+
page : (name) -> "http://en.wikipedia.org/w/api.php?action=parse&page=#{name}&format=json&prop=text|displaytitle|sections|revid&mobileformat=html"
|
3
|
+
search : (query) -> "http://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=#{query}&format=json&srlimit=10&srprop="
|
4
|
+
|
5
|
+
class Article extends Backbone.Model
|
6
|
+
retrieve : (page, callback) ->
|
7
|
+
$.ajax
|
8
|
+
url : URLs.page(page)
|
9
|
+
dataType : 'jsonp'
|
10
|
+
data : { page : page }
|
11
|
+
success : (response) =>
|
12
|
+
@set(response.parse) unless response.error?
|
13
|
+
callback() if _.isFunction(callback)
|
14
|
+
|
15
|
+
class Suggestion extends Backbone.Model
|
16
|
+
class Suggestions extends Backbone.Collection
|
17
|
+
model : Suggestion
|
18
|
+
url : URLs.search
|
19
|
+
parse : (response) ->
|
20
|
+
response.query.search
|
21
|
+
search : (query) ->
|
22
|
+
@fetch(dataType : 'jsonp', url : URLs.search(query))
|
23
|
+
|
24
|
+
class Home extends Tres.Screen
|
25
|
+
id : 'home'
|
26
|
+
template : JST['home']
|
27
|
+
submit : (event) ->
|
28
|
+
event.preventDefault()
|
29
|
+
form = new Tres.Form(@$el.find('form'))
|
30
|
+
Tres.Router.navigate "search/#{encodeURI(form.attributes().query)}", true
|
31
|
+
|
32
|
+
class Search extends Tres.Screen
|
33
|
+
id : 'search'
|
34
|
+
template : JST['search']
|
35
|
+
active : (query) ->
|
36
|
+
@title(query)
|
37
|
+
@list ?= new Tres.List(
|
38
|
+
collection : App.Suggestions
|
39
|
+
el : @$el.find('ul')
|
40
|
+
entry : { template : JST['result'], url : -> "article/#{@model.attributes.title}" }
|
41
|
+
)
|
42
|
+
App.Suggestions.search query
|
43
|
+
|
44
|
+
class Reader extends Tres.Screen
|
45
|
+
id : 'show-article'
|
46
|
+
template : JST['article']
|
47
|
+
active : (name) ->
|
48
|
+
@title(name)
|
49
|
+
@model.retrieve name, => @render()
|
50
|
+
|
51
|
+
$ ->
|
52
|
+
window.App = new Tres.App
|
53
|
+
App.Suggestions = new Suggestions
|
54
|
+
App.Reader = new Reader(model : new Article)
|
55
|
+
|
56
|
+
App.on
|
57
|
+
'' : new Home
|
58
|
+
'search/:query' : new Search
|
59
|
+
'article/:title' : App.Reader
|
60
|
+
|
61
|
+
App.boot(root : '/anagen/')
|