Class: Middleman::OrgExtension

Inherits:
Extension
  • Object
show all
Defined in:
lib/middleman-org/extension.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options_hash = {}, &block) ⇒ OrgExtension

Returns a new instance of OrgExtension.



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/middleman-org/extension.rb', line 21

def initialize(app, options_hash = {}, &block)
  # Call super to build options from the options_hash
  super

  # Require libraries only when activated
  require 'emacs-ruby'
  require 'org-ruby'
  require 'middleman-org/org_data'
  ::Tilt.prefer(Tilt::OrgTemplate, 'org')

  @name = options.name.to_sym if options.name
  # options.root = File.join(options.prefix, options.root) if options.prefix

  app.after_configuration do
    template_extensions org: :html
    if config[:org_engine] == :emacs_ruby
      ::Tilt.prefer(Tilt::EmacsRuby::OrgTemplate, 'org')
    end
  end

  # set up your extension
  # puts options.my_option
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



17
18
19
# File 'lib/middleman-org/extension.rb', line 17

def data
  @data
end

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'lib/middleman-org/extension.rb', line 18

def name
  @name
end

Instance Method Details

#after_configurationObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/middleman-org/extension.rb', line 45

def after_configuration
  @name ||= :"org#{::Middleman::Org.instances.keys.length}"
  ::Middleman::Org.instances[@name] = self

  # Make sure ActiveSupport's TimeZone stuff has something to work with,
  # allowing people to set their desired time zone via Time.zone or
  # set :time_zone
  Time.zone = app.config[:time_zone] if app.config[:time_zone]
  time_zone = Time.zone || 'UTC'
  zone_default = Time.find_zone!(time_zone)
  unless zone_default
    raise 'Value assigned to time_zone not recognized.'
  end
  Time.zone_default = zone_default

  @data = Org::OrgData.new(@app, self, options)
  @app.sitemap.register_resource_list_manipulator(:"org_articles", @data, false)
end