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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8d381930fd686eeb75503e121d00b86720a29440
4
+ data.tar.gz: edd613b6221cf1af94b7253698191181ee3b0ed6
5
+ SHA512:
6
+ metadata.gz: fa442f2e0bb011ff8e70c437b6953f5861a200124509dc82bf77faa1c6c0205bff900cad37cd02569cb1738b99a3875055a7e896c78944b9af4d4fb2018a62c6
7
+ data.tar.gz: 63d4368671e260d6a9a4a126bd6d32a15aa7e79d678f8fce9799efadbb06fed7af020c56c2fd2e2e67d9f7f21393cc2ebc1b547679c13e3372bfdd6699693e26
data/bin/eggshell ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/ruby
2
+ require_relative '../lib/eggshell.rb'
3
+
4
+ f = ARGV[0]
5
+ if !f || !File.exists?(f)
6
+ puts "Invalid file: #{f}"
7
+ exit
8
+ end
9
+
10
+ file_dir = File.realdirpath(File.dirname(f))
11
+ $eggshell = Eggshell::Processor.new
12
+ $eggshell.vars[:include_paths] << file_dir
13
+ Eggshell::Bundles::Registry.attach_bundle('basics', $eggshell)
14
+
15
+ require_relative '../lib/eggshell/bundles/loader.rb'
16
+ $loader = Eggshell::Processor.new
17
+ $loader.vars[:target] = $eggshell
18
+ Eggshell::Bundles::Registry.attach_bundle('loader', $loader)
19
+
20
+ lookups = [Dir.home, file_dir]
21
+ lookups.each do |home|
22
+ if File.exists?("#{home}/.eggshell")
23
+ $loader.process(IO.readlines("#{home}/.eggshell"))
24
+ $eggshell._info("loaded #{home}/.eggshell")
25
+ end
26
+ end
27
+
28
+ # @todo parse any additional opts via command line or local project?
29
+
30
+ $eggshell._info("PROCESSING #{f}")
31
+ output = $eggshell.process(IO.readlines(f))
32
+ puts output
@@ -0,0 +1,54 @@
1
+ module Eggshell::BlockHandler
2
+ # Indicates that subsequent lines should be collected.
3
+ COLLECT = :collect
4
+
5
+ # Unlike COLLECT, which will parse out macros and keep the execution order,
6
+ # this will collect the line raw before any macro detection takes place.
7
+ COLLECT_RAW = :collect_raw
8
+
9
+ # Indicates that the current line ends the block and all collected
10
+ # lines should be processed.
11
+ DONE = :done
12
+
13
+ # A variant of DONE: if the current line doesn't conform to expected structure,
14
+ # process the previous lines and indicate to processor that a new block has
15
+ # started.
16
+ RETRY = :retry
17
+
18
+ def set_processor(proc)
19
+ end
20
+
21
+ def set_block_params(name)
22
+ @block_params = {} if !@block_params
23
+ @block_params[name] = @proc.get_block_params(name)
24
+ end
25
+
26
+ def create_tag(tag, attribs, open = true)
27
+ # @todo escape val?
28
+ abuff = []
29
+ attribs.each do |key,val|
30
+ if val == nil
31
+ abuff << key
32
+ else
33
+ abuff << "#{key}='#{val}'"
34
+ end
35
+ end
36
+ "<#{tag} #{abuff.join(' ')}#{open ? '>' : '/>'}"
37
+ end
38
+
39
+ def start(name, line, buffer, indents = '', indent_level = 0)
40
+ end
41
+
42
+ def collect(line, buffer, indents = '', indent_level = 0)
43
+ end
44
+
45
+ # For exception handling, optional information to provide context about error
46
+ def offsets
47
+ end
48
+
49
+ module Defaults
50
+ class NoOpHandler
51
+ include Eggshell::BlockHandler
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,51 @@
1
+ # For multiline macros, the block collects lines specific to the block (including other nested macros).
2
+ # This allows for proper execution when dealing with loops and branches.
3
+ class Eggshell::Block
4
+ def initialize(macro, handler, args, depth, delim = nil)
5
+ @stack = [self]
6
+ @lines = []
7
+ @macro = macro
8
+ @handler = handler
9
+ @args = args
10
+ @delim = delim
11
+
12
+ # reverse, and swap out
13
+ if @delim && @delim[0] == '{'
14
+ @delim = @delim.reverse.gsub(/\{/, '}').gsub(/\[/, ']')
15
+ else
16
+ @delim = nil
17
+ end
18
+
19
+ @depth = depth
20
+ end
21
+
22
+ attr_reader :depth, :lines, :delim
23
+
24
+ # Returns the current active block.
25
+ def cur
26
+ @stack[-1]
27
+ end
28
+
29
+ # Adds a nested block to collect lines into.
30
+ def push(block)
31
+ @stack[-1].lines << block
32
+ @stack << block
33
+ end
34
+
35
+ # Removes a nested block.
36
+ def pop()
37
+ @stack.pop
38
+ end
39
+
40
+ def collect(entry)
41
+ @stack[-1].lines << entry
42
+ end
43
+
44
+ def process(buffer, depth = nil)
45
+ @handler.process(buffer, @macro, @args, @lines, depth == nil ? @depth : depth)
46
+ end
47
+
48
+ def inspect
49
+ "<BLOCK #{@macro} (#{@depth}) #{@handler.class} | #{@lines.inspect} >"
50
+ end
51
+ end