nice 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -3,11 +3,8 @@
3
3
  ## What?
4
4
 
5
5
  *Nice* is a light-weight engine which puts some *magic* into JS/AJAX driven Rails pages with the aim to ease the development of rich and interactive restful web applications.
6
- The idea is about state defintions as they are known in Adobe Flex for a while which represent one visiual status displayed to the user. In response to an event (typically user interaction), this state can change.
7
- Think of page states as of one visual view presented to the user - or for RESTful applications, one state is tied to one route.
8
- While plain HTML requires a page refresh to update the visual presentation, Javascript introduced a possiblity to define a transitition to the next state by adding or removing elements on the fly. Although this is an enhancement with regards to user experience, but the source code gets messed up easily, because the view will be generated both on the server and dynamically in the browser. Furthermore rendering code will be written twice and we all know that this leads to incoherence. Finally, the idea of *Nice* is to put the view generation entirely on the backend side (where it should be for several reasons!) and let the state transitions happen auto-magically. Instead of coding the changes between different states you will simply code your states by annotating which page elements belong to which state and *Nice* generates the glue code to transit between states - no matter how many states you have. Specially if you consider having multiple states you have to write a lot of code in plain javascript to handle all possible state changes, *Nice* can handle this easily and consistently.
9
6
 
10
- The whole framework is aimed to be non-intrusive as much as possible, so the way you regulary write your rails apps won't change dramatically.
7
+ Go [here](http://nice.codebility.com) for an example and a detailed description.
11
8
 
12
9
  ## How to use
13
10
 
@@ -87,6 +84,41 @@ This restriction is imposed by the way how the middleware calculates reference p
87
84
 
88
85
  All links in your application should now use the ```:remote => :true``` attribute to ensure the requests will be sent using javascript by default.
89
86
 
87
+ ### State Transitions
88
+
89
+ Nice offers the ability to make your state changes even smoother by using either JS and/or CSS. Every element inside a <code>data-state</code> with <code>data-state-transition=\"default\"</code> will be animated using the corresponding transition configuration. By default, a linear fade-in over 200ms is used, but you can override or configure any other property animation. You need to provide your configuration by creating some JS functions. I recommend using [coffee-script](http://coffeescript.org) and name the file *nice-transitions.js.coffee*:
90
+
91
+ ```
92
+ class this.NiceTransitions
93
+ @default =
94
+ duration: 1000
95
+ easing: "linear"
96
+ properties:
97
+ opacity: 0.0
98
+
99
+ @fade_slow =
100
+ duration: 2000
101
+ easing: "linear"
102
+ properties:
103
+ opacity: 0.0
104
+
105
+ @slide_top =
106
+ duration: 1000
107
+ easing: "swing"
108
+ properties:
109
+ "top": "-200px"
110
+ ```
111
+
112
+ The body class gets the always a CSS class with the following naming convention assigned: <code>state-\{current_state_name\}</code>. You can use this to configure your styles per state like this:
113
+
114
+ ```
115
+ .state-get_basic_a{
116
+ .set2, .set3{
117
+ opacity: 0.4;
118
+ }
119
+ }
120
+ ```
121
+
90
122
  ### Features
91
123
 
92
124
  *Nice* is still in early stages and there is truly a lot to do. If you feel intrested and want to contribute, please don't hestitate to start work on one of the following features or enhance existing ones.
@@ -104,7 +136,7 @@ Nice is a middleware which processes all HTML and JS requests by either removing
104
136
 
105
137
  ## Roadmap / Contribute
106
138
 
107
- - better example application
139
+ - css class manipulation and css3 transition support
108
140
  - test cases
109
141
  - customization of state names
110
142
  - customization of HTML5 attribute names
@@ -1,5 +1,15 @@
1
1
  ## default event handler
2
2
  class NiceJquery
3
+
4
+ # css top class manipulation
5
+ @change_top_css: (event) ->
6
+ # remove global state class and add new one
7
+ reg = /// ^
8
+ state-\S+
9
+ ///
10
+ matches = $("body").attr("class")?.match(reg)
11
+ $("body").removeClass(c_name) for c_name in matches if matches?
12
+ $("body").addClass("state-#{event.new_state_name}")
3
13
 
4
14
  # insert element after referencing node
5
15
  @insert_after: (event) ->
@@ -34,8 +44,6 @@ class NiceJquery
34
44
  )
