hyperloop 0.0.2 → 0.0.3

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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -0
  3. data/Gemfile +1 -1
  4. data/README.md +89 -11
  5. data/Rakefile +5 -0
  6. data/bin/hyperloop +7 -0
  7. data/hyperloop.gemspec +12 -3
  8. data/lib/hyperloop/application.rb +56 -16
  9. data/lib/hyperloop/cli.rb +11 -0
  10. data/lib/hyperloop/generators/site/Gemfile +3 -0
  11. data/lib/hyperloop/generators/site/_partial.html.erb +1 -0
  12. data/lib/hyperloop/generators/site/about.html.erb +3 -0
  13. data/lib/hyperloop/generators/site/app.css +2 -0
  14. data/lib/hyperloop/generators/site/app.js +2 -0
  15. data/lib/hyperloop/generators/site/application.html.erb +23 -0
  16. data/lib/hyperloop/generators/site/bootstrap.css +6805 -0
  17. data/lib/hyperloop/generators/site/config.ru +4 -0
  18. data/lib/hyperloop/generators/site/current-time.coffee +3 -0
  19. data/lib/hyperloop/generators/site/index.html.erb +11 -0
  20. data/lib/hyperloop/generators/site/jquery.js +8829 -0
  21. data/lib/hyperloop/generators/site/main.scss +7 -0
  22. data/lib/hyperloop/generators/site/socool.jpg +0 -0
  23. data/lib/hyperloop/generators/site.rb +47 -0
  24. data/lib/hyperloop/response.rb +2 -2
  25. data/lib/hyperloop/version.rb +1 -1
  26. data/lib/hyperloop/view/registry.rb +90 -0
  27. data/lib/hyperloop/view/scope.rb +23 -0
  28. data/lib/hyperloop/view.rb +73 -0
  29. data/lib/hyperloop.rb +3 -1
  30. data/spec/application_spec.rb +155 -19
  31. data/spec/fixtures/assets/app/assets/images/my-gif.gif +0 -0
  32. data/spec/fixtures/assets/app/assets/images/my-jpg.jpg +0 -0
  33. data/spec/fixtures/assets/app/assets/images/my-png.png +0 -0
  34. data/spec/fixtures/assets/app/assets/javascripts/app.js +1 -0
  35. data/spec/fixtures/assets/app/assets/javascripts/my-scripts.coffee +1 -0
  36. data/spec/fixtures/assets/app/assets/shouldfail/shouldfail.css +3 -0
  37. data/spec/fixtures/assets/app/assets/stylesheets/app.css +1 -0
  38. data/spec/fixtures/assets/app/assets/stylesheets/my-styles.scss +3 -0
  39. data/spec/fixtures/assets/app/views/index.html.erb +7 -0
  40. data/spec/fixtures/assets/app/views/layouts/application.html.erb +15 -0
  41. data/spec/fixtures/assets/vendor/assets/javascripts/vendored.js +1 -0
  42. data/spec/fixtures/assets/vendor/assets/stylesheets/vendored.css +3 -0
  43. data/spec/fixtures/erb/app/views/about.html.erb +10 -0
  44. data/spec/fixtures/erb/app/views/index.html.erb +10 -0
  45. data/spec/fixtures/layouts/app/views/index.html.erb +3 -0
  46. data/spec/fixtures/layouts/app/views/layouts/application.html.erb +12 -0
  47. data/spec/fixtures/layouts/app/views/subdir/index.html.erb +3 -0
  48. data/spec/fixtures/partials/app/views/index.html.erb +3 -0
  49. data/spec/fixtures/partials/app/views/layouts/application.html.erb +12 -0
  50. data/spec/fixtures/partials/app/views/subdir/_partial.html.erb +1 -0
  51. data/spec/fixtures/partials/app/views/subdir/index.html.erb +3 -0
  52. data/spec/fixtures/partials/app/views/subdir/nonroot.html.erb +3 -0
  53. data/spec/response_spec.rb +3 -3
  54. data/spec/spec_helper.rb +34 -0
  55. data/spec/view/registry_spec.rb +56 -0
  56. data/spec/view/scope_spec.rb +21 -0
  57. data/spec/view_spec.rb +93 -0
  58. metadata +202 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 535e10622d43abc48b580faae7406dd583de7088
