Class: Tilt::DynCliTemplate

Inherits:
Template
  • Object
show all
Defined in:
lib/dyndoc/srv/tilt.rb

Constant Summary collapse

@@end_token =
"__[[END_TOKEN]]__"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



12
13
14
# File 'lib/dyndoc/srv/tilt.rb', line 12

def content
  @content
end

Class Method Details

.engine_initialized?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/dyndoc/srv/tilt.rb', line 51

def self.engine_initialized?
  defined? ::DynDoc
end

.init(libs = nil) ⇒ Object



16
17
# File 'lib/dyndoc/srv/tilt.rb', line 16

def DynCliTemplate.init(libs=nil)
end

Instance Method Details

#decode_cmd(res) ⇒ Object



45
46
47
48
49
# File 'lib/dyndoc/srv/tilt.rb', line 45

def decode_cmd(res)
  if res =~ /^__send_cmd__\[\[([a-zA-Z0-9_]*)\]\]__([\s\S]*)/m
  	return {cmd: $1, content: $2}
  end
end

#evaluate(scope, locals, &block) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/dyndoc/srv/tilt.rb', line 67

def evaluate(scope, locals, &block)
  if locals.keys.include? :reinit and locals[:reinit]
    ## The layout needs to be reintailized for new dyndoc file but not for the layout (of course)!
    @dyndoc_cmd="dyndoc"
    @dyndoc_cmd += "_with_tag_tmpl" if locals[:reinit].include? :dyndoc_tag_tmpl
    @dyndoc_cmd += "_with_libs_reinit" if locals[:reinit].include? :dyndoc_libs
    @dyndoc_cmd += "_with_layout_reinit" if locals[:reinit].include? :dyndoc_layout
    locals.delete :reinit
  end

	@output=prepare_output
	#puts @output
	#@output
end

#initialize_engineObject



55
56
57
# File 'lib/dyndoc/srv/tilt.rb', line 55

def initialize_engine
	DynCliTemplate.init
end

#prepareObject



59
# File 'lib/dyndoc/srv/tilt.rb', line 59

def prepare; end

#prepare_outputObject



62
63
64
65
# File 'lib/dyndoc/srv/tilt.rb', line 62

def prepare_output
  send_dyndoc(data)
return @content
end

#send_dyndoc(code) ⇒ Object

reinit is an array



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/dyndoc/srv/tilt.rb', line 21

def send_dyndoc(code)

    addr,port="127.0.0.1",7777


#p [:addr,@addr]
	Socket.tcp(addr, port) {|sock|
			msg='__send_cmd__[['+@dyndoc_cmd+']]__' + code + @@end_token
			#p msg
				sock.print msg
			#sleep 1
				sock.close_write
				@result=sock.read
	}

	data=@result.split(@@end_token,-1)
	last=data.pop
	resCmd=decode_cmd(data.join(""))
	##p [:resCmd,resCmd]
	if resCmd and resCmd[:cmd] != "windows_platform"
		@content=resCmd[:content]
	end
end