golf 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/golf/compiler.rb CHANGED
@@ -1,23 +1,62 @@
1
1
  module Golf
2
2
  class Compiler
3
3
 
4
- def initialize(golfpath = "components")
4
+ def initialize(golfpath = ".")
5
+ puts "starting up in #{golfpath}"
5
6
  @golfpath = golfpath
6
7
  end
7
8
 
8
9
  def generate_componentsjs
9
- puts "compiling components in #{@golfpath}..."
10
- component_preamble = 'jQuery.golf.components='
11
- components = {}
12
- if File.exists?(@golfpath) and File.directory?(@golfpath)
13
- Dir["#{@golfpath}/**/*.html"].each do |path|
14
- name = path.split('/').last.gsub('.html','')
15
- html = File.read(path)
16
- components = components.merge({ name => { "name" => name, "html" => html }})
17
- end
10
+ "jQuery.golf.components=#{component_json};jQuery.golf.res=#{res_json};jQuery.golf.plugins=#{plugin_json};jQuery.golf.scripts=#{script_json};jQuery.golf.styles=#{style_json};jQuery.golf.setupComponents();"
11
+ end
12
+
13
+ def component_json
14
+ traverse("#{@golfpath}/components", "html")
15
+ end
16
+
17
+ def res_json
18
+ results = { "Gemfile" => "Gemfile", "plugins" => {},"config.ru" => "config.ru", "404.txt" => "404.txt" }
19
+ Dir["#{@golfpath}/plugins/*.js"].each do |path|
20
+ results["plugins"] = results["plugins"].merge({ File.basename(path) => "plugins/#{File.basename(path)}"})
18
21
  end
19
- component_preamble << JSON.dump(components) << ';' << 'jQuery.golf.res={};jQuery.golf.plugins={};jQuery.golf.scripts={};jQuery.golf.styles={};jQuery.golf.setupComponents();'
22
+ JSON.dump(results)
20
23
  end
21
24
 
25
+ def plugin_json
26
+ traverse("#{@golfpath}/plugins", "js")
27
+ end
28
+
29
+ def script_json
30
+ traverse("#{@golfpath}/scripts", "js")
31
+ end
32
+
33
+ def style_json
34
+ traverse("#{@golfpath}/styles", "css")
35
+ end
36
+
37
+ def traverse(dir, type)
38
+ results = {}
39
+ if File.exists?(dir) and File.directory?(dir)
40
+ Dir["#{dir}/**/*.#{type}"].each do |path|
41
+ if type == "html"
42
+ name = package_name(path)
43
+ else
44
+ name = path.split('/').last.gsub(".#{type}",'')
45
+ end
46
+ data = File.read(path)
47
+ results = results.merge({ name => { "name" => name, "#{type}" => data }})
48
+ end
49
+ end
50
+ JSON.dump(results)
51
+ end
52
+
53
+ def package_name(path)
54
+ path_arr = path.split('/')
55
+ i = path_arr.index('components')
56
+ name_segment = (path_arr.length - 1) - i
57
+ path_arr.slice(i + 1, name_segment - 1).join('.')
58
+ end
59
+
60
+
22
61
  end
23
62
  end
data/lib/golf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Golf
2
- VERSION = "0.1.8"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -3,16 +3,22 @@ require 'test_helper'
3
3
  class CompilerTest < Test::Unit::TestCase
4
4
 
5
5
  def setup
6
- @compiler = Golf::Compiler.new(File.expand_path("../data/components", __FILE__))
6
+ @compiler = Golf::Compiler.new(File.expand_path("../twitter_compiled", __FILE__))
7
7
  end
8
8
 
9
9
 
10
10
  def test_componentsjs_generation
11
11
  componentjs = @compiler.generate_componentsjs
12
- known_good = 'jQuery.golf.components={"HelloWorld":{"name":"HelloWorld","html":"<div><styletype=\"text/golf\">div.container{border:1pxsolidred;}</style><scripttype=\"text/golf\">function(){$(\".container\").append(\"<h1>Hello,world!</h1>\");}</script><divclass=\"container\"></div></div>"}};jQuery.golf.res={};jQuery.golf.plugins={};jQuery.golf.scripts={};jQuery.golf.styles={};jQuery.golf.setupComponents();'
12
+ known_good = File.read(File.expand_path("../twitter_compiled/components.js", __FILE__))
13
+ assert_equal componentjs.gsub(' ','').gsub('\n','').gsub('\\',''), known_good.gsub(' ','').gsub('\n','').gsub('\\','')
14
+ end
15
+
16
+
17
+ def test_package_name_resolution
18
+ result = @compiler.package_name '/asd/asdasd/components/golf/twitter/Tweet/Tweet.html'
19
+ assert_equal 'golf.twitter.Tweet', result
13
20
 