4
- data.tar.gz: f7a0bf12b3c795f531534dea263a6ab0bea2d752
3
+ metadata.gz: 2dfb955d1503bb9133c9c4f83c7813a1a65a1f41
4
+ data.tar.gz: 9321f9d51755fbeef6ef2bd694c3a129d273cbe4
5
5
  SHA512:
6
- metadata.gz: 06e67575817dae6fb4d83458255ac4abf763ccf6d577c273b5a9b48db4e86bde746274cd64b6c91a1486f29a83bccca4a56ac36255fe961a49a6029cfddee66c
7
- data.tar.gz: 1fa91fce8a2fc81f8d8de9a464216ab689723ce7723f030279b24153215f26ccdea1a58e2253d5b687777a6fe15a76ccac4475152001f8e3638a866a12f2f251
6
+ metadata.gz: 9c03dd0d3a042535c644e6db73be972d79783f92ed9a1231889050f3e086693aadb59d0b25716289646ba982737c2d0684c9dd1549993ca27edf4c42c10e9e94
7
+ data.tar.gz: f97317e18c1b3aa65243650b00d18fd235252799d6b740c5af0f409168e7f12e0bc98683f7424f9cd73bf76f2d0abb02dcb0081bc0b3cea2af64a26cf1e53d5c
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in hyperloop.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -1,24 +1,102 @@
1
- # Hyperloop
1
+ # Hyperloop [![Build Status](https://travis-ci.org/jakeboxer/hyperloop.png?branch=master)](https://travis-ci.org/jakeboxer/hyperloop)
2
2
 
3
- Make simple websites with a technology stack familiar to Rails programmers.
3
+ Hyperloop is a framework that lets you make static websites with a technology stack familiar to Rails programmers.
4
4
 
5
- ## Installation
5
+ Before you keep reading, let's get one thing out of the way:
6
6
 
7
- Add this line to your application's Gemfile:
7
+ ### If you think your website might need a database, do not use Hyperloop.
8
8
 
9
- gem 'hyperloop'
9
+ I came up with the idea for Hyperloop after hearing one too many experienced web developers say "I don't even know how
10
+ to set up a regular website anymore."
10
11
 
11
- And then execute:
12
+ With Hyperloop, you can create a new site just like you would with Rails. You can write ERB and Sass and CoffeeScript
13
+ and all that other good stuff. You can use layouts and partials and deploy to Heroku.
12
14
 
13
- $ bundle
15
+ Basically, you can do all the stuff you're used to with Rails. On top of that, you don't have to type any of the magic
16
+ incantations that just aren't necessary in a static site. You don't have to set up routes. You don't have to make
17
+ controllers with a method for every view. You don't have to think about environments or tests or schemas or helpers or
18
+ any of the other boilerplate directories/files that would clutter up a static site being shoehorned into a Rails app.
14
19
 
15
- Or install it yourself as:
20
+ ## Getting Started
16
21
 
17
- $ gem install hyperloop
22
+ 1. Install Hyperloop and Thin at the command prompt if you haven't yet:
18
23
 
19
- ## Usage
24
+ gem install hyperloop
25
+ gem install thin
20
26
 
