eggshell 0.8.1
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 +7 -0
- data/bin/eggshell +32 -0
- data/lib/eggshell/block-handler.rb +54 -0
- data/lib/eggshell/block.rb +51 -0
- data/lib/eggshell/bundles/basics.rb +854 -0
- data/lib/eggshell/bundles/loader.rb +57 -0
- data/lib/eggshell/bundles.rb +62 -0
- data/lib/eggshell/expression-evaluator.rb +862 -0
- data/lib/eggshell/macro-handler.rb +41 -0
- data/lib/eggshell/processor-context.rb +28 -0
- data/lib/eggshell.rb +758 -0
- metadata +55 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
# This bundle is used to interpret eggshell configs.
|
2
|
+
module Eggshell::Bundles::Loader
|
3
|
+
BUNDLE_ID = 'loader'
|
4
|
+
|
5
|
+
def self.new_instance(proc, opts = nil)
|
6
|
+
LoaderMacro.new.set_processor(proc)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.class_from_string(str)
|
10
|
+
str.split('::').inject(Object) do |mod, class_name|
|
11
|
+
mod.const_get(class_name)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class LoaderMacro
|
16
|
+
def set_processor(proc)
|
17
|
+
@proc = proc
|
18
|
+
proc.register_macro(self, *%w(gems files bundles vars))
|
19
|
+
end
|
20
|
+
|
21
|
+
def process(buffer, macname, args, lines, depth)
|
22
|
+
if macname == 'gems'
|
23
|
+
args.each do |gemname|
|
24
|
+
begin
|
25
|
+
require gemname
|
26
|
+
@proc._debug("_loaded gem: #{gemname}")
|
27
|
+
rescue LoadError
|
28
|
+
@proc._warn("could not load gem: #{gemname}")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
elsif macname == 'files'
|
32
|
+
args.each do |file|
|
33
|
+
begin
|
34
|
+
if file[0] == '/'
|
35
|
+
require file
|
36
|
+
else
|
37
|
+
@proc.vars[:target].vars[:include_paths].each do |root|
|
38
|
+
if File.exists?("#{root}/#{file}")
|
39
|
+
require "#{root}/#{file}"
|
40
|
+
@proc._debug("loaded file: #{root}/#{file}")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
rescue LoadError
|
45
|
+
@proc._warn("could not load file: #{file}")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
elsif macname == 'bundles'
|
49
|
+
args.each do |bundle|
|
50
|
+
Eggshell::Bundles::Registry.attach_bundle(bundle, @proc.vars[:target])
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
include Eggshell::Bundles::Bundle
|
57
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# Bundles allow macros and blocks to be bundled and initialized together. This
|
2
|
+
# makes it easy to create and distribute functionality, as well as configure
|
3
|
+
# automatic bundle loading within your own environment.
|
4
|
+
#
|
5
|
+
# The bundle [**must**] include the static method `new_instance(Eggshell::Processor proc, Hash opts = nil)`
|
6
|
+
#
|
7
|
+
# If the class has `BUNDLE_ID` defined, the bundle will be registered with that
|
8
|
+
# id, otherwise, it will use its class name.
|
9
|
+
module Eggshell::Bundles
|
10
|
+
|
11
|
+
# Helper module that automatically registers the bundle class extending it.
|
12
|
+
module Bundle
|
13
|
+
def self.included(clazz)
|
14
|
+
id = nil
|
15
|
+
if defined?(clazz::BUNDLE_ID)
|
16
|
+
id = clazz::BUNDLE_ID
|
17
|
+
else
|
18
|
+
id = clazz.to_s.gsub('::', '_').downcase
|
19
|
+
end
|
20
|
+
Registry.register_bundle(clazz, id)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Maintains central registry of bundles.
|
25
|
+
class Registry
|
26
|
+
@@reg = {}
|
27
|
+
|
28
|
+
def self.register_bundle(bundle, id)
|
29
|
+
if !bundle.respond_to?(:new_instance)
|
30
|
+
$stderr.write "registering bundle failed: #{bundle} does not have 'new_instance' method\n"
|
31
|
+
return
|
32
|
+
end
|
33
|
+
|
34
|
+
if !@@reg[id]
|
35
|
+
@@reg[id] = bundle
|
36
|
+
$stderr.write "registering bundle #{id} => #{bundle}\n"
|
37
|
+
else
|
38
|
+
$stderr.write "registering bundle failed: #{id} already registered\n"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.get_bundle(id)
|
43
|
+
return @@reg[id]
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.attach_bundle(id, proc)
|
47
|
+
bundle = @@reg[id]
|
48
|
+
if bundle
|
49
|
+
bundle.new_instance(proc)
|
50
|
+
else
|
51
|
+
$stderr.write "no bundle '#{id}'\n"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.unregister_bundle(id)
|
56
|
+
bundle = @@reg.delete(id)
|
57
|
+
$stderr.write "unregistered bundle #{id} => #{bundle}\n"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
require_relative './bundles/basics.rb'
|