Permalink
Browse files

it boots!

  • Loading branch information...
1 parent 646513a commit 9b7a75851ee87d078a5a2f3b4903b551aab115d0 @wycats committed Aug 26, 2010
View
@@ -1,4 +1,6 @@
source :gemcutter
# Specify your gem's dependencies in abbot-ng.gemspec
-gemspec
+gemspec
+
+gem "thin", :path => "~/Code/cool_stuff/thin"
View
0 bin/sc-server 100644 → 100755
No changes.
View
@@ -1,5 +1,5 @@
require "sproutcore/entries"
require "sproutcore/manifest"
-require "sproutcore/html"
+require "sproutcore/html_context"
require "sproutcore/server"
require "sproutcore/version"
View
@@ -34,8 +34,9 @@ def initialize(dir, target, target_type)
@entry_lookup = {}
Dir["#{@target_dir}/**/*.#{self.class.ext}"].each do |file|
+ next if file =~ %r{^#{@target_dir}/(debug|tests)}
source = File.read(file)
- requires = source.scan(%r{sc_require\(\s*['"](.*)['"]\)}).flatten
+ requires = source.scan(%r{\b(?:sc_)?require\(\s*['"](.*)['"]\)}).flatten
add Entry.new(file[%r{#{@target_dir}/(.*)\.#{self.class.ext}}, 1], requires, source)
end
@@ -62,9 +63,11 @@ def add(entry)
end
def compile
- output = inject("") do |output, file|
- output << "/* >>>>>>>>>> BEGIN #{file.name}.#{self.class.ext} */\n"
- output << "#{file.source}\n"
+ @compiled ||= begin
+ output = inject("") do |output, file|
+ output << "/* >>>>>>>>>> BEGIN #{file.name}.#{self.class.ext} */\n"
+ output << "#{file.source}\n"
+ end
end
end
@@ -73,6 +76,10 @@ def sort!
# define sorting heuristics in a subclass
end
+ def destination(file)
+ "#{destination_root}/#{file}"
+ end
+
private
def destination_root
"/static/#{LOCALE_MAP[self.class.locale]}/#{@target}"
@@ -94,12 +101,20 @@ def tsort_each_child(node)
class JavaScriptEntries < Entries
self.ext = "js"
+ self.locale = "english" # hardcode for now
+
def compile
- super << %[\nSC.bundleDidLoad("#{@package}/#{@target}");\n]
+ @compiled ||= begin
+ each do |entry|
+ entry.source.gsub!(/sc_super\(\s*\)/, "arguments.callee.base.apply(this, arguments)")
+ end
+
+ super << %[\nSC.bundleDidLoad("#{@package}/#{@target}");\n]
+ end
end
def sort!
- step1 = sort_by! do |entry|
+ sort_by! do |entry|
sort_by = case entry.name
# TODO: Allow preferred filename customization
when %r{^(\w+\.)lproj/strings$} then -3
@@ -112,6 +127,7 @@ def sort!
[sort_by, entry.name]
end
+
replace(tsort)
end
@@ -164,22 +180,24 @@ def sort!
end
def compile
- each do |entry|
- entry.source.gsub!(/(sc_static|static_url|sc_target)\(\s*['"](.+)['"]\s*\)/) do |resource|
- url = static_or_fallback($2)
-
- if url && url.destination
- "url('#{url.destination}')"
- else
- puts "WARN: static not found: #{$2} (from #{entry.name}"
+ @compiled ||= begin
+ each do |entry|
+ entry.source.gsub!(/(sc_static|static_url|sc_target)\(\s*['"](.+)['"]\s*\)/) do |resource|
+ url = static_or_fallback($2)
+
+ if url && url.destination
+ "url('#{url.destination}')"
+ else
+ puts "WARN: static not found: #{$2} (from #{entry.name}"
+ end
end
end
- end
- super
+ super
+ end
end
- def destination(default = "stylesheet.js")
+ def destination(default = "stylesheet.css")
super
end
end
View
@@ -2,9 +2,6 @@ module SproutCore
class HtmlContext
def initialize(config, manifest)
@config, @manifest = config, manifest
-
- @bootstrap = bootstrap
- @content_for_body = content_for_body
end
def sc_static(static)
@@ -36,7 +33,7 @@ def javascripts
scripts << %{<script type="text/javascript" src="#{location}"></script>}
end
scripts << %{<script type="text/javascript>String.preferredLanguage = "en";</script>}
+ scripts.join("\n")
end
- scripts.join("\n")
end
end
@@ -0,0 +1,41 @@
+module SproutCore
+ class HtmlContext
+ def initialize(config, manifest)
+ @config, @manifest = config, manifest
+ end
+
+ def sc_static(static)
+ if found_static = @manifest.find_static(static)
+ found_static.destination
+ else
+ puts "WARN: #{static} could not be found in any of the loaded frameworks, themes, or your app"
+ puts "from #{caller[0]}"
+ ""
+ end
+ end
+
+ def bootstrap
+ location = @manifest.find_js("bootstrap").destination
+ %{<script type='text/javascript' src="#{location}"></script>}
+ end
+
+ def stylesheets
+ sheets = []
+ @manifest.stylesheets.each do |name, list|
+ location = list.destination
+ sheets << %{<link href="#{location}" rel="stylesheet" type="text/css" />}
+ end
+ sheets.join("\n ")
+ end
+
+ def javascripts
+ scripts = []
+ @manifest.javascripts.each do |name, list|
+ location = list.destination
+ scripts << %{<script type="text/javascript" src="#{location}"></script>}
+ end
+ scripts << %{<script type="text/javascript">String.preferredLanguage = "en";</script>}
+ scripts.join("\n ")
+ end
+ end
+end
View
@@ -1,5 +1,7 @@
module SproutCore
class Manifest
+ attr_reader :javascripts, :stylesheets
+
def initialize
@javascripts = {}
@stylesheets = {}
@@ -22,24 +24,12 @@ def find_static(static)
nil
end
- def javascripts
- @javascripts.each do |k,v|
- puts
- puts k
- puts "<<<<========================>>>>"
- puts v.compile
- puts
- end
+ def find_js(js_target)
+ @javascripts.find { |target, list| target == js_target }.last
end
- def stylesheets
- @stylesheets.each do |k,v|
- puts
- puts k
- puts "<<<<========================>>>>"
- puts v.compile
- puts
- end
+ def find_css(css_target)
+ @stylesheets.find { |target, list| target == css_target }.last
end
end
end
View
@@ -1,21 +1,89 @@
+require "rack"
+require "erubis"
+
module SproutCore
+ class App
+ def initialize(context, manifest)
+ @context, @manifest = context, manifest
+ end
+
+ EXPIRES = (Time.now + (60 * 60 * 24 * 30)).rfc2822
+
+ def response(content_type, body, expires = EXPIRES)
+ body = body.is_a?(String) ? [body] : body
+ [200, {"Content-Type" => content_type, "Expires" => expires}, body]
+ end
+
+ def call(env)
+ url = env["PATH_INFO"]
+
+ if url == "/"
+ [200, {"Content-Type" => "text/html"}, [@context.render]]
+ else
+ url =~ %r{^/static/en/([^/]+)/(.*)$}
+
+ target = $1
+ type = $2
+
+ # TODO: HARDCODED
+ if target == "todos"
+ root = "/Users/wycats/Code/sprout/todos/apps/todos"
+ body = File.read("#{root}/#{type}")
+
+ if type =~ /\.js/
+ content_type = "application/javascript"
+ elsif type =~ /\.css/
+ content_type = "text/css"
+ end
+
+ return response(content_type, body)
+ end
+
+ case type
+ when "javascript.js"
+ body = @manifest.find_js(target).compile
+ response("application/javascript", body)
+ when "stylesheet.css"
+ body = @manifest.find_css(target).compile
+ response("text/css", body)
+ else
+ if file = @manifest.find_static(type)
+ response("application/octet-stream", File.open(file.source, "rb"))
+ else
+ [404, {"Content-Type" => "text/html"}, []]
+ end
+ end
+ end
+ end
+ end
+
class Server < ::Rack::Server
def initialize
- @sproutcore = File.expand_path("~/Code/sprout/sproutcore")
+ sproutcore = File.expand_path("~/Code/sprout/sproutcore")
@manifest = SproutCore::Manifest.new
+ # TODO: HARDCODED
%w(bootstrap runtime foundation datastore statechart desktop media).each do |target|
- manifest.add_target(@sproutcore, target, :frameworks)
+ @manifest.add_target(sproutcore, target, :frameworks)
end
- manifest.add_target(@sproutcore, "standard_theme", :themes)
+ # TODO: HARDCODED
+ @manifest.add_target(sproutcore, "standard_theme", :themes)
+
+ template_location = File.expand_path("../templates/index.erb", __FILE__)
+ template = Erubis::Eruby.new(File.read(template_location))
- @template = Erubis::Eruby.new(File.read(File.expand_path("../templates/index.erb", __FILE__)))
+ HtmlContext.class_eval <<-RUBY, template_location, 0
+ def render
+ #{template.src}
+ end
+ RUBY
+
+ @context = HtmlContext.new({}, @manifest)
end
def app
- path = ENV["PATH_INFO"]
-
+ App.new(@context, @manifest)
end
end
end
@@ -1,5 +1,5 @@
<!DOCTYPE html>
-<html<% unless @config[:manifest].blank? %> manifest="app.manifest"<% end %>>
+<html<% if @config[:manifest] %> manifest="app.manifest"<% end %>>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
@@ -8,21 +8,24 @@
<meta name="apple-mobile-web-app-status-bar-style" content="<%= @config[:manifest] || 'default' %>" />
<meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="apple-touch-icon<%= '-precomposed' if @config[:precomposed_icon] %>" href="<%= sc_static(@config[:icon] || 'sproutcore-logo.png') %>" />
- <link rel="apple-touch-startup-image" media="screen and (orientation:portrait)" href="<%= sc_static(@config[:startup_image_portrait] || 'sproutcore-startup-portrait.png') %>" />
- <link rel="apple-touch-startup-image" media="screen and (orientation:landscape)" href="<%= sc_static(@config[:startup_image_landscape] || 'sproutcore-startup-landscape.png') %>" />
- <link rel="shortcut icon" href="<%= sc_static(@config[:favicon] || 'favicon.ico') %>" type="image/x-icon" />
+ <link rel="apple-touch-startup-image" media="screen and (orientation:portrait)" href="<%= sc_static(@config[:startup_image_portrait] || 'sproutcore-startup-portrait.png') %>" />
+ <link rel="apple-touch-startup-image" media="screen and (orientation:landscape)" href="<%= sc_static(@config[:startup_image_landscape] || 'sproutcore-startup-landscape.png') %>" />
+ <link rel="shortcut icon" href="<%= sc_static(@config[:favicon] || 'favicon.ico') %>" type="image/x-icon" />
<title><%= @config[:title] %></title>
<%= stylesheets %>
</head>
- <body class="<%= [config[:theme_name] || "sc-theme", "focus"].compact.join(' ') %>">
+ <body class="<%= [@config[:theme_name] || "sc-theme", "focus"].compact.join(' ') %>">
<%= bootstrap %>
<div id="loading">
<p class="loading">Loading...</p>
</div>
<%= javascripts %>
- </body>
+ <% %w(core controllers/tasks models/task fixtures/task resources/main_page main).each do |resource| %>
+ <script src="/static/en/todos/<%= resource %>.js"></script>
+ <% end %>
+ </body>
</html>
View
@@ -19,6 +19,6 @@ Gem::Specification.new do |s|
s.add_runtime_dependency "rack", "~> 1.2"
s.files = `git ls-files`.split("\n")
- s.executables = `git ls-files`.split("\n").select{|f| f =~ /^bin/}
+ s.executables = `git ls-files`.split("\n").map{|f| f[/^bin\/(.*)/, 1] }.compact
s.require_path = 'lib'
end

0 comments on commit 9b7a758

Please sign in to comment.