Skip to content

Instantly share code, notes, and snippets.

@cj

cj/login.rb Secret

Last active August 29, 2015 14:07
Show Gist options
  • Save cj/0e9895ba427d950cf189 to your computer and use it in GitHub Desktop.
Save cj/0e9895ba427d950cf189 to your computer and use it in GitHub Desktop.
class LoginComp < Roda::Component
name :login
html './public/user-login.html'
def display data
events.trigger :submit
if server?
dom.html
else
bind_default_events
end
end
def moo
puts 'cow'
puts cache
end
on :submit do
moo
puts 'from submit!!'
end
on :input_log do
puts 'input clicked'
end
private
def bind_default_events
dom.find('#login-form-email') do |input|
input.on :keyup do
trigger :input_log
val = input.prop 'value'
dom.find('h1').html = val
end
end
end
setup do |dom|
head = dom.at('head')
inline_tags = []
head.css('script, link').each do |tag|
if (%w(src href) & tag.attributes.keys).empty?
inline_tags << tag
end
tag.remove
end
head.add_child app.assets [:css, :login]
head.add_child app.assets [:js, :login]
head.add_child '<script type="text/javascript" src="/assets/components"></script>'
inline_tags.each do |tag|
head.add_child tag
end
dom.css('img').each do |img|
img['src'] = '/assets/' + img['src']
end
form = dom.at('form#login-form')
form.css('.form-group').each do |group|
group['class'] = group['class'].gsub('has-error', '')
end
tmpl :field_error_msg, form.at('.field-error-msg')
tmpl :form_error_msg, form.at('.form-error-msg')
form['method'] = 'POST'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment