emberprecompile 0.1.3 → 0.1.4
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/bin/emberprecompile +3 -0
- data/lib/emberprecompile.rb +3 -0
- data/lib/emberprecompile/compiler.rb +93 -13
- data/lib/emberprecompile/config.rb +44 -0
- data/lib/emberprecompile/version.rb +1 -1
- data/lib/emberprecompile/watcher.rb +33 -7
- metadata +4 -3
data/bin/emberprecompile
CHANGED
@@ -13,4 +13,7 @@ case command
|
|
13
13
|
puts Emberprecompile::Watcher.watch
|
14
14
|
when "COMPILE"
|
15
15
|
puts Emberprecompile::Compiler.compile
|
16
|
+
when "SETUP"
|
17
|
+
AppSettings = Emberprecompile::Config.setting
|
18
|
+
print "Pre Compilation project is setup. \n\nLook into config.rb file for setting up paths to handlebar files"
|
16
19
|
end
|
data/lib/emberprecompile.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require "emberprecompile/version"
|
2
2
|
require "emberprecompile/compiler"
|
3
3
|
require "emberprecompile/watcher"
|
4
|
+
require "emberprecompile/config"
|
4
5
|
|
5
6
|
module Emberprecompile
|
6
7
|
# Your code goes here...
|
8
|
+
CONFIG_FILE_PATH = ""
|
9
|
+
SETTINGS = Emberprecompile::Config.setting
|
7
10
|
end
|
@@ -1,28 +1,108 @@
|
|
1
1
|
require 'find'
|
2
2
|
require 'barber'
|
3
|
+
require 'fileutils'
|
3
4
|
|
4
5
|
module Emberprecompile
|
5
6
|
class Compiler
|
6
7
|
def self.compile
|
7
|
-
|
8
|
-
|
8
|
+
source = SETTINGS["handlebars_dir"]
|
9
|
+
file_ext = SETTINGS["handlebars_ext"]
|
10
|
+
|
11
|
+
# Iterating through all files under source to identify
|
12
|
+
Find.find(source) do |file|
|
13
|
+
self.compileFile(file)
|
14
|
+
end
|
15
|
+
|
16
|
+
print "\n"
|
17
|
+
self.combine
|
18
|
+
print "Pre-Compiled handlebars are ready for use....\n-------------------------------------------------------\n"
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.combine
|
22
|
+
cache_source = SETTINGS["_cache"]
|
23
|
+
file_ext = SETTINGS["handlebars_ext"] + ".cache"
|
24
|
+
output_dir = SETTINGS["output_dir"]
|
25
|
+
|
26
|
+
if(output_dir.rindex("/") == output_dir.length-1)
|
27
|
+
output_dir[output_dir.length - 1] = ""
|
28
|
+
end
|
29
|
+
|
30
|
+
if( !File.directory?(SETTINGS["output_dir"]) )
|
31
|
+
FileUtils.mkdir SETTINGS["output_dir"]
|
32
|
+
end
|
33
|
+
|
34
|
+
fileName = output_dir + "/" + SETTINGS["output_file"]
|
9
35
|
output = File.new(fileName, "w")
|
10
36
|
|
11
|
-
|
37
|
+
# Iterating through each file and writing to output file
|
38
|
+
Find.find(cache_source) do |file|
|
12
39
|
if !FileTest.directory?(file)
|
13
|
-
if(file.end_with?(
|
14
|
-
|
15
|
-
templateName = file.chomp(".handlebars")
|
16
|
-
templateName.slice!(source)
|
17
|
-
result = Barber::Ember::FilePrecompiler.call(File.read(file))
|
18
|
-
output.write('/* '+ templateName + ' Handlebar */')
|
19
|
-
output.write('Ember.TEMPLATES["' + templateName + '"] = ' + result + "\n")
|
20
|
-
print "\n"
|
40
|
+
if(file.end_with?(file_ext))
|
41
|
+
output.write(File.read(file))
|
21
42
|
end
|
22
43
|
end
|
23
44
|
end
|
24
|
-
|
25
|
-
print "Pre-Compiled handlebars are ready for use....\n-------------------------------------------------------\n"
|
45
|
+
output.close()
|
26
46
|
end
|
47
|
+
|
48
|
+
def self.compileFile(file)
|
49
|
+
source = SETTINGS["handlebars_dir"]
|
50
|
+
file_ext = SETTINGS["handlebars_ext"]
|
51
|
+
|
52
|
+
if !FileTest.directory?(file)
|
53
|
+
if(file.end_with?(file_ext))
|
54
|
+
print "Compiling "+file
|
55
|
+
|
56
|
+
# Extracting Template Name from file name
|
57
|
+
templateName = file.chomp(file_ext)
|
58
|
+
templateName.slice!(source)
|
59
|
+
|
60
|
+
# Creating a temporary file for the handlebar to save output
|
61
|
+
tempFile_Name = SETTINGS["_cache"] + templateName.slice(0, templateName.rindex("/"))
|
62
|
+
FileUtils.makedirs(tempFile_Name)
|
63
|
+
tempFile_Name = SETTINGS["_cache"] + templateName + file_ext + ".cache"
|
64
|
+
tempFile = File.new(tempFile_Name, "w")
|
65
|
+
|
66
|
+
if(templateName.index("/") == 0)
|
67
|
+
templateName[0] = ""
|
68
|
+
end
|
69
|
+
# Compiling Handlebar using Barber plugin
|
70
|
+
result = Barber::Ember::FilePrecompiler.call(File.read(file))
|
71
|
+
|
72
|
+
# Writing output to temporary file
|
73
|
+
tempFile.write('/* '+ templateName + ' Handlebar */')
|
74
|
+
tempFile.write('Ember.TEMPLATES["' + templateName + '"] = ' + result + "\n")
|
75
|
+
|
76
|
+
tempFile.close()
|
77
|
+
print "\n"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.deleteFile(file)
|
83
|
+
source = SETTINGS["handlebars_dir"]
|
84
|
+
cache_source = SETTINGS["_cache"]
|
85
|
+
folder = false
|
86
|
+
|
87
|
+
if FileTest.directory?(file)
|
88
|
+
folder = true
|
89
|
+
end
|
90
|
+
|
91
|
+
if(source.rindex("/") == source.length-1)
|
92
|
+
source[source.length - 1] = ""
|
93
|
+
end
|
94
|
+
|
95
|
+
file.slice!(source)
|
96
|
+
cache_file = cache_source + file
|
97
|
+
if folder
|
98
|
+
FileUtils.remove_dir(cache_file)
|
99
|
+
else
|
100
|
+
cache_file = cache_file + ".cache"
|
101
|
+
if File.exists?(cache_file)
|
102
|
+
FileUtils.rm(cache_file)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
27
107
|
end
|
28
108
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'fssm'
|
3
|
+
require 'find'
|
4
|
+
|
5
|
+
module Emberprecompile
|
6
|
+
class Config
|
7
|
+
def self.setting
|
8
|
+
fileName = "emberprecompile-config.rb"
|
9
|
+
settings = Hash.new
|
10
|
+
|
11
|
+
# Config file does not exist, So create a new file.
|
12
|
+
if(!File.exists?(fileName))
|
13
|
+
file = File.new(fileName, "w")
|
14
|
+
file.write("# Settings file to change the paths of handlebars \n# and compiled version of handlebars files \n\n")
|
15
|
+
file.write('handlebars_dir = "views"'+" # Path to Handlebars files \n")
|
16
|
+
file.write('handlebars_ext = ".handlebars"'+" # Handlebar files extension \n")
|
17
|
+
file.write('output_dir = "compiled"'+" # Path to compiled Handlebars output \n")
|
18
|
+
file.write('output_file = "views.handlebars.js"'+" # File name of output \n")
|
19
|
+
file.close()
|
20
|
+
end
|
21
|
+
|
22
|
+
# Read config settings from file.
|
23
|
+
file = File.read(fileName)
|
24
|
+
file.each_line do |line|
|
25
|
+
if(line.match(/^#/))
|
26
|
+
next
|
27
|
+
elsif(line.match(/^$/))
|
28
|
+
next
|
29
|
+
else
|
30
|
+
if(line["#"] != nil)
|
31
|
+
temp = line.strip.split("#")
|
32
|
+
line = temp.first.to_s.strip
|
33
|
+
end
|
34
|
+
if(line["="] != nil)
|
35
|
+
temp = line.strip.split("=")
|
36
|
+
settings[temp.first.to_s.strip] = temp.last.to_s.strip.tr('"', "")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
settings["_cache"] = "._cache"
|
41
|
+
return settings
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -4,23 +4,49 @@ require 'fssm'
|
|
4
4
|
module Emberprecompile
|
5
5
|
class Watcher
|
6
6
|
def self.watch
|
7
|
-
source = "
|
7
|
+
source = SETTINGS["handlebars_dir"]
|
8
|
+
|
9
|
+
if !File.directory?(SETTINGS["_cache"])
|
10
|
+
Emberprecompile::Compiler.compile
|
11
|
+
end
|
12
|
+
|
13
|
+
print "Monitoring for changes in handlebar files in '" + SETTINGS["handlebars_dir"] + "' folder. Press Ctrl + C to stop it."
|
14
|
+
|
8
15
|
FSSM.monitor(source) do
|
9
16
|
update do |b, r|
|
10
|
-
print "Change detected in >>>> " + r + "\n
|
11
|
-
Emberprecompile::
|
17
|
+
print "Change detected in >>>> " + r + "\n >>> "
|
18
|
+
path_update = Emberprecompile::Watcher.getfilepath(b, r)
|
19
|
+
Emberprecompile::Compiler.compileFile(path_update)
|
20
|
+
Emberprecompile::Compiler.combine
|
21
|
+
print "\n"
|
12
22
|
end
|
13
23
|
|
14
24
|
create do |b, r|
|
15
|
-
print "Created >>>> " + r + "\n
|
16
|
-
Emberprecompile::
|
25
|
+
print "Created >>>> " + r + "\n >>>>>> "
|
26
|
+
path_update = Emberprecompile::Watcher.getfilepath(b, r)
|
27
|
+
Emberprecompile::Compiler.compileFile(path_update)
|
28
|
+
Emberprecompile::Compiler.combine
|
29
|
+
print "\n"
|
17
30
|
end
|
18
31
|
|
19
32
|
delete do |b, r|
|
20
|
-
print "Deleted >>>> " + r + "\n
|
21
|
-
Emberprecompile::
|
33
|
+
print "Deleted >>>> " + r + "\n"
|
34
|
+
path_update = Emberprecompile::Watcher.getfilepath(b, r)
|
35
|
+
Emberprecompile::Compiler.deleteFile(path_update)
|
36
|
+
Emberprecompile::Compiler.combine
|
37
|
+
print "\n"
|
22
38
|
end
|
23
39
|
end
|
24
40
|
end
|
41
|
+
|
42
|
+
def self.getfilepath(working_path, file_path)
|
43
|
+
working_dir = Dir.pwd
|
44
|
+
working_path.slice!(working_dir)
|
45
|
+
if(working_path.index("/") == 0)
|
46
|
+
working_path[0] = ""
|
47
|
+
end
|
48
|
+
return working_path + "/" + file_path
|
49
|
+
end
|
50
|
+
|
25
51
|
end
|
26
52
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emberprecompile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
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-06
|
12
|
+
date: 2013-07-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: barber
|
@@ -67,13 +67,14 @@ executables:
|
|
67
67
|
extensions: []
|
68
68
|
extra_rdoc_files: []
|
69
69
|
files:
|
70
|
-
- emberprecompile-0.1.
|
70
|
+
- emberprecompile-0.1.4.gem
|
71
71
|
- emberprecompile.gemspec
|
72
72
|
- Gemfile
|
73
73
|
- LICENSE.txt
|
74
74
|
- Rakefile
|
75
75
|
- README.md
|
76
76
|
- lib/emberprecompile/compiler.rb
|
77
|
+
- lib/emberprecompile/config.rb
|
77
78
|
- lib/emberprecompile/version.rb
|
78
79
|
- lib/emberprecompile/watcher.rb
|
79
80
|
- lib/emberprecompile.rb
|