14
- assert_equal componentjs.gsub(' ','').gsub('\n',''), known_good.gsub(' ','').gsub('\n','')
15
-
16
21
  end
17
22
 
23
+
18
24
  end
@@ -0,0 +1 @@
1
+ not found
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rack'
4
+ gem 'rack-contrib'
5
+ gem 'rack-rewrite'
6
+ gem 'golf'
@@ -0,0 +1,29 @@
1
+ <div>
2
+ <style type="text/golf">
3
+ </style>
4
+
5
+ <script type="text/golf">
6
+ function(query) {
7
+ var search = $.require("twitter").search;
8
+
9
+ search(query, function(i, tweet) {
10
+ $(".results").append(new Component.golf.twitter.Tweet(tweet));
11
+ $(".numresults").text(i+1);
12
+ });
13
+
14
+ $("form").submit(function() {
15
+ $.golf.location("/"+$("input[name='query']").val()+"/");
16
+ });
17
+ }
18
+ </script>
19
+
20
+ <div class="content">
21
+ <h1>Twitter Search</h1>
22
+ <form>
23
+ <input type="text" name="query"/>
24
+ <input type="submit"/>
25
+ </form>
26
+ <p><span class="numresults">0</span> results:</p>
27
+ <ul class="results"/>
28
+ </div>
29
+ </div>
@@ -0,0 +1,16 @@
1
+ <li>
2
+ <style type="text/golf">
3
+ span.user {
4
+ color: green;
5
+ }
6
+ </style>
7
+
8
+ <script type="text/golf">
9
+ function(tweet) {
10
+ $(".user").text(tweet.from_user);
11
+ $(".text").text(tweet.text);
12
+ }
13
+ </script>
14
+
15
+ <span class="user">A user</span> says: <span class="text">Some things.</span>
16
+ </li>
@@ -0,0 +1 @@
1
+ jQuery.golf.components={"golf.twitter.Tweet":{"name":"golf.twitter.Tweet","html":"<li>\n <style type=\"text/golf\">\n span.user {\n color: green;\n }\n <\/style>\n\n <script type=\"text/golf\">\n\n function(tweet) {\n $(\".user\").text(tweet.from_user);\n $(\".text\").text(tweet.text);\n }\n \n<\/script>\n\n <span class=\"user\">A user<\/span> says: <span class=\"text\">Some things.<\/span>\n<\/li>\n"},"golf.twitter.Search":{"name":"golf.twitter.Search","html":"<div>\n <style type=\"text/golf\">\n <\/style>\n\n <script type=\"text/golf\">\n\n function(query) {\n var search = $.require(\"twitter\").search;\n\n search(query, function(i, tweet) {\n $(\".results\").append(new Component.golf.twitter.Tweet(tweet));\n $(\".numresults\").text(i+1);\n });\n\n $(\"form\").submit(function() {\n $.golf.location(\"/\"+$(\"input[name='query']\").val()+\"/\");\n });\n }\n \n<\/script>\n\n <div class=\"content\">\n <h1>Twitter Search<\/h1>\n <form>\n <input type=\"text\" name=\"query\"/>\n <input type=\"submit\"/>\n <\/form>\n <p><span class=\"numresults\">0<\/span> results:<\/p>\n <ul class=\"results\"/>\n <\/div>\n<\/div>\n"}};jQuery.golf.res={"Gemfile":"Gemfile","plugins":{"twitter.js":"plugins/twitter.js"},"config.ru":"config.ru","404.txt":"404.txt"};jQuery.golf.plugins={"twitter":{"name":"twitter","js":"(function() {\n\n exports.search = function(query, callback) {\n $.getJSON(\n \"http://search.twitter.com/search.json?q=\"+escape(query)+\"&callback=?\",\n function(data) {\n $.each(data.results, function(i, tweet) {\n callback(i, tweet);\n });\n }\n );\n };\n\n})();\n"}};jQuery.golf.scripts={"00-myscript":{"name":"00-myscript","js":""}};jQuery.golf.styles={"main":{"name":"main","css":""}};jQuery.golf.setupComponents();
@@ -0,0 +1,7 @@
1
+ require 'bundler'
2
+ require 'golf'
3
+ require 'rack'
4
+ require 'rack/contrib'
5
+
6
+ use Golf::Rack
7
+ run Rack::NotFound.new('404.txt')
@@ -0,0 +1,9 @@
1
+ $.golf.defaultRoute = "/golf/";
2
+
3
+ $.golf.controller = [
4
+ { route: "/(.*)/",
5
+ action: function(container, params) {
6
+ container.append(new Component.golf.twitter.Search(unescape(params[1])));
7
+ }
8
+ }
9
+ ];
@@ -19,9 +19,6 @@
19
19
  servletUrl.substring(0, servletUrl.length - "index.html".length));
