nice 0.0.6 → 0.0.7

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.
@@ -29,8 +29,22 @@ class NiceJquery
29
29
  # remove all elements which are not of current state and all elements
30
30
  # which are of current state and secondly annotated to be always updated.
31
31
  @remove_state_elements: (event) ->
32
- $("[data-state]").not("[data-state~='#{event.curr_state}']").remove()
33
- $("[data-state~='#{event.curr_state}'][data-state-update!='no']").remove()
32
+ a = jQuery.makeArray( $("[data-state]").not("[data-state~='#{event.curr_state}']").not("[data-state~='all']") )
33
+ a = a.concat jQuery.makeArray( $("[data-state~='#{event.curr_state}'][data-state-update]").not("[data-state~='all']") )
34
+ a = a.concat jQuery.makeArray( $("[data-state~='all'][data-state-update]") )
35
+
36
+ for elem in a
37
+ transition = $(elem).data('state-transition-class')
38
+ console.log "######## REMOVE ELEMENT: #{elem}"
39
+ if( transition )
40
+ $(elem).bind 'transitionend webkitTransitionEnd oTransitionEnd otransitionend', (e) ->
41
+ $(this).remove()
42
+ $(elem).addClass(transition)
43
+ else
44
+ $(elem).remove()
45
+
46
+ return null
47
+
34
48
 
35
49
  # remove everything under the "root tag"
36
50
  @clean_root_tree: (event) ->
@@ -8,7 +8,12 @@ module Nice
8
8
  def self.remove_elements_not_of_state(state, doc)
9
9
 
10
10
  doc.css("[data-state]").each do |node|
11
- if !node.attribute('data-state').value.split(" ").include?(state) then
11
+ state_list = node.attribute('data-state').value.split(" ")
12
+
13
+ if !state_list.include?('all') &&
14
+ !state_list.include?(state) then
15
+
16
+ p "removed state: #{state_list}"
12
17
  node.remove
13
18
  end
14
19
  end
@@ -21,20 +26,25 @@ module Nice
21
26
  # get all nodes of the current state
22
27
  doc.css("*[data-state-root]").remove if upper_root # for upper_root option remove tree below root to shorten the search
23
28
  curr_state_nodes = doc.css("[data-state~='#{curr_state}']")
29
+ all_nodes = doc.css("[data-state~='all']")
30
+
24
31
 
25
32
  # get reference nodes in DOM tree for current nodes and generate js insert statements
26
33
  stack = curr_state_nodes.reverse.each_with_index.map do |curr_node,index|
27
34
 
28
- if curr_node.has_attribute?("data-state-update") &&
29
- curr_node.attribute("data-state-update").value == "no" then
35
+ # in case this node is not only assigned to the current state - check if it should be updated
36
+ if curr_node.attribute("data-state").value != curr_state &&
37
+ !curr_node.has_attribute?("data-state-update") then
30
38
  next
31
39
  end
32
40
 
33
- ref_id = self.ref_node_uid(curr_state,curr_state_nodes.count - index)
41
+ ref_id = self.ref_node_uid( curr_state,curr_state_nodes.count - index)
34
42
  ref_node_name = "[data-state-uid~=\'#{ref_id}\']"
35
43
  ref_node = doc.css(ref_node_name)
36
-
37
- next if ref_node == nil
44
+
45
+ if ref_node.blank?
46
+ next
47
+ end
38
48
 
39
49
  #get index
40
50
  idx = ref_node.attribute("data-state-uid").value.split(" ").find_index(ref_id)
@@ -50,6 +60,36 @@ module Nice
50
60
  # remove unuseful chars which will break the js parser
51
61
  js_text = js_text.gsub(/(\r\n|\n|\r|\t|\s\s)/,'')
52
62
  end
63
+
64
+ # nodes with 'all' attribute
65
+ stack += all_nodes.reverse.each_with_index.map do |curr_node,index|
66
+
67
+ if !curr_node.has_attribute?("data-state-update") then
68
+ next
69
+ end
70
+
71
+ ref_id = self.ref_node_uid( 'all',all_nodes.count - index)
72
+ ref_node_name = "[data-state-uid~=\'#{ref_id}\']"
73
+ ref_node = doc.css(ref_node_name)
74
+
75
+ if ref_node.blank?
76
+ next
77
+ end
78
+
79
+ #get index
80
+ idx = ref_node.attribute("data-state-uid").value.split(" ").find_index(ref_id)
81
+
82
+ ref_node_method = ref_node.attribute('data-state-insert-method').value.split(" ")[idx]
83
+
84
+ if ref_node_method == "insert"
85
+ js_text = Nice::Js::Caller.generate_js_insert_after curr_node, ref_node_name
86
+ else
87
+ js_text = Nice::Js::Caller.generate_js_insert_inside curr_node, ref_node_name
88
+ end
89
+
90
+ # remove unuseful chars which will break the js parser
91
+ js_text = js_text.gsub(/(\r\n|\n|\r|\t|\s\s)/,'')
92
+ end
53
93
 
