grounds 0.0.1 → 0.1.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/Makefile +4 -4
- data/VERSION +1 -1
- data/bin/grounds +24 -18
- data/grounds.gemspec +1 -2
- data/lib/grounds.rb +21 -0
- data/lib/rack/grounds.rb +89 -5
- data/public/index.html +1 -1
- data/public/index.manifest +6 -0
- data/t/02-all-features.bats +5 -5
- metadata +6 -7
- data/public/Makefile +0 -4
- data/public/index.html.grounds +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c15cb7acf34a6c49248ce9020cbf9ded136099b
|
4
|
+
data.tar.gz: 07578d08b28d51794ab3354da4f76a099423bf3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aff7833c2cec2daafbc24e9407f1267a3ab264156d19c55f5f8b9d6f75565824df142a9966ea5b20cd41d28c28bad71481aaa0625ed6f4af0e49332ffff97adf
|
7
|
+
data.tar.gz: b236d5666e733e5490b750184b051409069f1d6dc8a3e18449ab9c63bfa9803b6f01ad283ba631ad82da70c9d4fcb8a0ec7534bea1a6b3f8ec25ea5d6e4c6ae7
|
data/Gemfile.lock
CHANGED
data/Makefile
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
GEM = pkg/grounds-$(shell cat VERSION).gem
|
2
2
|
|
3
|
-
all: test
|
3
|
+
all: test $(GEM) clean
|
4
4
|
|
5
5
|
test:
|
6
6
|
bats --tap t
|
7
|
-
html:
|
8
|
-
make -wC public
|
9
7
|
Gemfile.lock: Gemfile grounds.gemspec
|
10
8
|
bundle --no-color
|
11
|
-
$(GEM): Gemfile.lock
|
9
|
+
$(GEM): Gemfile.lock
|
12
10
|
rake build
|
13
11
|
install: $(GEM)
|
14
12
|
rake install
|
13
|
+
release: $(GEM)
|
14
|
+
rake release
|
15
15
|
clean:
|
16
16
|
git clean -Xdf
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/bin/grounds
CHANGED
@@ -5,12 +5,12 @@ set -o errexit
|
|
5
5
|
: ${charset=utf-8}
|
6
6
|
: ${viewport='width=device-width'}
|
7
7
|
|
8
|
-
--language() { language=$1; }
|
9
|
-
--
|
10
|
-
--charset() { charset=$1; }
|
11
|
-
--viewport() { viewport=$1; }
|
8
|
+
--app-language() { language=$1; }
|
9
|
+
--app-attrs() { attrs+=" $1"; }
|
10
|
+
--app-charset() { charset=$1; }
|
11
|
+
--app-viewport() { viewport=$1; }
|
12
12
|
|
13
|
-
preamble=(language
|
13
|
+
preamble=(app-language app-attrs app-charset app-viewport)
|
14
14
|
is-preamble-keyword()
|
15
15
|
{ printf '%s\n' ${preamble[*]} | grep "^$1\$" >/dev/null; }
|
16
16
|
maybe-insert-preamble()
|
@@ -29,34 +29,40 @@ if ! `is-preamble-keyword $1`; then
|
|
29
29
|
: ${javascript_tag:='<script src="%s"></script>'}
|
30
30
|
: ${stylesheet_tag:='<link rel="stylesheet" href="%s">'}
|
31
31
|
|
32
|
-
--
|
33
|
-
--
|
34
|
-
--
|
35
|
-
--
|
36
|
-
--
|
37
|
-
--
|
38
|
-
|
39
|
-
|
40
|
-
|
32
|
+
--app-title() { head+=("$(printf "$title_tag" "$1")"); }
|
33
|
+
--vendor-head() { head+=("$1"); }
|
34
|
+
--app-head() { app_head+=("$1"); }
|
35
|
+
--app-body() { body+=("$1"); }
|
36
|
+
--vendor-foot() { foot+=("$1"); }
|
37
|
+
--app-foot() { app_foot+=("$1"); }
|
38
|
+
|
39
|
+
--stylesheet() { --${2}head "$(printf "$stylesheet_tag" "$1")"; }
|
40
|
+
--javascript() { --${2}foot "$(printf "$javascript_tag" "$1")"; }
|
41
|
+
--vendor-asset() { asset "$1" vendor-; }
|
42
|
+
--app-asset() { asset "$1" app-; }
|
43
|
+
asset() case "$1" in
|
44
|
+
*.css) --stylesheet "$1" $2;;
|
45
|
+
*.js) --javascript "$1" $2;;
|
41
46
|
*) echo >&2 "$0: $1: ignoring unknown asset";; esac
|
42
47
|
|
43
48
|
while read keyword words; do
|
44
49
|
if [[ $keyword ]]; then
|
45
50
|
keyword=$(echo $keyword | tr A-Z a-z | sed 's/:$//')
|
46
|
-
[[ $words ]] || words=$keyword keyword=asset
|
51
|
+
[[ $words ]] || words=$keyword keyword=app-asset
|
47
52
|
if type >&/dev/null -- "--$keyword"; then
|
48
53
|
maybe-insert-preamble $keyword
|
49
54
|
--$keyword "${words[@]}"
|
50
55
|
elif [[ $keyword != '#' ]]; then
|
51
56
|
echo >&2 "$0: unknown keyword \`$keyword'"; fi
|
52
57
|
else
|
53
|
-
while read line; do --body "$line"; done; fi; done
|
58
|
+
while read line; do --app-body "$line"; done; fi; done
|
54
59
|
|
55
60
|
maybe-insert-preamble
|
56
|
-
|
61
|
+
head=("${head[@]}" "${app_head[@]}")
|
62
|
+
body=("${body[@]}" "${foot[@]}" "${app_foot[@]}")
|
57
63
|
sed 's/^ *$//' <<EOF
|
58
64
|
<!doctype html>
|
59
|
-
`printf "$html_tag" "$language" "$
|
65
|
+
`printf "$html_tag" "$language" "$attrs"`
|
60
66
|
<head>`[[ $head ]] && printf '\n %s' "${head[@]}"`
|
61
67
|
</head>
|
62
68
|
<body>`[[ $body ]] && printf '\n %s' "${body[@]}"`
|
data/grounds.gemspec
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = 'grounds'
|
3
3
|
gem.version = `cat VERSION`
|
4
|
-
gem.summary = '
|
5
|
-
gem.license = 'MIT'
|
4
|
+
gem.summary = 'HTML5 app framework'
|
6
5
|
gem.author = 'Daniel Brockman'
|
7
6
|
gem.email = 'daniel@brockman.se'
|
8
7
|
gem.files = `git ls-files`.split($/)
|
data/lib/grounds.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Grounds
|
2
|
+
ADMIN_ROOT = File.expand_path('../public', File.dirname(__FILE__))
|
3
|
+
|
4
|
+
class App
|
5
|
+
def initialize(root)
|
6
|
+
@root = root
|
7
|
+
end
|
8
|
+
|
9
|
+
def public_root
|
10
|
+
expand_path 'public'
|
11
|
+
end
|
12
|
+
|
13
|
+
def env
|
14
|
+
{ files: Dir[expand_path '*'] }
|
15
|
+
end
|
16
|
+
|
17
|
+
def expand_path(path)
|
18
|
+
File.expand_path(path, @root)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/rack/grounds.rb
CHANGED
@@ -1,8 +1,92 @@
|
|
1
|
+
require 'grounds'
|
2
|
+
require 'json'
|
1
3
|
require 'rack'
|
2
4
|
require 'rack-slashenforce'
|
3
5
|
|
4
|
-
Rack::Grounds
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
module Rack::Grounds
|
7
|
+
def self.app
|
8
|
+
admin_prefix = '!'
|
9
|
+
app = Grounds::App.new(Dir.pwd)
|
10
|
+
Rack::Builder.app do
|
11
|
+
use Rack::AppendTrailingSlash
|
12
|
+
map "/#{admin_prefix}/env.json" do
|
13
|
+
run Rack::Grounds.json_app { app.env } end
|
14
|
+
map "/#{admin_prefix}" do
|
15
|
+
run Rack::Grounds.html_app(Grounds::ADMIN_ROOT) end
|
16
|
+
map '/' do
|
17
|
+
run Rack::Grounds.html_app(app.public_root) end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.json_app(&block)
|
22
|
+
headers = { 'Content-Type' => 'application/json' }
|
23
|
+
-> (env) { [200, headers, [block[env].to_json]] }
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.html_app(root)
|
27
|
+
Rack::Builder.app do
|
28
|
+
use Rack::Grounds::DynamicIndex, root
|
29
|
+
use Rack::Static, urls: [''], index: 'index.html', root: root
|
30
|
+
run -> (env) { fail 'should never get here' }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class DynamicIndex
|
35
|
+
def initialize(app, root)
|
36
|
+
@app = app
|
37
|
+
@root = root
|
38
|
+
end
|
39
|
+
|
40
|
+
def call(env)
|
41
|
+
path = File.join(@root, env['PATH_INFO'])
|
42
|
+
if should_handle? path
|
43
|
+
[200, { 'Content-Type' => 'text/html' }, [html_for(path)]]
|
44
|
+
else
|
45
|
+
@app.call(env)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def index_for(path) File.join(path, 'index.html') end
|
50
|
+
def manifest_for(path) File.join(path, 'index.manifest') end
|
51
|
+
def should_handle? path
|
52
|
+
%r{/$} === path and not File.exist? index_for(path) and
|
53
|
+
File.exist? manifest_for(path)
|
54
|
+
end
|
55
|
+
|
56
|
+
def html_for(path)
|
57
|
+
manifest = File.read(manifest_for(path))
|
58
|
+
open '|grounds', 'w+' do |process|
|
59
|
+
parse_manifest(manifest) { |x| process.write "#{x}\n" }
|
60
|
+
process.close_write
|
61
|
+
process.read
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def parse_manifest(manifest)
|
66
|
+
yield 'App-Attrs: manifest="index.manifest"'
|
67
|
+
section = :cache
|
68
|
+
for line in manifest.lines
|
69
|
+
line.chomp!
|
70
|
+
yield $1 if line =~ /^#= (.+)$/
|
71
|
+
line.sub! /#.*/, ''
|
72
|
+
line.sub! /^\s+|\s+$/, ''
|
73
|
+
case line
|
74
|
+
when 'CACHE MANIFEST', '*', ''
|
75
|
+
when 'CACHE:'
|
76
|
+
section = :cache
|
77
|
+
when 'NETWORK:'
|
78
|
+
section = :network
|
79
|
+
when 'FALLBACK:'
|
80
|
+
section = :fallback
|
81
|
+
else
|
82
|
+
case section
|
83
|
+
when :network
|
84
|
+
yield "App-Asset: #{line}"
|
85
|
+
when :cache
|
86
|
+
yield "Vendor-Asset: #{line}"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
data/public/index.html
CHANGED
data/t/02-all-features.bats
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# -*- sh -*-
|
2
2
|
@test "all features" {
|
3
3
|
bin/grounds <<'^D' |
|
4
|
-
Language: sv
|
5
|
-
|
6
|
-
Charset: iso-8859-1
|
7
|
-
Viewport: initial-scale=1.0
|
8
|
-
Title: Example
|
4
|
+
App-Language: sv
|
5
|
+
App-Attrs: ng-app="foo"
|
6
|
+
App-Charset: iso-8859-1
|
7
|
+
App-Viewport: initial-scale=1.0
|
8
|
+
App-Title: Example
|
9
9
|
foo.js
|
10
10
|
foo.css
|
11
11
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grounds
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Brockman
|
8
8
|
autorequire:
|
9
9
|
bindir: ruby-bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -81,18 +81,17 @@ files:
|
|
81
81
|
- VERSION
|
82
82
|
- bin/grounds
|
83
83
|
- grounds.gemspec
|
84
|
+
- lib/grounds.rb
|
84
85
|
- lib/rack/grounds.rb
|
85
|
-
- public/Makefile
|
86
86
|
- public/index.css
|
87
87
|
- public/index.html
|
88
|
-
- public/index.html.grounds
|
89
88
|
- public/index.js
|
89
|
+
- public/index.manifest
|
90
90
|
- ruby-bin/grounds
|
91
91
|
- t/01-empty-input.bats
|
92
92
|
- t/02-all-features.bats
|
93
93
|
homepage:
|
94
|
-
licenses:
|
95
|
-
- MIT
|
94
|
+
licenses: []
|
96
95
|
metadata: {}
|
97
96
|
post_install_message:
|
98
97
|
rdoc_options: []
|
@@ -113,5 +112,5 @@ rubyforge_project:
|
|
113
112
|
rubygems_version: 2.1.9
|
114
113
|
signing_key:
|
115
114
|
specification_version: 4
|
116
|
-
summary:
|
115
|
+
summary: HTML5 app framework
|
117
116
|
test_files: []
|
data/public/Makefile
DELETED
data/public/index.html.grounds
DELETED