Module: JSC::Plugin

Included in:
JSCRef, JSCite, MathJaxBlock, MathJaxInline
Defined in:
lib/plugin.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ctxObject (readonly)

Returns the value of attribute ctx.



3
4
5
# File 'lib/plugin.rb', line 3

def ctx
  @ctx
end

#siteObject (readonly)

Returns the value of attribute site.



3
4
5
# File 'lib/plugin.rb', line 3

def site
  @site
end

Instance Method Details

#configObject



5
6
7
8
9
10
11
12
# File 'lib/plugin.rb', line 5

def config
  @config                              ||= Hash.new
  @config['match_jax']                 ||= Hash.new
  @config['match_jax']['config']       ||= 'default.js'
  @config['match_jax']['local_config'] ||= ''
  @config['match_jax']['url']          ||= ''
  @config
end

#math_jaxObject



36
37
38
39
40
41
42
# File 'lib/plugin.rb', line 36

def math_jax
  r                         = !ctx['jsc']['mj_injected'] ?
      "<script type=\"text/javascript\" src=\"#{mj_url}?config=#{mj_config}#{mj_local}\"></script>" : ''
  ctx['jsc']['mj_injected'] ||= true
  r
  #todo need to modify   loadComplete     http://docs.mathjax.org/en/latest/configuration.html#local-config-files
end

#mj_configObject



20
21
22
# File 'lib/plugin.rb', line 20

def mj_config
  config['match_jax']['config']
end

#mj_localObject



28
29
30
# File 'lib/plugin.rb', line 28

def mj_local
  mj_local? ? ',' + config['match_jax']['config'] : ''
end

#mj_local?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/plugin.rb', line 24

def mj_local?
  !config['match_jax']['local_config'].empty?
end

#mj_urlObject



32
33
34
# File 'lib/plugin.rb', line 32

def mj_url
  config['match_jax']['url'].empty? ? 'http://cdn.mathjax.org/mathjax/latest/MathJax.js' : config['match_jax']['url']
end

#set_ctx(ctx) ⇒ Object



14
15
16
17
18
# File 'lib/plugin.rb', line 14

def set_ctx(ctx)
  @ctx, @site, = ctx, ctx.registers[:site]
  @config      = @site.config['jsc'] || {}
  ctx['jsc']   ||= {}
end