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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ichiban
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-04 00:00:00.000000000Z
12
+ date: 2012-11-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: activesupport
16
- requirement: &2157055820 !ruby/object:Gem::Requirement
15
+ name: erubis
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2157055820
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
- name: erubis
27
- requirement: &2157055400 !ruby/object:Gem::Requirement
31
+ name: sass
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *2157055400
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
- name: maruku
38
- requirement: &2157054980 !ruby/object:Gem::Requirement
47
+ name: listen
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,72 +53,114 @@ dependencies:
43
53
  version: '0'
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *2157054980
47
- description: The most elegant way to compile static websites
48
- email:
49
- - jarrettcolby@gmail.com
50
- executables:
51
- - ichiban.rb
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: activesupport
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: mocha
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: turn
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: lorax
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Static website compiler with advanced feature, including watcher script.
127
+ email: jarrett@madebyhq.com
128
+ executables: []
52
129
  extensions: []
53
130
  extra_rdoc_files: []
54
131
  files:
55
- - .gitignore
56
- - Gemfile
57
- - README
58
- - bin/ichiban.rb
59
- - ichiban.gemspec
60
- - klass.rb
61
- - lib/ichiban.rb
62
132
  - lib/ichiban/command.rb
63
- - lib/ichiban/compilation.rb
64
133
  - lib/ichiban/config.rb
65
- - lib/ichiban/erb_page.rb
66
- - lib/ichiban/files.rb
134
+ - lib/ichiban/deleter.rb
135
+ - lib/ichiban/dependencies.rb
136
+ - lib/ichiban/file.rb
67
137
  - lib/ichiban/helpers.rb
68
- - lib/ichiban/layouts.rb
69
- - lib/ichiban/loading.rb
138
+ - lib/ichiban/html_compiler.rb
70
139
  - lib/ichiban/logger.rb
71
- - lib/ichiban/mapping.rb
72
- - lib/ichiban/path.rb
73
- - lib/ichiban/script_runner.rb
74
- - lib/ichiban/tasks.rb
75
- - lib/ichiban/version.rb
140
+ - lib/ichiban/markdown.rb
76
141
  - lib/ichiban/watcher.rb
77
- - sample/Rakefile
78
- - sample/compiled/about.html
79
- - sample/compiled/bad.html
80
- - sample/compiled/images/check.png
81
- - sample/compiled/index.html
82
- - sample/compiled/javascripts/interaction.js
83
- - sample/compiled/staff/_employee.html
84
- - sample/compiled/staff/andre-marques.html
85
- - sample/compiled/staff/index.html
86
- - sample/compiled/staff/jarrett-colby.html
87
- - sample/compiled/stylesheets/reset.css
88
- - sample/compiled/stylesheets/screen.css
89
- - sample/config.rb
90
- - sample/content/about.html
91
- - sample/content/bad.html
92
- - sample/content/index.html
93
- - sample/content/staff/_employee.html
94
- - sample/content/staff/index.html
95
- - sample/data/employees.csv
96
- - sample/errors/404.html
97
- - sample/helpers/staff_helper.rb
98
- - sample/images/check.png
99
- - sample/javascripts/interaction.js
100
- - sample/layouts/default.html
101
- - sample/models/employee.rb
102
- - sample/scripts/bad.rb
103
- - sample/scripts/staff.rb
104
- - sample/stylesheets/reset.css
105
- - sample/stylesheets/screen.scss
106
- - spec/integration_spec.rb
107
- - spec/path_spec.rb
108
- - spec/spec_helper.rb
109
- homepage: ''
142
+ - lib/ichiban.rb
143
+ homepage: https://github.com/jarrett/ichiban
110
144
  licenses: []
111
- post_install_message:
145
+ post_install_message: ! 'Ichiban was installed successfully.
146
+
147
+ Type `ichiban` for usage hints.
148
+
149
+
150
+ If you intend to use Markdown in your projects,
151
+
152
+ be sure to install one of these Markdown gems:
153
+
154
+ redcarpet
155
+
156
+ maruku
157
+
158
+ rdiscount
159
+
160
+
161
+ For more information:
162
+
163
+ https://github.com/jarrett/ichiban'
112
164
  rdoc_options: []
113
165
  require_paths:
114
166
  - lib
@@ -125,12 +177,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
177
  - !ruby/object:Gem::Version
126
178
  version: '0'
127
179
  requirements: []
128
- rubyforge_project: ichiban
129
- rubygems_version: 1.8.11
180
+ rubyforge_project:
181
+ rubygems_version: 1.8.24
130
182
  signing_key:
131
183
  specification_version: 3
