rails-static 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.md +44 -0
- data/lib/rails-static/config.rb +16 -0
- data/lib/rails-static/railtie.rb +9 -0
- data/lib/rails-static.rb +22 -0
- data/lib/tasks/static.rake +76 -0
- data/rails-static.gemspec +17 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NWMyNDE4OTAxYTU4NWE4MThiZDZmNGE4OTdhZDdhYzBhN2Q0Y2QyYg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YWEyNWJkNzExNzY0ZjE0MTI1MWMyNzExNTEwMGQ0OGJlMGEyMzExYQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YzNjOGMyOTQyY2UxMGY5MTM0YTNlNDE0MmI4YjQ4MzZlMmQ3ZjAxMDEyZTc5
|
10
|
+
ZGQ2NWU0NDQ0ZTExNDE3MzhlNGZjNTYxMjMyZDhlYTBhNzQyZjEwNWYyNDAx
|
11
|
+
M2VlMGFkYWY5YmRlMDIwMTk0MGRiNDViOGY4YTNkMGZjN2Q3YzI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NGZiOWY3ZGQ1ZDk5YTYzZWFmODkzNTA3NzJkY2VlNGZhNjBlNjZjZDJhMmVj
|
14
|
+
ZTc4ZjI1NDdkODU0ZGQ5MjZiMDVmZTE0MjI1MDA4YTJlZTk1ZDU2N2Q0MTBj
|
15
|
+
ZWVlOTFjZTllY2ZmODdiOTdhYWUzYzViYjg2OWU5NGE3NzUxMzQ=
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
rails-static
|
2
|
+
=============================
|
3
|
+
|
4
|
+
A set of Rake tasks for generating static pages with Rails.
|
5
|
+
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
Add to your Gemfile:
|
10
|
+
|
11
|
+
`gem 'rails-static'`
|
12
|
+
|
13
|
+
Add to an initializer:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
if defined?(RailsStatic)
|
17
|
+
RailsStatic.configure do |config|
|
18
|
+
|
19
|
+
config.index = 'index'
|
20
|
+
config.routes = ['/']
|
21
|
+
config.extension = '.html'
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
And run:
|
28
|
+
|
29
|
+
`rake static`
|
30
|
+
|
31
|
+
|
32
|
+
## Config options
|
33
|
+
|
34
|
+
### index
|
35
|
+
|
36
|
+
Name of generated file for urls ending in `/`. Default is `index`
|
37
|
+
|
38
|
+
### routes
|
39
|
+
|
40
|
+
Array of app urls to request. Request the root route by default.
|
41
|
+
|
42
|
+
### extension
|
43
|
+
|
44
|
+
Extension of generated files. Default is no extension.
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module RailsStatic
|
2
|
+
class Config
|
3
|
+
include ActiveModel::Validations
|
4
|
+
|
5
|
+
attr_accessor :index
|
6
|
+
attr_accessor :routes
|
7
|
+
attr_accessor :extension
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
self.index = 'index'
|
11
|
+
self.routes = ['/']
|
12
|
+
self.extension = ''
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
data/lib/rails-static.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rails-static/config'
|
2
|
+
require 'rails-static/railtie' if defined?(Rails)
|
3
|
+
|
4
|
+
module RailsStatic
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def config=(data)
|
8
|
+
@config = data
|
9
|
+
end
|
10
|
+
|
11
|
+
def config
|
12
|
+
@config ||= Config.new
|
13
|
+
@config
|
14
|
+
end
|
15
|
+
|
16
|
+
def configure(&proc)
|
17
|
+
@config ||= Config.new
|
18
|
+
yield @config
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
task :static do
|
2
|
+
Rake::Task['static:generate'].invoke
|
3
|
+
end
|
4
|
+
|
5
|
+
namespace :static do
|
6
|
+
|
7
|
+
desc "Generate static pages"
|
8
|
+
task :generate => :environment do
|
9
|
+
abort "No static routes specified." unless RailsStatic.config.routes.any?
|
10
|
+
|
11
|
+
require "rails/console/app"
|
12
|
+
require "rails/console/helpers"
|
13
|
+
extend Rails::ConsoleMethods
|
14
|
+
|
15
|
+
puts "Generating static files..."
|
16
|
+
|
17
|
+
RailsStatic.config.routes.each do |route|
|
18
|
+
|
19
|
+
path = path_from_route route
|
20
|
+
|
21
|
+
puts "Generating #{path}"
|
22
|
+
|
23
|
+
r = app.get(route)
|
24
|
+
if r == 200
|
25
|
+
fullpath = full_path path
|
26
|
+
dir = File.dirname(fullpath)
|
27
|
+
FileUtils.mkdir_p dir
|
28
|
+
File.open(fullpath, "w") do |f|
|
29
|
+
f.write(app.response.body)
|
30
|
+
end
|
31
|
+
else
|
32
|
+
$stderr.puts "Error generating static file #{path} #{r.inspect}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Delete static pages"
|
38
|
+
task :clean => :environment do
|
39
|
+
RailsStatic.config.routes.each do |route|
|
40
|
+
path = path_from_route route
|
41
|
+
fullpath = full_path path
|
42
|
+
|
43
|
+
next unless File.exists? fullpath
|
44
|
+
|
45
|
+
puts "Deleting #{path}"
|
46
|
+
|
47
|
+
File.delete(fullpath) rescue nil
|
48
|
+
end
|
49
|
+
|
50
|
+
rm_empty
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def path_from_route(route)
|
56
|
+
path = route
|
57
|
+
path = path.gsub(%r{/$}, "/#{RailsStatic.config.index}") if route =~ %r{/$}
|
58
|
+
path += RailsStatic.config.extension
|
59
|
+
end
|
60
|
+
|
61
|
+
def full_path(path)
|
62
|
+
File.join(Rails.public_path, path)
|
63
|
+
end
|
64
|
+
|
65
|
+
def rm_empty
|
66
|
+
Dir.chdir Rails.public_path do
|
67
|
+
Dir.glob("**/").reverse_each do |d|
|
68
|
+
if (Dir.entries(d) - %w[ . .. ]).empty?
|
69
|
+
puts "Deleting directory /#{d}"
|
70
|
+
Dir.rmdir(d)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "rails-static"
|
6
|
+
s.version = '1.0.0'
|
7
|
+
s.authors = ["DanX"]
|
8
|
+
s.email = ["danx.exe@gmail.com"]
|
9
|
+
s.homepage = "http://www.mobvox.com.br"
|
10
|
+
s.summary = "Generate a static site with Rails."
|
11
|
+
s.description = "A rake task for generating static websites using Rails."
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-static
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- DanX
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-03-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A rake task for generating static websites using Rails.
|
14
|
+
email:
|
15
|
+
- danx.exe@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- README.md
|
21
|
+
- lib/rails-static.rb
|
22
|
+
- lib/rails-static/config.rb
|
23
|
+
- lib/rails-static/railtie.rb
|
24
|
+
- lib/tasks/static.rake
|
25
|
+
- rails-static.gemspec
|
26
|
+
homepage: http://www.mobvox.com.br
|
27
|
+
licenses: []
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project:
|
45
|
+
rubygems_version: 2.0.0
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: Generate a static site with Rails.
|
49
|
+
test_files: []
|
50
|
+
has_rdoc:
|