54
94
  stack
55
95
  end
@@ -18,7 +18,12 @@ module Nice
18
18
  ## case 3: curr_state == prev_state
19
19
 
20
20
  # => respond with JS which either first removes all elements of the current state and
21
- # later inserts new content OR directly replaces elements
21
+ # later inserts new content OR directly replaces elements
22
+
23
+
24
+ ## case 4: this is a normal ajax request responding with javascript from rails
25
+
26
+ # => ignore any NICE handling and return body unfiltered
22
27
 
23
28
 
24
29
  def initialize(app)
@@ -30,32 +35,41 @@ module Nice
30
35
  @referer = nil
31
36
 
32
37
  status, @headers, @body = @app.call(env)
38
+
39
+ p ""
40
+ p "!!!!!!!! RAILS RESPONSE HEADERS: #{@headers}"
41
+ p ""
33
42
 
34
- @is_js = Rack::Request.new(env).xhr?
43
+ @call_is_js = Rack::Request.new(env).xhr?
44
+ @app_resp_is_js = js?
45
+
46
+ if !@app_resp_is_js && (html? || @call_is_js)
47
+
48
+ @referer = env["HTTP_REFERER"]
49
+ @method = env["REQUEST_METHOD"]
50
+ @path = env["PATH_INFO"]
35
51
 
36
- if html? || @is_js
37
- @referer = env["HTTP_REFERER"]
38
- @method = env["REQUEST_METHOD"]
39
- @path = env["PATH_INFO"]
40
-
41
- # in case 2+3 the response will be plain javascript
42
- if @is_js
43
- @headers = {"Content-Type" => "text/javascript"}
44
- end
52
+ # in case 2+3 the response will be plain javascript
53
+ if @call_is_js
54
+ @headers = {"Content-Type" => "text/javascript"}
55
+ end
45
56
 
46
57
  [status, @headers, self]
58
+
47
59
  else
48
- [status, @headers, @body]
60
+ [status, @headers, @body]
49
61
  end
50
62
  end
51
63
 
52
- def each(&block)
53
- if html? || @is_js
54
- block.call("<!-- previous state: #{@referer} -->\n")
55
- block.call( Nice::Logic.run( @method, @path, @referer, doc, @is_js) )
56
- else
57
- block.call(@body)
64
+ def each(&block)
65
+
66
+ if !@app_resp_is_js && (html? || @call_is_js)
67
+ block.call("<!-- NICE Interception -->\n")
68
+ block.call( Nice::Logic.run( @method, @path, @referer, doc, @call_is_js) )
69
+ else
70
+ block.call(@body)
58
71
  end
72
+
59
73
  end
60
74
 
61
75
  # Helper
@@ -64,6 +78,10 @@ module Nice
64
78
  def html?
65
79
  @headers["Content-Type"] && @headers["Content-Type"].include?("text/html")
66
80
  end
81
+
82
+ def js?
83
+ @headers["Content-Type"] && ( @headers["Content-Type"].include?("text/javascript") || @headers["Content-Type"].include?("application/json") )
84
+ end
67
85
 
68
86
  def doc
69
87
  @doc ||= Nokogiri::HTML(body_to_string)
@@ -1,3 +1,3 @@
1
1
  module Nice
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-15 00:00:00.000000000 Z
12
+ date: 2013-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -97,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
97
  version: '0'
98
98
  segments:
99
99
  - 0
100
- hash: -579488533932706128
100
+ hash: 3851994827556330401
101
101
  required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  none: false
103
103
  requirements:
@@ -106,10 +106,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  segments:
108
108
  - 0
109
- hash: -579488533932706128
109
+ hash: 3851994827556330401
110
110
  requirements: []
111
111
  rubyforge_project:
112
- rubygems_version: 1.8.22
112
+ rubygems_version: 1.8.24
113
113
  signing_key:
114
114
  specification_version: 3
115
115
  summary: Nice / Nizza is a posh little town in south France.