trekky 0.0.7.rc3 → 0.0.7.rc4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1b9aec1a5d263db19517c2dbae4a6b8860c16fb
4
- data.tar.gz: eb8d218d698a83f6def8f82c8769c6151791a063
3
+ metadata.gz: 8a26adaa407a6fa2e89ea74733ceb53f4d8f3d47
4
+ data.tar.gz: bc6f465397df5c408d13a5b5104abfdd90730398
5
5
  SHA512:
6
- metadata.gz: 439ce4280105f0ce47a4e2aa070f9c23dacd60b1a768282c972930e9e29b2def2a49d1a45d7f61ccbde3c3d2701993070bda890fae311626155a86e932c4bf44
7
- data.tar.gz: fbcd0e90819f05fdde98d4f42ca404ad1b076d34c4c21feb3e317cc9e82cb547dd76f4384adb1841875a53d236045350a1395405c06c54c276ac06ce1b6a7276
6
+ metadata.gz: ff5ac2ce498134ce8930baf1e9d6367a3cc94131c7966c9cab18d2d6f9a1da84548166ef9c8568d5d2eff473af81aa1e2dd5330c37a0b4430d6fa9b67029cf17
7
+ data.tar.gz: 2912e3b48012184ef79b98c5bcff2f5c7459dbc238edb28ed2ad3416262e25df7575c0012133ddad5d72101f8492ff7f0abc4906d214bd27684d388a283b126e
data/bin/trekky CHANGED
@@ -16,6 +16,7 @@ Clap.run ARGV,
16
16
  exit
17
17
  }
18
18
 
19
+
19
20
  trekky = Trekky.new(source)
20
21
 
21
22
  unless daemon
data/lib/trekky.rb CHANGED
@@ -13,7 +13,9 @@ class Trekky
13
13
  end
14
14
 
15
15
  def render_to(target_dir)
16
- @context.sources.each do |source|
16
+ target_dir = Pathname.new(target_dir).expand_path
17
+
18
+ @context.each_source do |source|
17
19
  path = target_path(target_dir, source)
18
20
  output = source.render
19
21
  output = source.render_errors unless source.valid?
@@ -25,7 +27,7 @@ class Trekky
25
27
  private
26
28
 
27
29
  def target_path(target_dir, source)
28
- path = File.join(target_dir, source.path.gsub(@context.source_dir, ''))
30
+ path = File.join(target_dir, source.path.to_s.gsub(@context.source_dir.to_s, ''))
29
31
  if type = source.type
