trekky 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +47 -0
- data/lib/trekky.rb +40 -0
- data/lib/trekky/context.rb +69 -0
- data/lib/trekky/haml_source.rb +73 -0
- data/lib/trekky/sass_source.rb +16 -0
- data/lib/trekky/source.rb +35 -0
- data/lib/trekky/static_source.rb +16 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3f105a140b63b188cb68c6d4bd8f6cf2f77a7ce
|
4
|
+
data.tar.gz: e8b9ed82a66008e8c6ef344dd53335961cfa24b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 625341b4f4f9927a389ddb718484ff1131e999217573e7a9a435a0fae1f5c3097d2c2d1192613da7929b8c3f4ea422b3d499cda86df32e37c8601bd701b11aa9
|
7
|
+
data.tar.gz: c9083da525505bb422fddda8f777c12d38f54de49940fc2c06fe9a52009302e7e4412092780547f2f001030f23164e0e578e2b5eee689b9982d1d2e239c07318
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
trekky
|
2
|
+
======
|
3
|
+
|
4
|
+
Simple, very simple, sass and haml compiler for dear designer friend.
|
5
|
+
|
6
|
+
## Features
|
7
|
+
|
8
|
+
Say you have a file structure like this:
|
9
|
+
|
10
|
+
source
|
11
|
+
├── images
|
12
|
+
│ └── image.jpg
|
13
|
+
├── index.html.haml
|
14
|
+
├── javascripts
|
15
|
+
│ └── app.js
|
16
|
+
├── layouts
|
17
|
+
│ └── default.haml
|
18
|
+
└── stylesheets
|
19
|
+
└── hola.css.sass
|
20
|
+
|
21
|
+
And you run:
|
22
|
+
|
23
|
+
trekky -s source -t public
|
24
|
+
|
25
|
+
You'll end up having this:
|
26
|
+
|
27
|
+
public
|
28
|
+
├── images
|
29
|
+
│ └── image.jpg
|
30
|
+
├── index.html
|
31
|
+
├── javascripts
|
32
|
+
│ └── app.js
|
33
|
+
└── stylesheets
|
34
|
+
└── hola.css
|
35
|
+
|
36
|
+
## HELP
|
37
|
+
|
38
|
+
trekky -h
|
39
|
+
usage: trekky [-h] [-s source] [-t target]
|
40
|
+
|
41
|
+
|
42
|
+
## Deamon mode
|
43
|
+
|
44
|
+
Monitors source dir for changes, and copy/process on demand to target dir.
|
45
|
+
|
46
|
+
trekky -d
|
47
|
+
|
data/lib/trekky.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'trekky/context'
|
3
|
+
|
4
|
+
class Trekky
|
5
|
+
|
6
|
+
def initialize(source_dir)
|
7
|
+
@context = Context.new(source_dir)
|
8
|
+
end
|
9
|
+
|
10
|
+
def render_to(target_dir)
|
11
|
+
@context.sources.each do |source|
|
12
|
+
output = source.render
|
13
|
+
path = target_path(target_dir, source)
|
14
|
+
|
15
|
+
STDOUT.puts "Writing #{source.path} to #{path}"
|
16
|
+
write(output, path)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def target_path(target_dir, source)
|
23
|
+
path = File.join(target_dir, source.path.gsub(source_dir, ''))
|
24
|
+
if type = source.type
|
25
|
+
path.gsub(/\.#{type}/, '')
|
26
|
+
else
|
27
|
+
path
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def write(output, path)
|
32
|
+
FileUtils.mkdir_p(File.dirname(path))
|
33
|
+
File.open(path, "wb") {|f| f.write(output) }
|
34
|
+
end
|
35
|
+
|
36
|
+
def source_dir
|
37
|
+
@context.source_dir
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'trekky/haml_source'
|
2
|
+
require 'trekky/static_source'
|
3
|
+
require 'trekky/sass_source'
|
4
|
+
|
5
|
+
class Trekky
|
6
|
+
class Context
|
7
|
+
|
8
|
+
attr_reader :source_dir
|
9
|
+
|
10
|
+
def initialize(source_dir)
|
11
|
+
@source_dir = source_dir
|
12
|
+
@files = { layouts: [], partials: [], sources: [] }
|
13
|
+
build
|
14
|
+
end
|
15
|
+
|
16
|
+
def sources
|
17
|
+
@files[:sources]
|
18
|
+
end
|
19
|
+
|
20
|
+
def partials
|
21
|
+
@files[:partials]
|
22
|
+
end
|
23
|
+
|
24
|
+
def layouts
|
25
|
+
@files[:layouts]
|
26
|
+
end
|
27
|
+
|
28
|
+
def find_partial(name)
|
29
|
+
partials.find {|p| p.path == File.join(source_dir, name)}
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def build
|
35
|
+
Dir.glob(File.join(source_dir, "**/*")).each do |path|
|
36
|
+
|
37
|
+
next if File.directory?(path)
|
38
|
+
|
39
|
+
source = build_source(path)
|
40
|
+
|
41
|
+
if path.include?("#{source_dir}/layouts")
|
42
|
+
@files[:layouts] << source
|
43
|
+
next
|
44
|
+
end
|
45
|
+
|
46
|
+
if File.basename(path)[0] == '_'
|
47
|
+
@files[:partials] << source
|
48
|
+
next
|
49
|
+
end
|
50
|
+
|
51
|
+
@files[:sources] << source
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def build_source(path)
|
56
|
+
type = File.extname(path)[1..-1].intern
|
57
|
+
find_source_class(type).new(self, path)
|
58
|
+
end
|
59
|
+
|
60
|
+
def find_source_class(type)
|
61
|
+
types[type] || StaticSource
|
62
|
+
end
|
63
|
+
|
64
|
+
def types
|
65
|
+
{ sass: SassSource, haml: HamlSource }
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'haml'
|
2
|
+
require 'trekky/source'
|
3
|
+
|
4
|
+
class Trekky
|
5
|
+
class HamlSource < Source
|
6
|
+
|
7
|
+
attr_reader :regions
|
8
|
+
|
9
|
+
def initialize(context, path)
|
10
|
+
super
|
11
|
+
@regions = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def render(options = {}, &block)
|
15
|
+
if block_given? || options[:layout] == false
|
16
|
+
render_input(&block)
|
17
|
+
else
|
18
|
+
output = render_input
|
19
|
+
layout.render do |name|
|
20
|
+
if regions.has_key?(name)
|
21
|
+
regions[name]
|
22
|
+
else
|
23
|
+
output
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
rescue Exception => error
|
28
|
+
render_error(error)
|
29
|
+
end
|
30
|
+
|
31
|
+
def partial(name)
|
32
|
+
source = context.find_partial(name)
|
33
|
+
if source
|
34
|
+
source.render(layout: false)
|
35
|
+
else
|
36
|
+
STDERR.puts "[ERROR] Can't find partial: #{name}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def content_for(name, &block)
|
41
|
+
return unless block_given?
|
42
|
+
regions[name] = capture_haml(&block)
|
43
|
+
end
|
44
|
+
|
45
|
+
def type
|
46
|
+
:haml
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def render_input(&block)
|
52
|
+
Haml::Engine.new(input).render(self, locals, &block)
|
53
|
+
end
|
54
|
+
|
55
|
+
def locals
|
56
|
+
{}
|
57
|
+
end
|
58
|
+
|
59
|
+
def layout
|
60
|
+
@context.layouts.first
|
61
|
+
end
|
62
|
+
|
63
|
+
def render_error(e)
|
64
|
+
STDERR.puts "Error #{e.message}"
|
65
|
+
e.backtrace.each do |line|
|
66
|
+
STDERR.puts " #{line}"
|
67
|
+
end
|
68
|
+
nil
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Trekky
|
2
|
+
|
3
|
+
class Source
|
4
|
+
|
5
|
+
def initialize(context, path)
|
6
|
+
@path = path
|
7
|
+
@context = context
|
8
|
+
end
|
9
|
+
|
10
|
+
def render(&block)
|
11
|
+
raise NotImplementedError
|
12
|
+
end
|
13
|
+
|
14
|
+
def path
|
15
|
+
@path
|
16
|
+
end
|
17
|
+
|
18
|
+
def context
|
19
|
+
@context
|
20
|
+
end
|
21
|
+
|
22
|
+
def type
|
23
|
+
extension[1..-1].intern
|
24
|
+
end
|
25
|
+
|
26
|
+
def extension
|
27
|
+
File.extname(path)
|
28
|
+
end
|
29
|
+
|
30
|
+
def input
|
31
|
+
File.read(path)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trekky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Florio
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '4.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rb-fsevent
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
@@ -74,7 +74,14 @@ executables:
|
|
74
74
|
extensions: []
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
|
+
- README.md
|
77
78
|
- bin/trekky
|
79
|
+
- lib/trekky.rb
|
80
|
+
- lib/trekky/context.rb
|
81
|
+
- lib/trekky/haml_source.rb
|
82
|
+
- lib/trekky/sass_source.rb
|
83
|
+
- lib/trekky/source.rb
|
84
|
+
- lib/trekky/static_source.rb
|
78
85
|
homepage: http://github.com/lucasefe/trekky
|
79
86
|
licenses:
|
80
87
|
- MIT
|