Class: Hopskip::HopscotchParser
- Inherits:
-
Object
- Object
- Hopskip::HopscotchParser
- Defined in:
- lib/hopskip/hopscotch_parser.rb
Instance Attribute Summary collapse
-
#controller ⇒ Object
writeonly
Sets the attribute controller.
-
#yaml_source ⇒ Object
readonly
Returns the value of attribute yaml_source.
Instance Method Summary collapse
-
#initialize(controller) ⇒ HopscotchParser
constructor
A new instance of HopscotchParser.
- #show ⇒ Object
Constructor Details
#initialize(controller) ⇒ HopscotchParser
Returns a new instance of HopscotchParser.
9 10 11 12 13 14 15 |
# File 'lib/hopskip/hopscotch_parser.rb', line 9 def initialize(controller) @controller = controller filename = Rails.root.join('app', 'tours', "#{ @controller.controller_name }_tour.yml") if File.exists?(filename) @yaml_source = YAML::load(File.open("#{ Rails.root }/app/tours/#{ @controller.controller_name }_tour.yml")) end end |
Instance Attribute Details
#controller=(value) ⇒ Object (writeonly)
Sets the attribute controller
7 8 9 |
# File 'lib/hopskip/hopscotch_parser.rb', line 7 def controller=(value) @controller = value end |
#yaml_source ⇒ Object (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
#show ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/hopskip/hopscotch_parser.rb', line 17 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 |