deris 0.1.2
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.
- data/lib/deris.rb +2 -0
- data/lib/file.rb +42 -0
- data/lib/project.rb +61 -0
- metadata +84 -0
data/lib/deris.rb
ADDED
data/lib/file.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'haml'
|
4
|
+
|
5
|
+
module Deris
|
6
|
+
|
7
|
+
class File
|
8
|
+
|
9
|
+
attr_reader :name
|
10
|
+
|
11
|
+
def initialize(name = 'index', partials = {})
|
12
|
+
@name = name
|
13
|
+
@partials = partials
|
14
|
+
end
|
15
|
+
|
16
|
+
def write(directory)
|
17
|
+
output_path = ::File.join(directory, "#{@name}.html")
|
18
|
+
::File.open(output_path, 'w+') do |file|
|
19
|
+
file.write render
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def render(template = nil)
|
24
|
+
if template.nil?
|
25
|
+
template = @partials[:layout]
|
26
|
+
else
|
27
|
+
template = ::File.new(template).read if ::File.exist?(template)
|
28
|
+
end
|
29
|
+
haml_engine = Haml::Engine.new(template)
|
30
|
+
haml_engine.render(self)
|
31
|
+
end
|
32
|
+
|
33
|
+
def partial(template)
|
34
|
+
if template.is_a? Symbol
|
35
|
+
template = @partials[template] || ''
|
36
|
+
end
|
37
|
+
render(template)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/lib/project.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'fileutils'
|
3
|
+
require ::File.join(::File.dirname(__FILE__), 'file')
|
4
|
+
|
5
|
+
module Deris
|
6
|
+
|
7
|
+
class Project
|
8
|
+
|
9
|
+
def initialize(source)
|
10
|
+
@source = source
|
11
|
+
@source_directory = ::File.join(@source, '_src')
|
12
|
+
@defaults = partials_from @source_directory
|
13
|
+
end
|
14
|
+
|
15
|
+
def write(output)
|
16
|
+
# recreate the output directory
|
17
|
+
FileUtils.rm_rf(output) if ::File.exists?(output)
|
18
|
+
FileUtils.mkdir(output)
|
19
|
+
|
20
|
+
# find and copy all static content
|
21
|
+
static_content_mask = ::File.join(@source, "**")
|
22
|
+
static_content = Dir[static_content_mask].reject{|path| path =~ /_src$/}
|
23
|
+
static_content.each{|path| FileUtils.cp_r(path, output)}
|
24
|
+
|
25
|
+
# generate the index page from defaults
|
26
|
+
File.new('index', @defaults).write output
|
27
|
+
|
28
|
+
# generate the other pages of the site from sub-directories
|
29
|
+
source_directories.each do |dir|
|
30
|
+
partials = partials_from dir
|
31
|
+
partials = @defaults.merge(partials)
|
32
|
+
file_name = ::File.basename(dir)
|
33
|
+
File.new(file_name, partials).write output
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def source_directories
|
40
|
+
source_directory_mask = ::File.join(@source_directory, '*')
|
41
|
+
::Dir[source_directory_mask].find_all do |dir|
|
42
|
+
::File.directory?(dir)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def partials_from(directory)
|
47
|
+
partials = {}
|
48
|
+
partial_file_mask = ::File.join(directory, '*.haml')
|
49
|
+
partial_files = ::Dir.glob(partial_file_mask)
|
50
|
+
|
51
|
+
partial_files.each do |file|
|
52
|
+
file_sym = ::File.basename(file, '.haml').to_sym
|
53
|
+
partials[file_sym] = ::File.new(file).read
|
54
|
+
end
|
55
|
+
|
56
|
+
partials
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: deris
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Garry Shutler
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-06-07 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: haml
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 2
|
33
|
+
- 0
|
34
|
+
version: 2.2.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Simple documentation creation engine based on HAML
|
38
|
+
email: garry@robustsoftware.co.uk
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
files:
|
46
|
+
- lib/deris.rb
|
47
|
+
- lib/file.rb
|
48
|
+
- lib/project.rb
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: http://github.com/gshutler/deris
|
51
|
+
licenses: []
|
52
|
+
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options:
|
55
|
+
- --charset=UTF-8
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
hash: 3
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
requirements: []
|
77
|
+
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.3.7
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: Simple documentation creation engine based on HAML
|
83
|
+
test_files: []
|
84
|
+
|