bwoken 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -73,6 +73,13 @@ Complete
73
73
  Duration: 23.419741s
74
74
  </code></pre>
75
75
 
76
+ ### Bring in Libraries!
77
+
78
+ Wanna bring in [tuneup.js](https://github.com/alexvollmer/tuneup_js) or [mechanic](https://github.com/jaykz52/mechanic)? Just use `#github` instead of `#import`:
79
+
80
+ <pre><code>#github "alexvollmer/tuneup_js/tuneup.js"
81
+ #github "jaykz52/mechanic/src/mechanic-core.js"
82
+ </code></pre>
76
83
 
77
84
  ### Like Javascript?
78
85
 
@@ -3,6 +3,9 @@ require 'coffee_script/source'
3
3
  require 'json'
4
4
  require 'execjs'
5
5
 
6
+ require File.expand_path('../coffeescript/import_string', __FILE__)
7
+ require File.expand_path('../coffeescript/github_import_string', __FILE__)
8
+
6
9
  module Bwoken
7
10
  class Coffeescript
8
11
  class << self
@@ -22,17 +25,38 @@ module Bwoken
22
25
  end
23
26
 
24
27
  def precompile coffeescript
25
- coffeescript.lines.partition {|line| line =~ /^#import .*$/}.map(&:join)
28
+ coffeescript.lines.partition {|line| line =~ /^#(?:github|import) .*$/}
26
29
  end
27
30
 
28
31
  def compile source, target
29
- import_strings, sans_imports = precompile(IO.read source)
32
+ githubs_and_imports, sans_imports = precompile(IO.read source)
30
33
 
31
- javascript = self.context.call 'CoffeeScript.compile', sans_imports, :bare => true
34
+ javascript = coffeescript_to_javascript sans_imports.join
35
+ import_strings = githubs_to_imports(githubs_and_imports)
32
36
 
33
37
  write import_strings, javascript, :to => target
34
38
  end
35
39
 
40
+ def coffeescript_to_javascript coffee
41
+ self.context.call 'CoffeeScript.compile', coffee, :bare => true
42
+ end
43
+
44
+ def githubs_to_imports strings
45
+ strings.map do |string|
46
+ obj = import_string_object(string)
47
+ obj.parse
48
+ obj.to_s
49
+ end.join("\n")
50
+ end
51
+
52
+ def import_string_object string
53
+ if string =~ /^#github/
54
+ GithubImportString.new(string)
55
+ else
56
+ ImportString.new(string)
57
+ end
58
+ end
59
+
36
60
  def write *args
37
61
  to_hash = args.last
38
62
  chunks = args[0..-2]
@@ -0,0 +1,75 @@
1
+ require 'fileutils'
2
+ require File.expand_path('../import_string', __FILE__)
3
+
4
+ module Bwoken
5
+ class Coffeescript
6
+ class GithubImportString < ImportString
7
+ attr_reader :repo_name, :file_path
8
+
9
+ def initialize string
10
+ @string = string
11
+ parse_parts
12
+ end
13
+
14
+ def parse
15
+ ensure_github
16
+ end
17
+
18
+ def to_s
19
+ %Q|#import "#{repo_path}/#{file_path}"|
20
+ end
21
+
22
+ private
23
+
24
+ # this is kinda gross. Key thing to recognize is that we're whitelisting
25
+ # the account name, project name, and filename. We'll eventually be escaping
26
+ # out to Kernel#`, so we shouldn't be allowing all characters (eg, ';' would be BAD)
27
+ def parse_parts
28
+ importing = @string.match(%r{\A\s*#github\s+['"]?\b([^'"]*)['"]?}i)[1]
29
+ @repo_name, @file_path = importing.match(%r{([-a-z_0-9]+/[-a-z_0-9]+)/([-a-z_0-9/\.]*)})[1..2]
30
+ end
31
+
32
+ def ensure_github
33
+ if !repo_exists? || ENV['FORCE_GITHUB'] == 'true'
34
+ clean_repo
35
+ download_repo
36
+ end
37
+ end
38
+
39
+ def clean_repo
40
+ delete_repo if repo_exists?
41
+ end
42
+
43
+ def delete_repo
44
+ FileUtils.rm_rf(repo_path)
45
+ end
46
+
47
+ def repo_path
48
+ File.join(Bwoken.path, 'github', repo_name)
49
+ end
50
+
51
+ def repo_exists?
52
+ File.exist? repo_path
53
+ end
54
+
55
+ def download_repo
56
+ prepare_repo_path
57
+ clone_repo
58
+ delete_dot_git
59
+ end
60
+
61
+ def prepare_repo_path
62
+ FileUtils.mkdir_p File.dirname(repo_path)
63
+ end
64
+
65
+ def clone_repo
66
+ `git clone --single-branch --branch master git://github.com/#{repo_name} #{repo_path}`
67
+ end
68
+
69
+ def delete_dot_git
70
+ FileUtils.rm_rf File.join(repo_path, '.git')
71
+ end
72
+
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,17 @@
1
+ module Bwoken
2
+ class Coffeescript
3
+ class ImportString
4
+
5
+ def initialize string
6
+ @string = string
7
+ end
8
+
9
+ def parse
10
+ end
11
+
12
+ def to_s
13
+ @string
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Bwoken
2
- VERSION = "1.2.1" unless defined?(::Bwoken::VERSION)
2
+ VERSION = "1.3.0" unless defined?(::Bwoken::VERSION)
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bwoken
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-03-01 00:00:00.000000000 Z
13
+ date: 2013-03-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: coffee-script-source
@@ -121,6 +121,8 @@ files:
121
121
  - README.md
122
122
  - bin/unix_instruments.sh
123
123
  - lib/bwoken/build.rb
124
+ - lib/bwoken/coffeescript/github_import_string.rb
125
+ - lib/bwoken/coffeescript/import_string.rb
124
126
  - lib/bwoken/coffeescript.rb
125
127
  - lib/bwoken/configs/bwoken.xcconfig
126
128
  - lib/bwoken/device.rb
@@ -146,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
148
  version: '0'
147
149
  segments:
148
150
  - 0
149
- hash: 4120650318918644756
151
+ hash: -192482595553482221
150
152
  required_rubygems_version: !ruby/object:Gem::Requirement
151
153
  none: false
152
154
  requirements:
@@ -155,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
157
  version: '0'
156
158
  segments:
157
159
  - 0
158
- hash: 4120650318918644756
160
+ hash: -192482595553482221
159
161
  requirements: []
160
162
  rubyforge_project:
161
163
  rubygems_version: 1.8.25