Class: LazyValue::ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/lazy_value/application_controller.rb

Constant Summary collapse

REGEXP =
/<%= lazy_value_tag(?:.*?)do %>(.*?)<% end %>|<%= lazy_value_tag { (.+?) } %>/m
ERROR_MESSAGE =
"Incorrect usage. Try to use \"lazy_value_tag do ... end\" or \"lazy_value_tag { ... }\""

Instance Method Summary collapse

Instance Method Details

#showObject



6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/lazy_value/application_controller.rb', line 6

def show
  matches = code.match(REGEXP)
  if matches.present? && matches[1].present?
    render plain: ActionController::Base.render(inline: matches[1])
  elsif matches.present? && matches[2].present?
    render plain: eval(matches[2])
  else
    render plain: ERROR_MESSAGE
  end
end