132
- summary: Static website compiler
133
- test_files:
134
- - spec/integration_spec.rb
135
- - spec/path_spec.rb
136
- - spec/spec_helper.rb
184
+ summary: Ichiban
185
+ test_files: []
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- pkg/*
2
- *.gem
3
- .bundle
4
- .sass-cache
5
- .sass-cache/**/*
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in ichiban.gemspec
4
- gemspec
data/README DELETED
@@ -1,56 +0,0 @@
1
- To use, create a folder for your project. Populate it with the appropriate folders. Create a Rakefile and add this:
2
-
3
- require 'ichiban'
4
- Ichiban::Tasks.new.define
5
-
6
- Overall design
7
- ==============
8
-
9
- The Rakefile should have as little in it as possible.
10
-
11
- Each individual bit of functionality should be separate and self-sufficient, although they can all depend on a configured project.
12
-
13
- For each of the following:
14
-
15
- - Content file
16
- - Stylesheet
17
- - JS
18
- - Image
19
-
20
- ...do each of these:
21
-
22
- - Compile/copy one
23
- - List all
24
- - List stale
25
- - Compile/copy all
26
- - Compile/copy stale
27
-
28
- Listing is done in files.rb. Compiling is done in compilation.rb.
29
-
30
- Further:
31
-
32
- - List all data files
33
- - Run scripts
34
-
35
- The compilation logger needs to be accessible from everywhere so that generators etc. can get to it.
36
-
37
- The watcher should delete files in the compiled directory when they're no longer needed. This can't be automatically determined for files based on scripts.
38
-
39
- The watcher should use the fork process described here:
40
-
41
- http://rkh.im/code-reloading
42
-
43
- Initially, the watcher forks. Both the parent and child process watch for changes, but they respond differently. The parent's only job is to kill the
44
- child and refork upon changes to models, scripts, and helpers. The child's job is to compile.
45
-
46
- Scripts should have an optional dependencies block:
47
-
48
- dependencies('data/employees.csv', 'data/stores.csv') do
49
- # Generate calls go here
50
- end
51
-
52
- This will cause the block to run only when employees.csv or stores.csv has changed. Since there's no way to infer the output file paths,
53
- we need to simply keep track of when the script was last run. Then, if any of the dependencies have changed after that, we re-run the script.
54
- To track this, we'll store a JSON hash in scripts/.last_runs
55
-
56
- {'employees.rb': 1316041807}
data/bin/ichiban.rb DELETED
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'ichiban'
5
-
6
- Ichiban::Command.new(ARGV).run
data/ichiban.gemspec DELETED
@@ -1,25 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "ichiban/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "ichiban"
7
- s.version = Ichiban::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ["Jarrett Colby"]
10
- s.email = ["jarrettcolby@gmail.com"]
11
- s.homepage = ""
12
- s.summary = %q{Static website compiler}
13
- s.description = %q{The most elegant way to compile static websites}
14
-
15
- s.rubyforge_project = "ichiban"
16
-
17
- s.add_dependency 'activesupport'
18
- s.add_dependency 'erubis'
19
- s.add_dependency 'maruku'
20
-
21
- s.files = `git ls-files`.split("\n")
22
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
- s.require_paths = ["lib"]
25
- end
data/klass.rb DELETED
@@ -1,7 +0,0 @@
1
-
2
- class Foo
3
- def bar
4
- puts 'bar'
5
- end
6
- end
7
-
@@ -1,93 +0,0 @@
1
- module Ichiban
2
- class Compiler
3
- include Layouts
4
-
5
- # This should not be called from the watcher. The watcher should have a more fine-grained way of looking at changed files.
6
- def compile
7
- load_all_ruby_files
8
- compile_stale
9
- run_scripts
10
- end
11
-
12
- # Includes, content, images, etc
13
- def compile_all
14
- content_files.each { |path| compile_content_file(path) }
15
- javascripts.each { |path| copy_javascript(path) }
16
- images.each { |path| copy_image(path) }
17
- stylesheets.each { |path| copy_or_compile_stylesheet(path) }
18
- end
19
-
20
- def compile_content_file(src_path)
21
- dest_path = content_dest(src_path)
22
- FileUtils.mkdir_p File.dirname(dest_path.abs)
23
- File.open(dest_path.replace_ext('html').abs, 'w') do |f|
24
- begin
25
- f.write(compile_content_file_to_string(src_path))
26
- rescue Exception => exc
27
- Ichiban.logger.exception(exc)
28
- end
29
- end
30
- end
31
-
32
- def compile_content_file_to_string(src_path)
33
- erb_context = ErbPage::Context.new(:_current_path => content_dest(src_path).web)
34
- result = ErbPage.new(File.read(src_path.abs), :filename => src_path.abs).evaluate(erb_context)
35
- result = case src_path.ext
36
- when 'markdown'
37
- Maruku.new(result).to_html
38
- when 'html'
39
- result
40
- else
41
- raise "compile_file_to_string doesn't know how to handle #{src_path.abs}"
42
- end
43
- wrap_in_layouts(erb_context, result)
44
- end
45
-
46
- # Includes, content, images, etc
47
- def compile_stale
48
- stale_content_files.each { |path| compile_content_file(path) }
49
- stale_javascripts.each { |path| copy_js(path) }
50
- stale_images.each { |path| copy_image(path) }
51
- stale_stylesheets.each { |path| copy_or_compile_stylesheet(path) }
52
- end
53
-
54
- def copy_image(path)
55
- dest = image_dest(path)
56
- FileUtils.mkdir_p(dest.dirname)
57
- FileUtils.cp(path.abs, dest.abs)
58
- end
59
-
60
- def copy_javascript(path)
61
- dest = javascript_dest(path)
62
- FileUtils.mkdir_p(dest.dirname)
63
- FileUtils.cp(path.abs, dest.abs)
64
- end
65
-
66
- def copy_or_compile_stylesheet(path)
67
- dest = stylesheet_dest(path)
68
- case path.ext
69
- when 'css'
70
- FileUtils.mkdir_p(dest.dirname)
71
- FileUtils.cp(path.abs, dest.abs)
72
- when 'scss', 'sass'
73
- Sass.compile_file(path.abs, dest.abs, :style => :compressed)
74
- end
75
- end
76
-
77
- def fresh
78
- load_all_ruby_files
79
- compile_all
80
- run_scripts
81
- end
82
-
83
- def run_scripts
84
- scripts.each do |path|
85
- begin
86
- ScriptRunner.run_script_file(path)
87
- rescue Exception => exc
88
- Ichiban.logger.exception(exc)
89
- end
90
- end
91
- end
92
- end
93
- end
@@ -1,16 +0,0 @@
1
- module Ichiban
2
- class ErbPage < Erubis::Eruby
3
- def add_preamble(src)
4
- src << "@_erb_out = _buf = '';"
5
- end
6
-
7
- class Context < Erubis::Context
8
- include ::Ichiban::Helpers
9
- include ::Erubis::XmlHelper
10
-
11
- def layout_stack
12
- @_layout_stack or ['default']
13
- end
14
- end
15
- end
16
- end
data/lib/ichiban/files.rb DELETED
@@ -1,105 +0,0 @@
1
- =begin
2
- - Content file
3
- - Stylesheet
4
- - JS
5
- - Image
6
-
7
- ...do each of these:
8
-
9
- - Compile/copy one
10
- - List all
11
- - List stale
12
- - Compile/copy all
13
- - Compile/copy stale
14
- =end
15
-
16
- module Ichiban
17
- class Compiler
18
- def content_files
19
- paths_in('content').reject { |path| path.directory? }
20
- end
21
-
22
- def data_files
23
- paths_in 'data'
24
- end
25
-
26
- def helpers
27
- paths_in 'helpers', 'rb'
28
- end
29
-
30
- def images
31
- paths_in 'images'
32
- end
33
-
34
- def models
35
- paths_in 'models', 'rb'
36
- end
37
-
38
- # Returns all stylesheet except for those beginning with an underscore
39
- def stylesheets
40
- paths_in('stylesheets').reject { |path| path.filename.start_with?('_') }
41
- end
42
-
43
- def javascripts
44
- paths_in 'javascripts', 'js'
45
- end
46
-
47
- def scripts
48
- paths_in 'scripts', 'rb'
49
- end
50
-
51
- # For the stale methods, we rely on the source-destination mapping as provided by mapping.rb.
52
-
53
- def stale_content_files
54
- stale(content_files) do |src_path|
55
- content_dest(src_path)
56
- end
57
- end
58
-
59
- def stale_images
60
- stale(images) do |src_path|
61
- image_dest(src_path)
62
- end
63
- end
64
-
65
- def stale_stylesheets
66
- stale(stylesheets) do |src_path|
67
- stylesheet_dest(src_path)
68
- end
69
- end
70
-
71
- def stale_javascripts
72
- stale(javascripts) do |src_path|
73
- javascript_dest(src_path)
74
- end
75
- end
76
-
77
- private
78
-
79
- def paths_in(dir, ext = nil)
80
- pattern = ext ? "**/*.#{ext}" : '**/*'
81
- Dir.glob(File.join(Ichiban.project_root, dir, pattern)).collect { |abs| Path.new abs }
82
- end
83
-
84
- # This method accepts a block. The block will be passed a source file path and must return either a destination path or an array thereof.
85
- def stale(source_paths)
86
- source_paths.reject do |path|
87
- dest = yield(path)
88
- dest = [dest] unless dest.is_a?(Array)
89
- up_to_date?(path, *dest)
90
- end
91
- end
92
-
93
- # Accepts one source file and one or more destination files. Pass in Path objects.
94
- # Note that this method is different from the one in FileUtils: The FileUtils version accepts
95
- # one destination and multiple sources.
96
- def up_to_date?(src, *dests)
97
- src_time = File.mtime(src.abs)
98
- dests.each do |dest|
99
- return false if !File.exists?(dest.abs)
100
- return false unless File.mtime(dest.abs) > src_time
101
- end
102
- true
103
- end
104
- end
105
- end
@@ -1,10 +0,0 @@
1
- module Ichiban
2
- module Layouts
3
- def wrap_in_layouts(erb_context, html)
4
- erb_context.layout_stack.reverse.inject(html) do |html, layout_name|
5
- layout_path = Path.new(File.join(Ichiban.project_root, 'layouts', layout_name + '.html'))
6
- ErbPage.new(File.read(layout_path.abs), :filename => layout_path.abs).evaluate(erb_context) { html }
7
- end
8
- end
9
- end
10
- end
@@ -1,19 +0,0 @@
1
- module Ichiban
2
- class Compiler
3
- def load_all_ruby_files
4
- models.each { |path| load path.abs }
5
- helpers.each { |path| load_helper path }
6
- end
7
-
8
- def load_helper(path)
9
- load path.abs
10
- mod_name = path.filename_without_ext.classify
11
- begin
12
- mod = Object.const_get(mod_name)
13
- rescue NameError
14
- raise "Expected #{path.abs} to define module #{classname}"
15
- end
16
- ErbPage::Context.send(:include, mod)
17
- end
18
- end
19
- end
@@ -1,38 +0,0 @@
1
- module Ichiban
2
- class Compiler
3
- def content_dest(src_path)
4
- if src_path.ext == 'markdown'
5
- src_path = src_path.replace_ext('html')
6
- end
7
- Path.new(
8
- File.join(Ichiban.project_root, 'compiled',
9
- src_path.relative_from('content')
10
- )
11
- )
12
- end
13
-
14
- def image_dest(src_path)
15
- Path.new(
16
- File.join(Ichiban.project_root, 'compiled', 'images',
17
- src_path.relative_from('images')
18
- )
19
- )
20
- end
21
-
22
- def javascript_dest(src_path)
23
- Path.new(
24
- File.join(Ichiban.project_root, 'compiled', 'javascripts',
25
- src_path.relative_from('javascripts')
26
- )
27
- )
28
- end
29
-
30
- def stylesheet_dest(src_path)
31
- Path.new(
32
- File.join(Ichiban.project_root, 'compiled', 'stylesheets',
33
- src_path.relative_from('stylesheets')
34
- )
35
- ).replace_ext('css')
36
- end
37
- end
38
- end
data/lib/ichiban/path.rb DELETED
@@ -1,55 +0,0 @@
1
- # A Path object is a wrapper around an absolute path.
2
-
3
- class Path
4
- attr_reader :abs
5
-
6
- def directory?
7
- File.directory?(abs)
8
- end
9
-
10
- def dirname
11
- File.dirname(abs)
12
- end
13
-
14
- def ext
15
- File.extname(abs).slice(1..-1)
16
- end
17
-
18
- def filename
19
- File.basename(abs)
20
- end
21
-
22
- def filename_without_ext
23
- File.basename(abs, File.extname(abs))
24
- end
25
-
26
- def initialize(abs)
27
- @abs = abs
28
- end
29
-
30
- # Returns a string relative to the given folder
31
- def relative_from(folder_in_project_root)
32
- prefix = File.join(Ichiban.project_root, folder_in_project_root)
33
- raise(ArgumentError, "#{abs} does not start with #{prefix}") unless abs.start_with?(prefix)
34
- abs.slice(prefix.length..-1)
35
- end
36
-
37
- def replace_ext(new_ext)
38
- self.class.new(abs.sub(/\..+$/, '.' + new_ext))
39
- end
40
-
41
- # Only meaningful for paths in the compiled directory. Returns a string representing the path from the web root.
42
- # Assumes Ichiban's standard URL rewriting rules are in effect.
43
- def web
44
- web_path = relative_from('compiled')
45
- if web_path.end_with?('.html')
46
- if web_path.end_with?('index.html')
47
- web_path.slice(0..-11) # Slice index.html off the end
48
- else
49
- web_path.slice(0..-6) + '/' # Slice .html off the end and add the trailing slash
50
- end
51
- else
52
- web_path
53
- end
54
- end
55
- end