sitespec 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8d6222e445f895dd7381c1814d6f8147f759cc5d
4
+ data.tar.gz: 0ab9b64d04ef3c0fde3190861d62fbadef7b05dd
5
+ SHA512:
6
+ metadata.gz: 25f303786ec48c337ac19b5f8f9c1edf0659e46ec2f9b34ead47507fdeabc710266c2f2b3e2f812ef7a9ede6e64cacb66e27d6f7c32bda87c861e1ad94962a25
7
+ data.tar.gz: 88e4be9dafab41c38f2f8357fd94dfccbb3489e80eb8f06e38bced2737aefa95419ac5a509909899c5a267cd0c39b1d522505042e038c337a66667b9b2b0d3f6
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ /build
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Ryo Nakamura
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Sitespec
2
+ Generate static site from your rack application & spec definition.
3
+
4
+ ## Installation
5
+ ```sh
6
+ # shell-command
7
+ gem install sitespec
8
+ ```
9
+
10
+ ## Usage
11
+ ```ruby
12
+ # spec/your_spec.rb
13
+ require "sitespec"
14
+
15
+ Sitespec.configure do
16
+ self.application = MyRackApplication.new
17
+ self.build_path = "build"
18
+ end
19
+
20
+ describe "Static site generation" do
21
+ include Sitespec
22
+
23
+ it "generates static files from rack application" do
24
+ get "/stylesheets/all.css"
25
+ get "/images/favicon.ico"
26
+ get "/index.html"
27
+ get "/2000/01/01/hello.html"
28
+ get "/2000/01/02/world.html"
29
+ get "/feed.xml"
30
+ end
31
+ end
32
+ ```
33
+
34
+ ```sh
35
+ # shell-command
36
+ rspec
37
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ module Sitespec
2
+ class Builder
3
+ def self.build(*args)
4
+ new(*args).build
5
+ end
6
+
7
+ def initialize(request)
8
+ @request = request
9
+ end
10
+
11
+ def build
12
+ Response.new(*call).tap {|response| Writer.write(@request, response) }
13
+ end
14
+
15
+ def call
16
+ Sitespec.configuration.application.call(@request.env)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ require "pathname"
2
+
3
+ module Sitespec
4
+ class Configuration
5
+ attr_accessor :application, :build_path
6
+
7
+ def initialize
8
+ @build_path = "build"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,40 @@
1
+ require "stringio"
2
+ require "uri"
3
+
4
+ module Sitespec
5
+ class Request
6
+ def initialize(method, path, params = {}, custom_env = {})
7
+ @custom_env = custom_env
8
+ @method = method
9
+ @params = params
10
+ @path = path
11
+ end
12
+
13
+ def env
14
+ @env ||= {
15
+ "HTTPS" => https? ? "on" : "off",
16
+ "HTTP_HOST" => uri.host,
17
+ "PATH_INFO" => uri.path,
18
+ "QUERY_STRING" => uri.query,
19
+ "REQUEST_METHOD" => @method.to_s.upcase,
20
+ "REQUEST_URI" => uri.to_s,
21
+ "SERVER_NAME" => uri.hostname,
22
+ "SERVER_PORT" => uri.port,
23
+ "rack.errors" => StringIO.new,
24
+ "rack.input" => StringIO.new,
25
+ "rack.multithread" => false,
26
+ "rack.run_once" => false,
27
+ "rack.url_scheme" => https? ? "http" : "https",
28
+ "rack.version" => [1, 1],
29
+ }.merge(@custom_env)
30
+ end
31
+
32
+ def uri
33
+ @uri ||= URI.parse(@path)
34
+ end
35
+
36
+ def https?
37
+ URI::HTTP === uri && uri.https?
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,17 @@
1
+ module Sitespec
2
+ class Response
3
+ attr_reader :status, :header
4
+
5
+ def initialize(status, header, body)
6
+ @body = body
7
+ @header = header
8
+ @status = status
9
+ end
10
+
11
+ def body
12
+ lines = []
13
+ @body.each {|line| lines << line }
14
+ lines.join
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module Sitespec
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,29 @@
1
+ module Sitespec
2
+ class Writer
3
+ def self.write(*args)
4
+ new(*args).write
5
+ end
6
+
7
+ def initialize(request, response)
8
+ @request = request
9
+ @response = response
10
+ end
11
+
12
+ def write
13
+ mkpath
14
+ create
15
+ end
16
+
17
+ def path
18
+ @path ||= Pathname.new("#{Sitespec.configuration.build_path}#{@request.uri.path}")
19
+ end
20
+
21
+ def mkpath
22
+ path.parent.mkpath
23
+ end
24
+
25
+ def create
26
+ path.open("w") {|file| file << @response.body }
27
+ end
28
+ end
29
+ end
data/lib/sitespec.rb ADDED
@@ -0,0 +1,41 @@
1
+ require "sitespec/builder"
2
+ require "sitespec/configuration"
3
+ require "sitespec/request"
4
+ require "sitespec/response"
5
+ require "sitespec/version"
6
+ require "sitespec/writer"
7
+
8
+ module Sitespec
9
+ def self.configuration
10
+ @configuration ||= Configuration.new
11
+ end
12
+
13
+ def self.configure(&block)
14
+ configuration.instance_eval(&block)
15
+ end
16
+
17
+ module_function
18
+
19
+ attr_reader :request, :response
20
+
21
+ def get(path, params = {}, env = {})
22
+ process(:get, path, params, env)
23
+ end
24
+
25
+ def post(path, params = {}, env = {})
26
+ process(:post, path, params, env)
27
+ end
28
+
29
+ def put(path, params = {}, env = {})
30
+ process(:put, path, params, env)
31
+ end
32
+
33
+ def delete(path, params = {}, env = {})
34
+ process(:delete, path, params, env)
35
+ end
36
+
37
+ def process(*args)
38
+ @request = Request.new(*args)
39
+ @response = Builder.build(@request)
40
+ end
41
+ end
data/sitespec.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "sitespec/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "sitespec"
7
+ spec.version = Sitespec::VERSION
8
+ spec.authors = ["Ryo Nakamura"]
9
+ spec.email = ["r7kamura@gmail.com"]
10
+ spec.summary = "Generate static site from your rack application & spec definition"
11
+ spec.homepage = "https://github.com/r7kamura/sitespec"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", ">= 1.4"
20
+ spec.add_development_dependency "pry"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec", ">= 2.14.1"
23
+ end
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+
3
+ describe Sitespec do
4
+ before do
5
+ Sitespec.configuration.application = ->(env) do
6
+ [200, {}, ["OK"]]
7
+ end
8
+ end
9
+
10
+ it "generates static files from rack application" do
11
+ get "/index.html"
12
+ response.status.should == 200
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
+ require "sitespec"
3
+
4
+ RSpec.configure do |config|
5
+ config.treat_symbols_as_metadata_keys_with_true_values = true
6
+ config.include Sitespec
7
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sitespec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryo Nakamura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.14.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: 2.14.1
69
+ description:
70
+ email:
71
+ - r7kamura@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/sitespec.rb
82
+ - lib/sitespec/builder.rb
83
+ - lib/sitespec/configuration.rb
84
+ - lib/sitespec/request.rb
85
+ - lib/sitespec/response.rb
86
+ - lib/sitespec/version.rb
87
+ - lib/sitespec/writer.rb
88
+ - sitespec.gemspec
89
+ - spec/sitespec_spec.rb
90
+ - spec/spec_helper.rb
91
+ homepage: https://github.com/r7kamura/sitespec
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.0.3
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Generate static site from your rack application & spec definition
115
+ test_files:
116
+ - spec/sitespec_spec.rb
117
+ - spec/spec_helper.rb
118
+ has_rdoc: