ichiban 0.0.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ichiban/command.rb +13 -1
- data/lib/ichiban/config.rb +7 -17
- data/lib/ichiban/deleter.rb +24 -0
- data/lib/ichiban/dependencies.rb +33 -0
- data/lib/ichiban/file.rb +115 -0
- data/lib/ichiban/helpers.rb +6 -10
- data/lib/ichiban/html_compiler.rb +61 -0
- data/lib/ichiban/logger.rb +59 -3
- data/lib/ichiban/markdown.rb +34 -0
- data/lib/ichiban/watcher.rb +35 -3
- data/lib/ichiban.rb +44 -17
- metadata +123 -74
- data/.gitignore +0 -5
- data/Gemfile +0 -4
- data/README +0 -56
- data/bin/ichiban.rb +0 -6
- data/ichiban.gemspec +0 -25
- data/klass.rb +0 -7
- data/lib/ichiban/compilation.rb +0 -93
- data/lib/ichiban/erb_page.rb +0 -16
- data/lib/ichiban/files.rb +0 -105
- data/lib/ichiban/layouts.rb +0 -10
- data/lib/ichiban/loading.rb +0 -19
- data/lib/ichiban/mapping.rb +0 -38
- data/lib/ichiban/path.rb +0 -55
- data/lib/ichiban/script_runner.rb +0 -33
- data/lib/ichiban/tasks.rb +0 -23
- data/lib/ichiban/version.rb +0 -3
- data/sample/Rakefile +0 -2
- data/sample/compiled/about.html +0 -13
- data/sample/compiled/bad.html +0 -0
- data/sample/compiled/images/check.png +0 -0
- data/sample/compiled/index.html +0 -13
- data/sample/compiled/javascripts/interaction.js +0 -1
- data/sample/compiled/staff/_employee.html +0 -13
- data/sample/compiled/staff/andre-marques.html +0 -13
- data/sample/compiled/staff/index.html +0 -17
- data/sample/compiled/staff/jarrett-colby.html +0 -13
- data/sample/compiled/stylesheets/reset.css +0 -1
- data/sample/compiled/stylesheets/screen.css +0 -1
- data/sample/config.rb +0 -3
- data/sample/content/about.html +0 -1
- data/sample/content/bad.html +0 -3
- data/sample/content/index.html +0 -1
- data/sample/content/staff/_employee.html +0 -1
- data/sample/content/staff/index.html +0 -6
- data/sample/data/employees.csv +0 -2
- data/sample/errors/404.html +0 -1
- data/sample/helpers/staff_helper.rb +0 -5
- data/sample/images/check.png +0 -0
- data/sample/javascripts/interaction.js +0 -1
- data/sample/layouts/default.html +0 -13
- data/sample/models/employee.rb +0 -16
- data/sample/scripts/bad.rb +0 -1
- data/sample/scripts/staff.rb +0 -8
- data/sample/stylesheets/reset.css +0 -1
- data/sample/stylesheets/screen.scss +0 -5
- data/spec/integration_spec.rb +0 -89
- data/spec/path_spec.rb +0 -15
- data/spec/spec_helper.rb +0 -19
@@ -1,33 +0,0 @@
|
|
1
|
-
module Ichiban
|
2
|
-
# This class runs .rb files located in the content folder. Its main purpose is to generate pages from databases.
|
3
|
-
class ScriptRunner
|
4
|
-
include Layouts
|
5
|
-
|
6
|
-
def generate(template_path_from_content_root, destination_path_from_site_root, ivars)
|
7
|
-
template_path = Path.new(
|
8
|
-
File.join(Ichiban.project_root, 'content', template_path_from_content_root)
|
9
|
-
)
|
10
|
-
destination_path = Path.new(
|
11
|
-
File.join(Ichiban.project_root, 'compiled', destination_path_from_site_root + '.html')
|
12
|
-
)
|
13
|
-
erb_context = ErbPage::Context.new(ivars.merge(:_current_path => destination_path_from_site_root))
|
14
|
-
result = ErbPage.new(File.read(template_path.abs), :filename => template_path.abs).evaluate(erb_context)
|
15
|
-
result = wrap_in_layouts(erb_context, result)
|
16
|
-
File.open(destination_path.abs, 'w') do |f|
|
17
|
-
f.write result
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def initialize(path)
|
22
|
-
@source = path.abs
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.run_script_file(path)
|
26
|
-
new(path).run
|
27
|
-
end
|
28
|
-
|
29
|
-
def run
|
30
|
-
instance_eval(File.read(@source), @source)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/lib/ichiban/tasks.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module Ichiban
|
2
|
-
def self.define_tasks(rakefile)
|
3
|
-
desc 'Generates the static site and puts it in the "compiled" directory. Files will only be compiled as necessary. If a layout has been modified, all files will be recompiled.'
|
4
|
-
task :compile => :init do
|
5
|
-
Ichiban::Compiler.new.compile
|
6
|
-
end
|
7
|
-
|
8
|
-
desc 'Generates the static site and puts it in the "compiled" directory. All files will be compiled from scratch.'
|
9
|
-
task :fresh => :init do
|
10
|
-
Ichiban::Compiler.new.fresh
|
11
|
-
end
|
12
|
-
|
13
|
-
desc 'Continuously watch for changes and compile files as needed.'
|
14
|
-
task :watch => :init do
|
15
|
-
Ichiban::Watcher.new.watch
|
16
|
-
end
|
17
|
-
|
18
|
-
desc 'Initialize Ichiban.'
|
19
|
-
task :init do
|
20
|
-
Ichiban.configure_for_project(File.dirname(File.expand_path(rakefile)))
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/lib/ichiban/version.rb
DELETED
data/sample/Rakefile
DELETED
data/sample/compiled/about.html
DELETED
data/sample/compiled/bad.html
DELETED
File without changes
|
Binary file
|
data/sample/compiled/index.html
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
// Foo
|
@@ -1,17 +0,0 @@
|
|
1
|
-
<!DOCTYPE HTML>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>Sample</title>
|
5
|
-
</head>
|
6
|
-
|
7
|
-
<body>
|
8
|
-
|
9
|
-
<h1>Employees</h1>
|
10
|
-
<ul>
|
11
|
-
<li><a href="/staff/jarrett-{employee.last.downcase}/">Jarrett Colby</a></li>
|
12
|
-
<li><a href="/staff/andre-{employee.last.downcase}/">Andre Marques</a></li>
|
13
|
-
</ul>
|
14
|
-
|
15
|
-
</body>
|
16
|
-
|
17
|
-
</html>
|
@@ -1 +0,0 @@
|
|
1
|
-
h1, h2, h3, h4, h5, h6 {font-size: 100%;}
|
@@ -1 +0,0 @@
|
|
1
|
-
body h1{color:#f04040}
|
data/sample/config.rb
DELETED
data/sample/content/about.html
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
<h1>About</h1>
|
data/sample/content/bad.html
DELETED
@@ -1,3 +0,0 @@
|
|
1
|
-
<!-- This page demonstrates what happens when an error is raised inside a page. The compiler should report the error and gracefully recover. -->
|
2
|
-
|
3
|
-
<% raise "This error is being generated by content/bad.html. This is intentional. The purpose is to illustrate how the compiler recovers gracefully from an in-page error." %>
|
data/sample/content/index.html
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
<h1>Home</h1>
|
@@ -1 +0,0 @@
|
|
1
|
-
<h1><%= @first %> <%= @last %></h1>
|
data/sample/data/employees.csv
DELETED
data/sample/errors/404.html
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
<h1>The page does not exist.</h1>
|
data/sample/images/check.png
DELETED
Binary file
|
@@ -1 +0,0 @@
|
|
1
|
-
// Foo
|
data/sample/layouts/default.html
DELETED
data/sample/models/employee.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
class Employee
|
2
|
-
def self.all
|
3
|
-
CSV.read(File.join(Ichiban.project_root, 'data', 'employees.csv')).collect do |row|
|
4
|
-
new(row[0], row[1])
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
attr_accessor :first
|
9
|
-
|
10
|
-
def initialize(first, last)
|
11
|
-
@first = first
|
12
|
-
@last = last
|
13
|
-
end
|
14
|
-
|
15
|
-
attr_accessor :last
|
16
|
-
end
|
data/sample/scripts/bad.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
raise 'This error is being generated by scripts/bad.rb. This is intentional. The purpose is to illustrate how the compiler recovers gracefully from a script error.'
|
data/sample/scripts/staff.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
h1, h2, h3, h4, h5, h6 {font-size: 100%;}
|
data/spec/integration_spec.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
2
|
-
require 'nokogiri'
|
3
|
-
|
4
|
-
describe Ichiban do
|
5
|
-
def compiled(path = nil)
|
6
|
-
path.nil? ? File.join(root, 'compiled') : File.join(root, 'compiled', path)
|
7
|
-
end
|
8
|
-
|
9
|
-
def parse_compiled(path)
|
10
|
-
@parsed_html ||= {}
|
11
|
-
@parsed_html[path] ||= Nokogiri.HTML(File.read(compiled(path)))
|
12
|
-
end
|
13
|
-
|
14
|
-
def root
|
15
|
-
File.expand_path(File.join(File.dirname(__FILE__), '../sample'))
|
16
|
-
end
|
17
|
-
|
18
|
-
before(:all) do
|
19
|
-
FileUtils.rm_rf compiled
|
20
|
-
FileUtils.mkdir compiled
|
21
|
-
end
|
22
|
-
|
23
|
-
shared_examples_for 'compilation' do
|
24
|
-
it 'creates all the content files and directories as needed' do
|
25
|
-
compiled('index.html').should be_file
|
26
|
-
compiled('about.html').should be_file
|
27
|
-
compiled('staff/index.html').should be_file
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'renders the content' do
|
31
|
-
parse_compiled('index.html').css('h1').inner_html.should == 'Home'
|
32
|
-
parse_compiled('about.html').css('h1').inner_html.should == 'About'
|
33
|
-
parse_compiled('staff/index.html').css('h1').inner_html.should == 'Employees'
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'inserts the content into the layout' do
|
37
|
-
parse_compiled('index.html').css('head').length.should == 1
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'copies images' do
|
41
|
-
compiled('images/check.png').should be_file
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'compiles SCSS' do
|
45
|
-
File.read(compiled('stylesheets/screen.css')).should include('body h1{color:#f04040}')
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'copies CSS' do
|
49
|
-
compiled('stylesheets/reset.css').should be_file
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'copies JS' do
|
53
|
-
compiled('javascripts/interaction.js').should be_file
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'logs errors raised within content files' do
|
57
|
-
Ichiban.logger.test_messages.detect do |msg|
|
58
|
-
msg.start_with?('RuntimeError: This error is being generated by content/bad.html. This is intentional. The purpose is to illustrate how the compiler recovers gracefully from an in-page error.')
|
59
|
-
end.should_not be_nil
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'logs errors raised within scripts' do
|
63
|
-
Ichiban.logger.test_messages.detect do |msg|
|
64
|
-
msg.start_with?('RuntimeError: This error is being generated by scripts/bad.rb. This is intentional. The purpose is to illustrate how the compiler recovers gracefully from a script error.')
|
65
|
-
end.should_not be_nil
|
66
|
-
end
|
67
|
-
|
68
|
-
context 'with scripts' do
|
69
|
-
it 'generates files' do
|
70
|
-
compiled('staff/andre-marques.html').should be_file
|
71
|
-
compiled('staff/jarrett-colby.html').should be_file
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'interpolates data into the template' do
|
75
|
-
parse_compiled('staff/andre-marques.html').css('h1').inner_html == 'Andre Marques'
|
76
|
-
parse_compiled('staff/jarrett-colby.html').css('h1').inner_html == 'Jarrett Colby'
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context 'fresh compile' do
|
82
|
-
before(:all) do
|
83
|
-
Ichiban.configure_for_project(root)
|
84
|
-
Ichiban::Compiler.new.fresh
|
85
|
-
end
|
86
|
-
|
87
|
-
it_should_behave_like 'compilation'
|
88
|
-
end
|
89
|
-
end
|
data/spec/path_spec.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'ichiban'
|
2
|
-
|
3
|
-
include Ichiban
|
4
|
-
|
5
|
-
describe Path do
|
6
|
-
#describe '#relative_from' do
|
7
|
-
# it 'returns the path relative to the given subfolder' do
|
8
|
-
# Path.new('/project/content/foo/index.html').relative_from('content').should == 'foo/index.html'
|
9
|
-
# end
|
10
|
-
#
|
11
|
-
# it 'raises if the file is not in the given subfolder' do
|
12
|
-
# lambda { Path.new('/project/content/foo/index.html').relative_from('errors') }.should raise_error
|
13
|
-
# end
|
14
|
-
#end
|
15
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# Put the working directory's version of Ichiban first in the list of load paths. That way,
|
2
|
-
# we won't load an installed version of the gem.
|
3
|
-
$:.unshift File.expand_path(File.join(File.dirname(__FILE__)), '../lib')
|
4
|
-
|
5
|
-
require 'ichiban'
|
6
|
-
|
7
|
-
module Ichiban
|
8
|
-
class Logger
|
9
|
-
def out(msg)
|
10
|
-
(@test_messages ||= []) << msg
|
11
|
-
end
|
12
|
-
|
13
|
-
attr_reader :test_messages
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
RSpec::Matchers.define :be_file do
|
18
|
-
match { |path| File.exists?(path) }
|
19
|
-
end
|