Class: Hopskip::HopscotchParser

Inherits:
Object
  • Object
show all
Defined in:
lib/hopskip/hopscotch_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ HopscotchParser

Returns a new instance of HopscotchParser.



9
10
11
12
13
14
15
16
17
18
# File 'lib/hopskip/hopscotch_parser.rb', line 9

def initialize(controller)
  @controller = controller
  filename = Rails.root.join('app', 'tours', "#{ @controller.controller_name }_tour.yml")
  puts filename
  if File.exists?(filename)
    @yaml_source = YAML::load(File.open("#{ Rails.root }/app/tours/#{ @controller.controller_name }_tour.yml"))
  else
    puts 'cannot find file!'
  end
end

Instance Attribute Details

#controller=(value) ⇒ Object (writeonly)

Sets the attribute controller

Parameters:

  • value

    the value to set the attribute controller to.



7
8
9
# File 'lib/hopskip/hopscotch_parser.rb', line 7

def controller=(value)
  @controller = value
end

#yaml_sourceObject (readonly)

Returns the value of attribute yaml_source.



6
7
8
# File 'lib/hopskip/hopscotch_parser.rb', line 6

def yaml_source
  @yaml_source
end

Instance Method Details

#showObject



20
21
22
23
24
25
26
# File 'lib/hopskip/hopscotch_parser.rb', line 20

def show
  if @yaml_source.present? && @yaml_source[@controller.action_name].present?
    steps = @yaml_source[@controller.action_name]['steps']
    locals = { id: "#{ @controller.controller_name }_#{ @controller.action_name }_tour", steps: steps.to_json }
    Erubis::Eruby.new("<script>var tour = {id: \"<%= id %>\",steps: <%= steps %>};hopscotch.startTour(tour);</script>").result(locals).html_safe
  end
end