35
45
 
36
46
 
37
-
38
-
39
47
  # each DOM Manipulation should call this method which will apply the transition animation start values
40
48
  # to the elements before inserting into the DOM tree and the trigger the animation
41
49
  @perform_transition: (elem_ref, elem_new, action) ->
@@ -65,7 +73,8 @@ class NiceJquery
65
73
  # if no custom definitions exist - generate a default to do something at least
66
74
  if( !transition_def? )
67
75
  if transition?
68
- console.log("Custom Transition Definition for \"#{transition}\" is missing! Please create a NiceTransitions class and configure your transitions.")
76
+ console.log("Custom Transition Definition for \"#{transition}\" is \
77
+ missing! Please create a NiceTransitions class and configure your transitions.")
69
78
 
70
79
  # rescue default transition
71
80
  transition_def =
@@ -97,5 +106,7 @@ class NiceJquery
97
106
  document.addEventListener "nice.dom.InsertAfterEvent", NiceJquery.insert_after, false
98
107
  document.addEventListener "nice.dom.InsertInsideEvent", NiceJquery.insert_inside, false
99
108
  document.addEventListener "nice.dom.RemoveStateEvent", NiceJquery.remove_state_elements, false
109
+ document.addEventListener "nice.dom.ChangeTopCssEvent", NiceJquery.change_top_css, false
100
110
  document.addEventListener "nice.hist.ChangeURLEvent", NiceJquery.move_to_url, false
101
111
  document.addEventListener "nice.hist.PopHistoryEvent", NiceJquery.insert_or_update_back_listener, false
112
+
@@ -114,7 +114,11 @@ module Nice
114
114
 
115
115
  doc
116
116
  end
117
-
117
+
118
+ def self.add_top_css doc, current_state
119
+ doc.css("body").add_class("state-#{current_state}")
120
+ doc
121
+ end
118
122
 
119
123
  private
120
124
 
@@ -30,9 +30,9 @@ module Nice
30
30
  "NiceEventDispatcher.dispatch_event(\'nice.ui.StateDidChangeEvent\',{prev_state:\'#{prev_state}\', new_state:\"#{new_state}\"});"
31
31
  end
32
32
 
33
- # State Transition Animations
34
- def self.perform_transition_animations
35
- "NiceEventDispatcher.dispatch_event(\'nice.trsn.AnimateEvent\');"
33
+ # Change Body Css Class to reflect current state
34
+ def self.change_top_css new_state_name
35
+ "NiceEventDispatcher.dispatch_event(\'nice.dom.ChangeTopCssEvent\',{new_state_name:\'#{new_state_name}\'});"
36
36
  end
37
37
 
38
38
  end
@@ -39,7 +39,7 @@ module Nice
39
39
  # case 1
40
40
  if !is_js then
41
41
 
42
- cleaned_doc.to_html
42
+ Nice::HtmlParser.add_top_css(cleaned_doc, current_state).to_html
43
43
 
44
44
  # case 2
45
45
  else
@@ -56,6 +56,8 @@ module Nice
56
56
  js_stack << "// inform ui on state change"
57
57
  js_stack << Nice::Js::Caller.state_did_change(prev_state,current_state)
58
58
 
59
+ js_stack << Nice::Js::Caller.change_top_css(current_state)
60
+
59
61
  js_stack.join("\n")
60
62
  end
61
63
  end
@@ -1,3 +1,3 @@
1
1
  module Nice
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
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.4
4
+ version: 0.0.5
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-06-18 00:00:00.000000000 Z
12
+ date: 2012-06-20 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: -2243244646297613030
100
+ hash: 3643352142035015313
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: -2243244646297613030
109
+ hash: 3643352142035015313
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.