30
32
  path.gsub(/\.#{type}/, '')
31
33
  else
@@ -1,3 +1,4 @@
1
+ require 'pathname'
1
2
  require_relative 'data'
2
3
  require_relative 'haml_source'
3
4
  require_relative 'sass_source'
@@ -9,54 +10,77 @@ class Trekky
9
10
  attr_reader :source_dir
10
11
 
11
12
  def initialize(source_dir)
12
- @source_dir = source_dir
13
- @files = { layouts: [], partials: [], sources: [] }
14
- build
13
+ @source_dir = Pathname.new(source_dir).expand_path
15
14
  end
16
15
 
17
- def sources
18
- @files[:sources]
16
+ def each_source
17
+ files[:sources].each do |path|
18
+ yield build_source(path)
19
+ end
19
20
  end
20
21
 
21
22
  def partials
22
- @files[:partials]
23
+ files[:partials]
23
24
  end
24
25
 
25
26
  def layouts
26
- @files[:layouts]
27
+ files[:layouts]
27
28
  end
28
29
 
29
30
  def find_partial(name)
30
- partials.find {|p| p.path == File.join(source_dir, name)}
31
+ if partial = partials.find { |path| path == (source_dir + name) }
32
+ build_source(partial)
33
+ end
34
+ end
35
+
36
+ def find_layout(name)
37
+ layout = layouts.find do |path|
38
+ layout_path = source_dir + "layouts/#{name}"
39
+ path == layout_path
40
+ end
41
+
42
+ if layout
43
+ build_source(layout)
44
+ end
31
45
  end
32
46
 
33
47
  def data
34
48
  @data ||= Data.new(data_path)
35
49
  end
36
50
 
37
- private
38
-
39
- def build
40
- Dir.glob(File.join(source_dir, "**/*")).each do |path|
41
-
42
- next if File.directory?(path)
51
+ def layout
52
+ if path = layouts.first
53
+ build_source(path)
54
+ end
55
+ end
43
56
 
44
- source = build_source(path)
57
+ private
45
58
 
46
- if path.include?("#{source_dir}/layouts")
47
- @files[:layouts] << source
48
- next
49
- end
59
+ def files
60
+ @files ||= find_files
61
+ end
50
62
 
51
- if File.basename(path)[0] == '_'
52
- @files[:partials] << source
53
- next
63
+ def find_files
64
+ all_files = { layouts: [], partials: [], sources: [] }
65
+
66
+ paths.inject(all_files) do |hash, path|
67
+ unless path.directory?
68
+ if path.to_s.include?("#{source_dir}/layouts")
69
+ hash[:layouts].push(path)
70
+ elsif path.basename.to_s[0] == '_'
71
+ hash[:partials].push(path)
72
+ else
73
+ hash[:sources].push(path)
74
+ end
54
75
  end
55
-
56
- @files[:sources] << source
76
+ hash
57
77
  end
58
78
  end
59
79
 
80
+ def paths
81
+ Pathname.glob(source_dir + "**/*")
82
+ end
83
+
60
84
  def build_source(path)
61
85
  type = File.extname(path)[1..-1].intern
62
86
  find_source_class(type).new(self, path)
@@ -74,6 +98,5 @@ class Trekky
74
98
  File.join(Dir.pwd, 'data')
75
99
  end
76
100
 
77
-
78
101
  end
79
102
  end
@@ -55,11 +55,22 @@ class Trekky
55
55
  private
56
56
 
57
57
  def render_input(locals = {}, &block)
58
- Haml::Engine.new(input).render(self, locals, &block)
58
+ Haml::Engine.new(body).render(self, locals, &block)
59
59
  end
60
60
 
61
61
  def layout
62
- @context.layouts.first
62
+ name = header["layout"] || 'default.haml'
63
+ context.find_layout(name)
64
+ end
65
+
66
+ def read_file
67
+ regexp = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
68
+ content = File.read(path)
69
+ if m = regexp.match(content)
70
+ return YAML.load(m[0]), m.post_match
71
+ else
72
+ return {}, content
73
+ end
63
74
  end
64
75
 
65
76
  end
@@ -15,14 +15,14 @@ class Trekky
15
15
  def render
16
16
  clear_errors
17
17
  Sass.load_paths << @context.source_dir
18
- @output = Sass::Engine.new(input, options).render
18
+ @output = Sass::Engine.new(body, options).render
19
19
  rescue Exception => error
20
20
  add_error error
21
21
  end
22
22
 
23
23
  def render_error(error)
24
- input = error.message.to_s.gsub(HTML_ESCAPE_ONCE_REGEXP, HTML_ESCAPE)
25
- sprintf('body::before{ content:"%s" }', input)
24
+ text = error.message.to_s.gsub(HTML_ESCAPE_ONCE_REGEXP, HTML_ESCAPE)
25
+ sprintf('body::before{ content:"%s" }', text)
26
26
  end
27
27
 
28
28
  def options
data/lib/trekky/source.rb CHANGED
@@ -1,13 +1,17 @@
1
+ # encoding: UTF-8
2
+
1
3
  class Trekky
2
4
 
3
5
  class Source
4
6
 
5
7
  attr_reader :output, :context, :path, :errors
8
+ attr_reader :body, :header
6
9
 
7
10
  def initialize(context, path)
8
11
  @path = path
9
12
  @context = context
10
13
  @errors = []
14
+ read
11
15
  end
12
16
 
13
17
  def data
@@ -30,12 +34,12 @@ class Trekky
30
34
  File.extname(path)
31
35
  end
32
36
 
33
- def input
34
- File.read(path)
37
+ def read
38
+ @header, @body = read_file
35
39
  end
36
40
 
37
41
  def add_error(error)
38
- STDOUT.puts "ERROR: #{error.message} (#{path})"
42
+ STDOUT.puts "ERROR: #{error.message} (#{path}) -> #{error.backtrace.first}"
39
43
  @errors << error
40
44
  nil
41
45
  end
@@ -44,6 +48,10 @@ class Trekky
44
48
  @errors = []
45
49
  end
46
50
 
51
+ def read_file
52
+ return {}, File.read(path)
53
+ end
54
+
47
55
  def render_errors
48
56
  @errors.map do |error|
49
57
  render_error(error)
@@ -6,7 +6,7 @@ class Trekky
6
6
 
7
7
  def render
8
8
  clear_errors
9
- @output = input
9
+ @output = body
10
10
  end
11
11
 
12
12
  def type
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trekky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7.rc3
4
+ version: 0.0.7.rc4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Florio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-29 00:00:00.000000000 Z
11
+ date: 2014-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clap
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sass
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '3.3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: haml
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '4.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '4.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rb-fsevent
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0.9'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.9'
69
69
  description: Simple, very simple, sass and haml compiler.
@@ -93,17 +93,17 @@ require_paths:
93
93
  - lib
94
94
  required_ruby_version: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - '>='
96
+ - - ">="
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
99
  required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>'
101
+ - - ">"
102
102
  - !ruby/object:Gem::Version
103
103
  version: 1.3.1
104
104
  requirements: []
105
105
  rubyforge_project:
106
- rubygems_version: 2.0.14
106
+ rubygems_version: 2.2.2
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: Simple, very simple, sass and haml compiler for dear designer friend.