20
20
  </script>
21
21
  <script type="text/javascript" src="jquery.js"></script>
22
- <script type="text/javascript">
23
- jQuery.golf = {};
24
- </script>
25
22
  <script type="text/javascript" src="jquery.address.js"></script>
26
23
  <script type="text/javascript" src="jquery.golf.js"></script>
27
24
  <script type="text/javascript" src="components.js"></script>
@@ -41,7 +41,6 @@ function Component() {
41
41
  function Debug(prefix) {
42
42
  return function(text) {
43
43
  text = prefix+": "+text;
44
- window.devmode = true;
45
44
  if (window.devmode && window.console && window.console.log)
46
45
  console.log(text);
47
46
  else if (window.serverside)
@@ -0,0 +1,14 @@
1
+ (function() {
2
+
3
+ exports.search = function(query, callback) {
4
+ $.getJSON(
5
+ "http://search.twitter.com/search.json?q="+escape(query)+"&callback=?",
6
+ function(data) {
7
+ $.each(data.results, function(i, tweet) {
8
+ callback(i, tweet);
9
+ });
10
+ }
11
+ );
12
+ };
13
+
14
+ })();
File without changes
File without changes
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: golf
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.8
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Micha Niskin, Alan Dipert, Julio Capote
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-10 00:00:00 -07:00
13
+ date: 2011-04-11 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -89,18 +89,25 @@ files:
89
89
  - templates/twitter/plugins/twitter.js
90
90
  - templates/twitter/scripts/00-myscript.js
91
91
  - templates/twitter/styles/main.css
92
- - test/data/app_error.html
93
- - test/data/components.js
94
- - test/data/components/HelloWorld/HelloWorld.html
95
- - test/data/controller.js
96
- - test/data/index.html
97
- - test/data/jquery.address.js
98
- - test/data/jquery.golf.js
99
- - test/data/jquery.js
100
- - test/data/welcome2golf.html
101
92
  - test/test_compiler.rb
102
93
  - test/test_helper.rb
103
94
  - test/test_rack.rb
95
+ - test/twitter_compiled/404.txt
96
+ - test/twitter_compiled/Gemfile
97
+ - test/twitter_compiled/app_error.html
98
+ - test/twitter_compiled/components.js
99
+ - test/twitter_compiled/components/golf/twitter/Search/Search.html
100
+ - test/twitter_compiled/components/golf/twitter/Tweet/Tweet.html
101
+ - test/twitter_compiled/config.ru
102
+ - test/twitter_compiled/controller.js
103
+ - test/twitter_compiled/index.html
104
+ - test/twitter_compiled/jquery.address.js
105
+ - test/twitter_compiled/jquery.golf.js
106
+ - test/twitter_compiled/jquery.js
107
+ - test/twitter_compiled/plugins/twitter.js
108
+ - test/twitter_compiled/scripts/00-myscript.js
109
+ - test/twitter_compiled/styles/main.css
110
+ - test/twitter_compiled/welcome2golf.html
104
111
  has_rdoc: true
105
112
  homepage: http://golf.github.com
106
113
  licenses: []
@@ -1,13 +0,0 @@
1
- <div>
2
- <style type="text/golf">
3
- div.container {
4
- border: 1px solid red;
5
- }
6
- </style>
7
- <script type="text/golf">
8
- function() {
9
- $(".container").append("<h1>Hello, world!</h1>");
10
- }
11
- </script>
12
- <div class="container"></div>
13
- </div>
@@ -1 +0,0 @@
1
- jQuery.golf.components={"HelloWorld":{"name":"HelloWorld","html":"<div>\n <style type=\"text/golf\">\n div.container {\n border: 1px solid red;\n }\n <\/style>\n <script type=\"text/golf\">\n\n function() {\n $(\".container\").append(\"<h1>Hello, world!<\/h1>\");\n }\n \n<\/script>\n <div class=\"container\"><\/div>\n<\/div>\n"}};jQuery.golf.res={};jQuery.golf.plugins={};jQuery.golf.scripts={};jQuery.golf.styles={};jQuery.golf.setupComponents();
@@ -1,7 +0,0 @@
1
- $.golf.controller = [
2
- { route: ".*",
3
- action: function(container, params) {
4
- container.empty().append(new Component.HelloWorld());
5
- }
6
- }
7
- ];
File without changes
File without changes
File without changes
File without changes