mwp_themes_proposal_client 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", "3.2.6"
4
+ gem "capybara", ">= 0.4.0"
5
+ gem "sqlite3"
6
+
7
+ # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
8
+ # gem 'ruby-debug'
9
+ # gem 'ruby-debug19'
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = MwpThemesProposalClient
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rake'
10
+ require 'rake/rdoctask'
11
+
12
+ require 'rake/testtask'
13
+
14
+ Rake::TestTask.new(:test) do |t|
15
+ t.libs << 'lib'
16
+ t.libs << 'test'
17
+ t.pattern = 'test/**/*_test.rb'
18
+ t.verbose = false
19
+ end
20
+
21
+ task :default => :test
22
+
23
+ Rake::RDocTask.new(:rdoc) do |rdoc|
24
+ rdoc.rdoc_dir = 'rdoc'
25
+ rdoc.title = 'MwpThemesProposalClient'
26
+ rdoc.options << '--line-numbers' << '--inline-source'
27
+ rdoc.rdoc_files.include('README.rdoc')
28
+ rdoc.rdoc_files.include('lib/**/*.rb')
29
+ end
@@ -0,0 +1,16 @@
1
+ class MwpEventRegister
2
+ sessionId = null
3
+ self = this
4
+
5
+ @registerEvent = (eventName, themeIds) ->
6
+ return unless eventName
7
+ $.post '/mwp-themes-proposal/1/register/'+eventName.toString()+'.json', { session_id: sessionId, theme_id: themeIds }
8
+
9
+ @hook = (selector, eventName) ->
10
+ $(selector).click ->
11
+ self.registerEvent(eventName, $(this).attr('data-theme-id'))
12
+
13
+ @setSessionId = (sid) ->
14
+ sessionId = sid
15
+
16
+ window.MwpEventRegister = MwpEventRegister
@@ -0,0 +1,49 @@
1
+ module StatsHelper
2
+ def stats_helper(&blk)
3
+ hooks_array = Array.new
4
+
5
+ hooks = Helpers::Hooks.new(hooks_array)
6
+ hooks.instance_eval(&blk)
7
+
8
+ hooks_js = hooks_array.map do |h|
9
+ Helpers.mwp_register_hook(h[:scope], h[:event])
10
+ end.join("\n")
11
+
12
+ session[:session_id] ?
13
+ Helpers.format_hook_js(session[:session_id], hooks_js) :
14
+ nil
15
+ end
16
+
17
+ private
18
+
19
+ module Helpers
20
+ class Hooks
21
+ def initialize(hooks)
22
+ @hooks = hooks
23
+ end
24
+
25
+ def hook(scope, event)
26
+ @hooks << { scope: scope, event: event }
27
+ end
28
+ end
29
+
30
+ def self.format_hook_js(session_id, hooks_js)
31
+ session_id = Digest::MD5.hexdigest(session_id)
32
+ %Q{
33
+ <script type="text/javascript" charset="utf-8">
34
+ (function() {
35
+ jQuery(function() {
36
+ MwpEventRegister.setSessionId('#{session_id}');
37
+ #{hooks_js}
38
+ });
39
+ }).call(this);
40
+ </script>
41
+ }.gsub("\n", "").gsub(/\s+/, ' ').html_safe
42
+ end
43
+
44
+ def self.mwp_register_hook(scope, event)
45
+ "MwpEventRegister.hook('#{scope}', '#{event}');"
46
+ end
47
+ end
48
+
49
+ end
@@ -0,0 +1,4 @@
1
+ module MwpThemesProposalClient
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mwp_themes_proposal_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ivan Kasatenko
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-08 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Themes proposal client-side client gem
15
+ email:
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - app/assets/javascripts/mwp_themes_proposal_client.js.coffee
21
+ - app/helpers/stats_helper.rb
22
+ - lib/mwp_themes_proposal_client.rb
23
+ - MIT-LICENSE
24
+ - Rakefile
25
+ - Gemfile
26
+ - README.rdoc
27
+ homepage:
28
+ licenses: []
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 1.8.24
48
+ signing_key:
49
+ specification_version: 3
50
+ summary: Themes proposal client-side client gem
51
+ test_files: []