ichiban 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/lib/ichiban/command.rb +13 -1
  2. data/lib/ichiban/config.rb +7 -17
  3. data/lib/ichiban/deleter.rb +24 -0
  4. data/lib/ichiban/dependencies.rb +33 -0
  5. data/lib/ichiban/file.rb +115 -0
  6. data/lib/ichiban/helpers.rb +6 -10
  7. data/lib/ichiban/html_compiler.rb +61 -0
  8. data/lib/ichiban/logger.rb +59 -3
  9. data/lib/ichiban/markdown.rb +34 -0
  10. data/lib/ichiban/watcher.rb +35 -3
  11. data/lib/ichiban.rb +44 -17
  12. metadata +123 -74
  13. data/.gitignore +0 -5
  14. data/Gemfile +0 -4
  15. data/README +0 -56
  16. data/bin/ichiban.rb +0 -6
  17. data/ichiban.gemspec +0 -25
  18. data/klass.rb +0 -7
  19. data/lib/ichiban/compilation.rb +0 -93
  20. data/lib/ichiban/erb_page.rb +0 -16
  21. data/lib/ichiban/files.rb +0 -105
  22. data/lib/ichiban/layouts.rb +0 -10
  23. data/lib/ichiban/loading.rb +0 -19
  24. data/lib/ichiban/mapping.rb +0 -38
  25. data/lib/ichiban/path.rb +0 -55
  26. data/lib/ichiban/script_runner.rb +0 -33
  27. data/lib/ichiban/tasks.rb +0 -23
  28. data/lib/ichiban/version.rb +0 -3
  29. data/sample/Rakefile +0 -2
  30. data/sample/compiled/about.html +0 -13
  31. data/sample/compiled/bad.html +0 -0
  32. data/sample/compiled/images/check.png +0 -0
  33. data/sample/compiled/index.html +0 -13
  34. data/sample/compiled/javascripts/interaction.js +0 -1
  35. data/sample/compiled/staff/_employee.html +0 -13
  36. data/sample/compiled/staff/andre-marques.html +0 -13
  37. data/sample/compiled/staff/index.html +0 -17
  38. data/sample/compiled/staff/jarrett-colby.html +0 -13
  39. data/sample/compiled/stylesheets/reset.css +0 -1
  40. data/sample/compiled/stylesheets/screen.css +0 -1
  41. data/sample/config.rb +0 -3
  42. data/sample/content/about.html +0 -1
  43. data/sample/content/bad.html +0 -3
  44. data/sample/content/index.html +0 -1
  45. data/sample/content/staff/_employee.html +0 -1
  46. data/sample/content/staff/index.html +0 -6
  47. data/sample/data/employees.csv +0 -2
  48. data/sample/errors/404.html +0 -1
  49. data/sample/helpers/staff_helper.rb +0 -5
  50. data/sample/images/check.png +0 -0
  51. data/sample/javascripts/interaction.js +0 -1
  52. data/sample/layouts/default.html +0 -13
  53. data/sample/models/employee.rb +0 -16
  54. data/sample/scripts/bad.rb +0 -1
  55. data/sample/scripts/staff.rb +0 -8
  56. data/sample/stylesheets/reset.css +0 -1
  57. data/sample/stylesheets/screen.scss +0 -5
  58. data/spec/integration_spec.rb +0 -89
  59. data/spec/path_spec.rb +0 -15
  60. 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
@@ -1,3 +0,0 @@
1
- module Ichiban
2
- VERSION = "0.0.2"
3
- end
data/sample/Rakefile DELETED
@@ -1,2 +0,0 @@
1
- require 'ichiban'
2
- Ichiban.define_tasks(__FILE__)
@@ -1,13 +0,0 @@
1
- <!DOCTYPE HTML>
2
- <html>
3
- <head>
4
- <title>Sample</title>
5
- </head>
6
-
7
- <body>
8
-
9
- <h1>About</h1>
10
-
11
- </body>
12
-
13
- </html>
File without changes
Binary file
@@ -1,13 +0,0 @@
1
- <!DOCTYPE HTML>
2
- <html>
3
- <head>
4
- <title>Sample</title>
5
- </head>
6
-
7
- <body>
8
-
9
- <h1>Home</h1>
10
-
11
- </body>
12
-
13
- </html>
@@ -1 +0,0 @@
1
- // Foo
@@ -1,13 +0,0 @@
1
- <!DOCTYPE HTML>
2
- <html>
3
- <head>
4
- <title>Sample</title>
5
- </head>
6
-
7
- <body>
8
-
9
- <h1> </h1>
10
-
11
- </body>
12
-
13
- </html>
@@ -1,13 +0,0 @@
1
- <!DOCTYPE HTML>
2
- <html>
3
- <head>
4
- <title>Sample</title>
5
- </head>
6
-
7
- <body>
8
-
9
- <h1>Andre Marques</h1>
10
-
11
- </body>
12
-
13
- </html>
@@ -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,13 +0,0 @@
1
- <!DOCTYPE HTML>
2
- <html>
3
- <head>
4
- <title>Sample</title>
5
- </head>
6
-
7
- <body>
8
-
9
- <h1>Jarrett Colby</h1>
10
-
11
- </body>
12
-
13
- </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
@@ -1,3 +0,0 @@
1
- Ichiban.config do |cfg|
2
- cfg.relative_url_root = '/'
3
- end
@@ -1 +0,0 @@
1
- <h1>About</h1>
@@ -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." %>
@@ -1 +0,0 @@
1
- <h1>Home</h1>
@@ -1 +0,0 @@
1
- <h1><%= @first %> <%= @last %></h1>
@@ -1,6 +0,0 @@
1
- <h1>Employees</h1>
2
- <ul>
3
- <% Employee.all.each do |employee| %>
4
- <li><%= link_to employee.first + ' ' + employee.last, employee_path(employee) %></li>
5
- <% end %>
6
- </ul>
@@ -1,2 +0,0 @@
1
- Jarrett,Colby
2
- Andre,Marques
@@ -1 +0,0 @@
1
- <h1>The page does not exist.</h1>
@@ -1,5 +0,0 @@
1
- module StaffHelper
2
- def employee_path(employee)
3
- "/staff/#{employee.first.downcase}-{employee.last.downcase}/"
4
- end
5
- end
Binary file
@@ -1 +0,0 @@
1
- // Foo
@@ -1,13 +0,0 @@
1
- <!DOCTYPE HTML>
2
- <html>
3
- <head>
4
- <title>Sample</title>
5
- </head>
6
-
7
- <body>
8
-
9
- <%= yield %>
10
-
11
- </body>
12
-
13
- </html>
@@ -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
@@ -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.'
@@ -1,8 +0,0 @@
1
- Employee.all.each do |employee|
2
- generate(
3
- 'staff/_employee.html',
4
- File.join('staff', "#{employee.first.downcase}-#{employee.last.downcase}"),
5
- :first => employee.first,
6
- :last => employee.last
7
- )
8
- end
@@ -1 +0,0 @@
1
- h1, h2, h3, h4, h5, h6 {font-size: 100%;}
@@ -1,5 +0,0 @@
1
- $red: #f04040;
2
-
3
- body {
4
- h1 {color: $red;}
5
- }
@@ -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