peaberry 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ vendor/bundle/
6
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # -*- encoding: UTF-8 -*-
2
+
3
+ source :rubygems
4
+
5
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) OZAWA Sakuro
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.
@@ -0,0 +1,38 @@
1
+ = Peaberry
2
+
3
+ == What is This
4
+
5
+ Peaberry is a clone of the dotjs server(djsd).
6
+ One advantage of Peaberry is that it can serve CoffeeScript(s).
7
+
8
+ == How to Install
9
+
10
+ === Browser Extension
11
+
12
+ Install a dotjs extension for your browser.
13
+ dotjs comes with a extension for Chrome.
14
+ See README in dotjs for case of other browsers.
15
+
16
+ === Dotjs Daemon
17
+
18
+ Stop djsd if one is running.
19
+
20
+ $ launchctl unload ~/Library/LaunchAgents/com.github.dotjs.plist
21
+
22
+ You should also remove or rename this to avoid its startup on your logging in.
23
+
24
+ Then run
25
+
26
+ $ peaberry install
27
+
28
+ to deploy com.github.peaberry.plist.
29
+
30
+ All should work as same as djsd did.
31
+
32
+ == Tips
33
+
34
+ Thanks to sprockets, you can split scripts into parts.
35
+
36
+ For example, following ~/.js/default.coffee will include all scripts
37
+ in ~/.js/default directory and will be served as default.js.
38
+ # require_tree ./default
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/ruby
2
+ # -*- encoding: UTF-8 -*-
3
+
4
+ require 'rubygems'
5
+ begin
6
+ require 'bundler/setup'
7
+ rescue LoadError => e
8
+ # ignore
9
+ end
10
+
11
+ require 'peaberry'
12
+
13
+ case ARGV.shift
14
+ when 'install'
15
+ Peaberry::PlistInstaller.new.install
16
+ else
17
+ Rack::Server.start(:app => Peaberry::DotJs.new, :Port => 3131)
18
+ end
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="US-ASCII"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>KeepAlive</key>
6
+ <true/>
7
+ <key>Label</key>
8
+ <string>com.github.peaberry</string>
9
+ <key>ProgramArguments</key>
10
+ <array>
11
+ <string><%= ruby_bin_path %></string>
12
+ <string><%= peaberry_script_path %></string>
13
+ </array>
14
+ <key>RunAtLoad</key>
15
+ <true/>
16
+ </dict>
17
+ </plist>
@@ -0,0 +1,6 @@
1
+ # -*- encoding: UTF-8 -*-
2
+
3
+ require 'peaberry/version'
4
+ require 'peaberry/mime'
5
+ require 'peaberry/dot_js'
6
+ require 'peaberry/plist_installer'
@@ -0,0 +1,42 @@
1
+ # -*- encoding: UTF-8 -*-
2
+
3
+ require 'rack'
4
+ require 'coffee-script'
5
+ require 'sprockets'
6
+
7
+ module Peaberry
8
+ class DotJs
9
+
10
+ def initialize
11
+ @sprockets = Sprockets::Environment.new
12
+ dot_js_dir = File.expand_path('~/.js')
13
+ @sprockets.append_path(dot_js_dir)
14
+ end
15
+
16
+ def call(env)
17
+ headers = Rack::Utils::HeaderHash.new
18
+ request = Rack::Request.new(env)
19
+
20
+ path = request.path_info
21
+ files = []
22
+ files << @sprockets.find_asset('default.js')
23
+ files << @sprockets.find_asset(path.sub(/^\//, ''))
24
+
25
+ body = "// dotjs is working! //\n" + files.compact.map(&:to_s).join
26
+
27
+ headers['Content-Length'] = body.bytesize.to_s
28
+ headers['Content-Type'] = 'text/javascript'
29
+ origin = env['HTTP_ORIGIN'].to_s.split(/;\s+/)
30
+ search = path.gsub('/','').gsub(/\.js$/,'') + '$'
31
+ if origin && origin.length == 1 && path.length != 1 && origin[0].match(search)
32
+ headers['Access-Control-Allow-Origin'] = origin[0]
33
+ end
34
+
35
+ [ Rack::Utils.status_code(:ok), headers, body.lines ]
36
+ rescue ExecJS::ProgramError => e # CoffeeScript->JavaScript
37
+ @sprockets.send(:expire_index!)
38
+ raise e.class, e.message.sub(%r<^(\s+\(in) .*/(\.js/)>) { "#$1 #$2" }
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,4 @@
1
+ require 'rack/mime'
2
+
3
+ # Let's remove TLD-ish extension(s)
4
+ Rack::Mime::MIME_TYPES.delete('.com')
@@ -0,0 +1,26 @@
1
+ # -*- encoding: UTF-8 -*-
2
+
3
+ require 'erb'
4
+ require 'fileutils'
5
+
6
+ module Peaberry
7
+ class PlistInstaller
8
+ PLIST_ERB_PATH = File.join(File.dirname(__FILE__), '../../com.github.peaberry.plist.erb')
9
+ PLIST_PATH = File.expand_path('~/Library/LaunchAgents/com.github.peaberry.plist')
10
+ def install
11
+ dir = File.dirname(PLIST_PATH)
12
+ FileUtils.mkdir_p(dir) unless FileTest.directory?(dir)
13
+ open(PLIST_PATH, 'w') do |plist|
14
+ ruby_bin_path =
15
+ if RbConfig.respond_to?(:ruby)
16
+ RbConfig.ruby
17
+ else
18
+ File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
19
+ end
20
+ peaberry_script_path = File.expand_path(File.join(File.dirname(__FILE__), '../../bin/peaberry'))
21
+ plist.print ERB.new(File.read(PLIST_ERB_PATH)).result(binding)
22
+ end
23
+ system 'launchctl', 'load', PLIST_PATH
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ # -*- encoding: UTF-8 -*-
2
+
3
+ module Peaberry
4
+ VERSION = '0.0.1'
5
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $:.push File.expand_path('../lib', __FILE__)
4
+ require 'peaberry/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'peaberry'
8
+ s.version = Peaberry::VERSION
9
+ s.authors = ['OZAWA Sakuro']
10
+ s.email = ['sakuro@2238club.org']
11
+ s.homepage = ''
12
+ s.summary = %q{A dotjs server clone}
13
+ s.description = %q{Peaberry is a clone of dotjs server(djsd) which can serve CoffeeScript(s).}
14
+
15
+ s.rubyforge_project = 'peaberry'
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ['lib']
21
+ s.add_dependency 'coffee-script'
22
+ s.add_dependency 'sprockets', '~> 2.0.0'
23
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: peaberry
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - OZAWA Sakuro
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: coffee-script
16
+ requirement: &70128767616920 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70128767616920
25
+ - !ruby/object:Gem::Dependency
26
+ name: sprockets
27
+ requirement: &70128767614840 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70128767614840
36
+ description: Peaberry is a clone of dotjs server(djsd) which can serve CoffeeScript(s).
37
+ email:
38
+ - sakuro@2238club.org
39
+ executables:
40
+ - peaberry
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - LICENSE
47
+ - README.rdoc
48
+ - Rakefile
49
+ - bin/peaberry
50
+ - com.github.peaberry.plist.erb
51
+ - lib/peaberry.rb
52
+ - lib/peaberry/dot_js.rb
53
+ - lib/peaberry/mime.rb
54
+ - lib/peaberry/plist_installer.rb
55
+ - lib/peaberry/version.rb
56
+ - peaberry.gemspec
57
+ homepage: ''
58
+ licenses: []
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project: peaberry
77
+ rubygems_version: 1.8.10
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: A dotjs server clone
81
+ test_files: []