21
- TODO: Write usage instructions here
27
+ 2. At the command prompt, create a new Hyperloop site:
28
+
29
+ hyperloop new mysite
30
+
31
+ where "mysite" is the site name.
32
+
33
+ 3. Change directory to `mysite` and start the web server:
34
+
35
+ cd mysite
36
+ thin start
37
+
38
+ 4. Go to [http://localhost:3000/](http://localhost:3000/) and you'll see your brand new website!
39
+
40
+ ## Structure
41
+
42
+ ### Layout
43
+
44
+ Your layout is in `app/views/layouts/application.html.erb`.
45
+
46
+ ### Views
47
+
48
+ Your site root is in `app/views/index.html.erb`.
49
+
50
+ If you create `app/views/hello.html.erb`, you'll be able to get to it by going to
51
+ [http://localhost:3000/hello/](http://localhost:3000/hello/).
52
+
53
+ ### Subdirectories
54
+
55
+ You can nest views in subdirectories. If you create the following files, the following URLs will work:
56
+
57
+ - `app/views/people/ted_nyman.html.erb` will make [http://localhost:3000/people/ted_nyman/](http://localhost:3000/people/ted_nyman/) work.
58
+ - `app/views/people/index.html.erb` will make [http://localhost:3000/people/](http://localhost:3000/people/) work.
59
+ - `app/views/projects/2013/yeezus.html.erb` will make [http://localhost:3000/projects/2013/yeezus/](http://localhost:3000/projects/2013/yeezus/) work.
60
+
61
+ ### Partials
62
+
63
+ If you create `app/views/_some_section.html.erb`, you'll be able to load it as a partial almost like you would in Rails:
64
+
65
+ ``` ruby
66
+ <%= render "some_section" %>
67
+ ```
68
+
69
+ Note: In Rails, it's `<%= render :partial => "some_section" %>`, since there are other things you could want to render
70
+ besides a partial. In Hyperloop, there aren't, so the options hash isn't necessary.
71
+
72
+ ### CSS, SCSS, Sass, JavaScript, and CoffeeScript
73
+
74
+ If you create some files like:
75
+
76
+ ```
77
+ app/assets/stylesheets/bootstrap.css
78
+ app/assets/stylesheets/stylez1.css
79
+ app/assets/stylesheets/stylez2.scss
80
+ app/assets/javascripts/jquery.js
81
+ app/assets/javascripts/scriptz1.js
82
+ app/assets/javascripts/scriptz2.coffee
83
+ ```
84
+
85
+ They'll be included in all your views, so long as you have these two tags:
86
+
87
+ ``` html
88
+ <!-- I suggest putting this in between <head> and </head> -->
89
+ <link href="/assets/stylesheets/app.css" media="all" rel="stylesheet" type="text/css">
90
+
91
+ <!-- I suggest putting this at the end of the document body (as in, right before </body>) -->
92
+ <script src="/assets/javascripts/app.js" type="text/javascript"></script>
93
+ ```
94
+
95
+ somewhere in your layout. All your CSS and JS assets belong in these folders, including vendored ones like jQuery and Bootstrap.
96
+
97
+ ### Images
98
+
99
+ If you create `app/assets/images/photo.jpg`, you'll be able to show it in a view with `<img src="/assets/images/photo.jpg">`.
22
100
 
23
101
  ## Contributing
24
102
 
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/hyperloop ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
5
+ require "hyperloop/cli"
6
+
7
+ Hyperloop::CLI.start
data/hyperloop.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'hyperloop/version'
4
+ require "hyperloop/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "hyperloop"
@@ -18,9 +18,18 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency 'rack', '~> 1.5'
21
+ spec.add_dependency "coffee-script", "~> 2.2.0"
22
+ spec.add_dependency "rack", "~> 1.5"
23
+ spec.add_dependency "sass", "~> 3.2.12"
24
+ spec.add_dependency "sprockets", "~> 2.10.0"
25
+ spec.add_dependency "thor", "~> 0.18.1"
26
+ spec.add_dependency "tilt", "~> 1.4.1"
27
+ spec.add_dependency "yui-compressor", "~> 0.12.0"
22
28
 
23
29
  spec.add_development_dependency "bundler", "~> 1.3"
30
+ spec.add_development_dependency "nokogiri", "~> 1.6.0"
31
+ spec.add_development_dependency "pry"
32
+ spec.add_development_dependency "pry-debugger"
24
33
  spec.add_development_dependency "rake"
25
34
  spec.add_development_dependency "rspec", "~> 2.14"
26
35
  end
@@ -1,26 +1,32 @@
1
- require 'rack'
1
+ require "rack"
2
+ require "sprockets"
3
+ require "yui/compressor"
2
4
 
3
5
  module Hyperloop
4
6
  class Application
5
7
  include Rack::Utils
6
8
 
7
9
  def initialize(root=nil)
8
- @root = root
9
- @views_path = File.join([@root, 'app/views'].compact)
10
+ @root = root
11
+ @view_registry = View::Registry.new(@root)
10
12
  end
11
13
 
12
14
  # Rack call interface.
13
15
  def call(env)
14
16
  request = Rack::Request.new(env)
15
17
  response = Response.new
16
- path = view_path(request)
17
18
 
18
- if File.exist?(path)
19
- # If there's a file at the view path, use its data as the response body.
20
- data = File.read(path)
19
+ if self.class.asset_path?(request.path) && asset = assets[normalized_asset_path(request.path)]
20
+ # If the path is for an asset, find the specified asset and use its data
21
+ # as the response body.
22
+ response["Content-Type"] = asset.content_type
23
+ response.write(asset.source)
24
+ elsif view = @view_registry.find_template_view(normalized_request_path(request.path))
25
+ # If there's a view at the path, use its data as the response body.
26
+ data = view.render(request)
21
27
  response.write(data)
22
28
  else
23
- # If there's no file at the view path, 404.
29
+ # If there's no view at the path, 404.
24
30
  response.status = 404
25
31
  end
26
32
 
@@ -29,17 +35,51 @@ module Hyperloop
29
35
 
30
36
  private
31
37
 
32
- # Internal: Get the view path for the specified request.
38
+ # Internal: Is the specified path for assets?
33
39
  #
34
- # request - Rack::Request to get the view path for.
40
+ # path - Path to check.
35
41
  #
36
- # Returns a String.
37
- def view_path(request)
38
- path = File.join(@views_path, request.path).chomp('/')
42
+ # Returns a boolean.
43
+ def self.asset_path?(path)
44
+ path =~ /^\/assets\/(images|javascripts|stylesheets)\//
45
+ end
46
+
47
+ # Internal: The sprockets environment for the app.
48
+ #
49
+ # Returns a Sprockets::Environment.
50
+ def assets
51
+ @assets ||= Sprockets::Environment.new do |env|
52
+ env.append_path(File.join(@root, "app", "assets"))
53
+ env.append_path(File.join(@root, "vendor", "assets"))
54
+
55
+ # compress everything in production
56
+ if ENV["RACK_ENV"] == "production"
57
+ env.js_compressor = YUI::JavaScriptCompressor.new(:munge => true)
58
+ env.css_compressor = YUI::CssCompressor.new
59
+ end
60
+ end
61
+ end
62
+
63
+ # Internal: Get a normalized version of the specified asset path.
64
+ #
65
+ # path - Asset path to normalize
66
+ #
67
+ # Returns a string.
68
+ def normalized_asset_path(path)
69
+ path.sub(/^\/assets\//, "")
70
+ end
39
71
 
40
- # If we're currently pointing to a directory, get index in it.
41
- path = File.join(path, 'index') if Dir.exist?(path)
42
- path + '.html'
72
+ # Internal: Get a normalized version of the specified request path.
73
+ #
74
+ # path - Request path to normalize
75
+ #
76
+ # Returns a string.
77
+ def normalized_request_path(path)
78
+ if path == "/"
79
+ path
80
+ else
81
+ path.chomp("/")
82
+ end
43
83
  end
44
84
  end
45
85
  end
@@ -0,0 +1,11 @@
1
+ require "hyperloop/generators/site"
2
+ require "thor"
3
+
4
+ module Hyperloop
5
+ class CLI < Thor
6
+ desc "new SITENAME", "Create a new Hyperloop site. \"hyperloop new my_site\" creates a new site called MySite in \"./my_site\""
7
+ def new(name)
8
+ Hyperloop::Generators::Site.start([name])
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "hyperloop", "<%= Hyperloop::VERSION %>"
@@ -0,0 +1 @@
1
+ <p>Here's a partial! You know it's a partial because the filename starts with an underscore.</p>
@@ -0,0 +1,3 @@
1
+ <h2>About</h2>
2
+
3
+ <p>This page is accessible by making a request to /about from your browser.</p>
@@ -0,0 +1,2 @@
1
+ //= require_tree ../../../vendor/assets/stylesheets
2
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ //= require_tree ../../../vendor/assets/javascripts
2
+ //= require_tree .
@@ -0,0 +1,23 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= name.capitalize %></title>
5
+
6
+ <link href="/assets/stylesheets/app.css" media="all" rel="stylesheet" type="text/css">
7
+ </head>
8
+
9
+ <body>
10
+ <h1>Welcome to <%= name.capitalize %>!</h1>
11
+
12
+ <nav>
13
+ <ul>
14
+ <li><a href="/">Home</a></li>
15
+ <li><a href="/about">About</a></li>
16
+ </ul>
17
+ </nav>
18
+
19
+ <%%= yield %>
20
+
21
+ <script src="/assets/javascripts/app.js" type="text/javascript"></script>
22
+ </body>
23
+ </html>