Created
October 11, 2013 16:51
-
-
Save gabetax/6938181 to your computer and use it in GitHub Desktop.
Javascript Page Object Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% @body_data = { | |
page_object: 'PostForm', | |
rails_env: Rails.env, | |
post_max_length: Post.column_types['title'].limit | |
} | |
%> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Csp</title> | |
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> | |
<%= javascript_include_tag "application", "data-turbolinks-track" => true %> | |
<%= csrf_meta_tags %> | |
</head> | |
<%= tag 'body', { data: @body_data || {} }, true %> | |
<%= yield %> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ -> | |
dispatchPageObjects() | |
dispatchPageObjects = -> | |
bodyData = $('body').data() | |
pageObjectClass = bodyData.pageObject | |
# window[foo] does String to Function conversion | |
new window[pageObjectClass](bodyData).start() if pageObjectClass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class @PostForm | |
constructor: ({@railsEnv, @postMaxLength}) -> | |
start: -> | |
@showInjectedValues() | |
@makeLabelsRed() | |
showInjectedValues: -> | |
alert "in #{@railsEnv} titles can only be #{@postMaxLength} characters long" | |
makeLabelsRed: -> | |
$('label').css 'color', 'red' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment