grounds 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 518239f5829185ec886ed17a8eabf2355f752fa0
4
- data.tar.gz: d257dee4c67cadf6ede99359c82673c8bc34f742
3
+ metadata.gz: 3c15cb7acf34a6c49248ce9020cbf9ded136099b
4
+ data.tar.gz: 07578d08b28d51794ab3354da4f76a099423bf3a
5
5
  SHA512:
6
- metadata.gz: e52b26e7b14e253a01acac9ef1ce14b57f6b4f1ec7a9cb7bc629f95d4d591f88ccff6ca7b74ee63db7ee3dde40d498e136ebb3291dc9d69f7c0dbb9f4f883a08
7
- data.tar.gz: 9eeb8a070cbff001b9f1880d3ad018fbefae68172a74a730d8d9479b28918d8da4c5a65a6f74d8ea27a901cba2b362f4d236f8e5e1fb00295abadae72f60fbcc
6
+ metadata.gz: aff7833c2cec2daafbc24e9407f1267a3ab264156d19c55f5f8b9d6f75565824df142a9966ea5b20cd41d28c28bad71481aaa0625ed6f4af0e49332ffff97adf
7
+ data.tar.gz: b236d5666e733e5490b750184b051409069f1d6dc8a3e18449ab9c63bfa9803b6f01ad283ba631ad82da70c9d4fcb8a0ec7534bea1a6b3f8ec25ea5d6e4c6ae7
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grounds (0.0.1)
4
+ grounds (0.1.0)
5
5
  rack (~> 1.5.0)
6
6
  rack-slashenforce (= 0.0.2)
7
7
 
data/Makefile CHANGED
@@ -1,16 +1,16 @@
1
1
  GEM = pkg/grounds-$(shell cat VERSION).gem
2
2
 
3
- all: test html Gemfile.lock clean
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 lib/rack/grounds.rb
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
1
+ 0.1.0
@@ -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
- --attributes() { attributes+=" $1"; }
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 attributes charset viewport)
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
- --head() { head+=("$1"); }
33
- --body() { body+=("$1"); }
34
- --foot() { foot+=("$1"); }
35
- --title() { --head "$(printf "$title_tag" "$1")"; }
36
- --stylesheet() { --head "$(printf "$stylesheet_tag" "$1")"; }
37
- --javascript() { --foot "$(printf "$javascript_tag" "$1")"; }
38
- --asset() case "$1" in
39
- *.css) --stylesheet "$1";;
40
- *.js) --javascript "$1";;
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
- body=("${body[@]}" "${foot[@]}")
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" "$attributes"`
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[@]}"`
@@ -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 = 'Grounds, HTML app toolkit'
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($/)
@@ -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
@@ -1,8 +1,92 @@
1
+ require 'grounds'
2
+ require 'json'
1
3
  require 'rack'
2
4
  require 'rack-slashenforce'
3
5
 
4
- Rack::Grounds = Rack::Builder.new {
5
- use Rack::AppendTrailingSlash
6
- use Rack::Static, urls: [''], root: 'public', index: 'index.html'
7
- run -> { [404, { 'Content-Type' => 'text/plain' }, ['Not found']] }
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
@@ -6,7 +6,7 @@
6
6
  <link rel="stylesheet" href="index.css">
7
7
  </head>
8
8
  <body>
9
- <p>Grounds is the modern web developer’s best friend.</p>
9
+ <h1>Grounds console</h1>
10
10
  <script src="index.js"></script>
11
11
  </body>
12
12
  </html>
@@ -0,0 +1,6 @@
1
+ CACHE MANIFEST
2
+ #= App-Body: <h1>Grounds console</h1>
3
+
4
+ NETWORK:
5
+ index.css
6
+ index.js
@@ -1,11 +1,11 @@
1
1
  # -*- sh -*-
2
2
  @test "all features" {
3
3
  bin/grounds <<'^D' |
4
- Language: sv
5
- Attributes: ng-app="foo"
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.1
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-25 00:00:00.000000000 Z
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: Grounds, HTML app toolkit
115
+ summary: HTML5 app framework
117
116
  test_files: []
@@ -1,4 +0,0 @@
1
- all: index.html
2
-
3
- %.html: %.html.grounds
4
- ../bin/grounds <$< >$@
@@ -1,4 +0,0 @@
1
- index.css
2
- index.js
3
-
4
- <p>Grounds is the modern web developer’s best friend.</p>