fifty 0.1.2 → 0.1.3

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.
Files changed (2) hide show
  1. data/lib/fifty.rb +25 -4
  2. metadata +2 -2
data/lib/fifty.rb CHANGED
@@ -6,7 +6,7 @@ module Fifty
6
6
  require 'json'
7
7
 
8
8
  # Version of the gem.
9
- VERSION = '0.1.2'
9
+ VERSION = '0.1.3'
10
10
 
11
11
  # Class-level variables.
12
12
 
@@ -17,7 +17,7 @@ module Fifty
17
17
  attr_accessor :helpers
18
18
  # Hash of compiled shared data.
19
19
  attr_accessor :shareds
20
- # Hash of compiled partials
20
+ # Hash of HTML compiled partials
21
21
  attr_accessor :partials
22
22
  # Boolean - have we compiled?
23
23
  attr_accessor :compiled
@@ -27,6 +27,8 @@ module Fifty
27
27
  attr_accessor :logger
28
28
  # Handlebars runtime.
29
29
  attr_accessor :hbs
30
+ # Time last updated at.
31
+ attr_accessor :updated
30
32
  end
31
33
 
32
34
  # Default values for class variables.
@@ -35,6 +37,7 @@ module Fifty
35
37
  self.helpers = {}
36
38
  self.shareds = {}
37
39
  self.partials = {}
40
+ self.updated = {}
38
41
 
39
42
  self.logger = $stdout
40
43
  self.compiled = false
@@ -45,6 +48,7 @@ module Fifty
45
48
  # Handle missing Handlebars partials.
46
49
  # We don't register partials server-side.
47
50
  self.hbs.partial_missing do |name|
51
+ debug "Missing partial #{name}"
48
52
  hbs = Fifty.render_haml(name)
49
53
  Fifty.hbs2html(hbs, @@current)
50
54
  end
@@ -66,7 +70,7 @@ module Fifty
66
70
  # Output the helpers, the partials,
67
71
  # and the data inside script tags.
68
72
  def self.headers
69
- scripts = ['helpers', 'partials', 'shareds']
73
+ scripts = ['helpers', 'shareds']
70
74
  headers = ''
71
75
  scripts.each { |type| headers += header(type) }
72
76
  headers
@@ -112,10 +116,25 @@ module Fifty
112
116
  # Iterate over all template files
113
117
  # and compile each one to HBS.
114
118
  def self.compile_template_files
119
+ FileUtils.mkdir_p('./.hbs')
115
120
  get_template_files.each do |file|
121
+ updated[file] = File.mtime(file)
116
122
  compile_template_file(file)
117
123
  end
118
124
  end
125
+
126
+ def self.recompile_templates
127
+ FileUtils.mkdir_p('./.hbs')
128
+ recompiled = false
129
+ get_template_files.each do |file|
130
+ if File.mtime(file) != updated[file]
131
+ compile_template_file(file)
132
+ updated[file] = File.mtime(file)
133
+ recompiled = true
134
+ end
135
+ end
136
+ yield if recompiled
137
+ end
119
138
 
120
139
  # Compile a single HAML template
121
140
  # file to HTML with HBS.
@@ -123,6 +142,8 @@ module Fifty
123
142
  contents = File.read(file)
124
143
  partial = render_raw_haml(contents)
125
144
  name = path_to_name(file)
145
+ path = './.hbs/' + name.to_s + '.handlebars'
146
+ File.open(path, 'w+') { |f| f.write(partial) }
126
147
  template = escape_hbs(partial)
127
148
  reg = partial_registerer(name, template)
128
149
  partials[name] = reg
@@ -251,7 +272,7 @@ module Fifty
251
272
  end
252
273
  code
253
274
  end
254
-
275
+
255
276
  # Generates a Javascript script tag with inline code.
256
277
  def self.script_tag(id, code, type = 'text/javascript')
257
278
  "\n<script id='#{id}' type='#{type}'>#{code}</script>\n"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fifty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-27 00:00:00.000000000 Z
12
+ date: 2013-06-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json