railj 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.textile ADDED
@@ -0,0 +1,5 @@
1
+ Copyright (c) 2009 Aleksandr Koss <kossnocorp@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
4
+
5
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,5 @@
1
+ h1. Railj
2
+
3
+ Hello cruel world!
4
+
5
+ h1. "License":http://github.com/kossnocorp/railj/blob/master/LICENSE.textile
data/Rakefile CHANGED
@@ -7,10 +7,10 @@ begin
7
7
  gem.name = 'railj'
8
8
  gem.summary = %Q{Railj}
9
9
  gem.description = %Q{Porno with Rails and JavaScript in leading roles}
10
- gem.email = "kossnocorp@gmail.ru"
10
+ gem.email = "kossnocorp@gmail.com"
11
11
  gem.homepage = "http://github.com/kossnocorp/railj"
12
12
  gem.authors = ["Aleksandr Koss"]
13
- gem.version = '0.0.1'
13
+ gem.version = '0.0.2'
14
14
 
15
15
  Jeweler::GemcutterTasks.new
16
16
 
@@ -52,3 +52,4 @@ Rake::RDocTask.new do |rdoc|
52
52
  rdoc.rdoc_files.include('README*')
53
53
  rdoc.rdoc_files.include('lib/**/*.rb')
54
54
  end
55
+
Binary file
@@ -1,25 +1,25 @@
1
1
  $(function() {
2
- $('[data-default-value]').each(function() {
3
- var default_value = $(this).attr('data-default-value');
4
-
2
+ $('[placeholder]').each(function() {
3
+ var default_value = $(this).attr('placeholder');
4
+
5
5
  if(default_value != '') {
6
-
6
+
7
7
  var start_up_value = $(this).val(),
8
8
  is_password = $(this).attr('type') == 'password',
9
9
  object = $(this),
10
10
  default_object = null,
11
- default_object_html =
12
- '<input class="' +
11
+ default_object_html =
12
+ '<input class="' +
13
13
  (is_password ? 'default-value-password ' : '' ) +
14
14
  'default-value" value="' + default_value + '" ' +
15
- 'style="border:0;margin:3px;position:absolute;top:0;left:0;"' +
15
+ 'style="border:0;margin:3px;position:absolute;top:0;left:0;"' +
16
16
  '/>';
17
17
 
18
18
  object.wrap('<div style="position: relative;"></div>');
19
-
19
+
20
20
  function destroy_default_object() {
21
21
  if(default_object == null) return;
22
-
22
+
23
23
  default_object.remove();
24
24
  default_object = null;
25
25
  }
@@ -29,22 +29,22 @@ $(function() {
29
29
  destroy_default_object();
30
30
  }
31
31
 
32
- function create_default_object() {
32
+ function create_default_object() {
33
33
  if(default_object) return;
34
34
 
35
- default_object = $(default_object_html).insertAfter(object);
36
-
35
+ default_object = $(default_object_html).insertAfter(object);
36
+
37
37
  default_object
38
38
  .focus(refocus_default_object)
39
39
  .click(refocus_default_object);
40
40
  }
41
41
 
42
42
  // Start up cheking
43
-
43
+
44
44
  if(start_up_value == '') create_default_object();
45
-
45
+
46
46
  // Triggers
47
-
47
+
48
48
  function object_focus() {
49
49
  if(default_object) destroy_default_object();
50
50
  }
@@ -57,3 +57,4 @@ $(function() {
57
57
  }
58
58
  });
59
59
  });
60
+
@@ -2,22 +2,22 @@ module Railj
2
2
  module Defaulted
3
3
  def self.included base
4
4
  base.class_eval do
5
-
5
+
6
6
  #
7
-
7
+
8
8
  alias railsjs__defaulted_text_field text_field
9
-
9
+
10
10
  def text_field object_name, method = nil, options = {}
11
11
 
12
- method_copy = method ? method.clone : nil
13
-
12
+ method_copy = method ? method.clone : nil
13
+
14
14
  if method_copy and method_copy.class == Hash
15
-
15
+
16
16
  if default_value = method_copy[:default]
17
17
  method_copy.delete :default
18
- method_copy['data-default-value'] = default_value
18
+ method_copy['placeholder'] = default_value
19
19
  end
20
-
20
+
21
21
  railsjs__defaulted_text_field \
22
22
  object_name, method_copy
23
23
  elsif method
@@ -28,27 +28,27 @@ module Railj
28
28
  object_name, {}
29
29
  end
30
30
  end
31
-
31
+
32
32
  #
33
-
33
+
34
34
  alias railsjs__defaulted_password_field password_field
35
-
35
+
36
36
  def password_field object_name, method = nil, options = {}
37
37
 
38
38
  method_copy = method ? method.clone : nil
39
-
39
+
40
40
  if method_copy and method_copy.class == Hash
41
-
41
+
42
42
  if default_value = method_copy[:default]
43
43
  method_copy.delete :default
44
- method_copy['data-default-value'] = default_value
44
+ method_copy['placeholder'] = default_value
45
45
  end
46
-
46
+
47
47
  railsjs__defaulted_password_field \
48
48
  object_name, method_copy
49
49
  elsif method
50
50
  debugger
51
-
51
+
52
52
  railsjs__defaulted_password_field \
53
53
  object_name, method, options
54
54
  else
@@ -62,3 +62,4 @@ module Railj
62
62
  end
63
63
 
64
64
  ActionView::Helpers::FormBuilder.send :include, Railj::Defaulted
65
+
data/lib/i18n/i18n.rb ADDED
@@ -0,0 +1,49 @@
1
+ module Railj
2
+ module Rack
3
+ class I18n
4
+ def initialize app, options = {}
5
+ @app = app
6
+ @options = options
7
+ end
8
+
9
+ def call env
10
+ # Valid url is /i18n-<i18n key>-<locale>.<format> where
11
+ # i18n key - yaml branch named "locale.key"
12
+ # locale - locale as is
13
+ # format - js or json
14
+
15
+ if data_array = env['PATH_INFO'].scan( \
16
+ /^\/i18n-(\w+)-(\w{1,3})[.](js[on]*)$/)[0]
17
+
18
+ key, locale, type = data_array
19
+
20
+ # Return if :accepted_keys not :all and
21
+ # not included in :accepted_keys array
22
+
23
+ return @app.call env if \
24
+ @options[:accepted_keys] and
25
+ @options[:accepted_keys] != :all and
26
+ not @options[:accepted_keys].include? key.to_sym # Key don't accepted
27
+
28
+ # Get yaml branch by key
29
+
30
+ json = YAML::load(
31
+ File.open(File.dirname(__FILE__) +
32
+ "/../config/locales/#{locale}.yml"
33
+ ))[locale][key].to_json
34
+
35
+ return @app.call env if json == 'null' # Branch not found
36
+
37
+ content_type, response = type == 'js' ?
38
+ ['application/javascript', "var i18n_#{key} = [#{json}];"] :
39
+ ['application/json', json]
40
+
41
+ [200, {'Content-Type' => content_type}, [response]]
42
+ else
43
+ @app.call env
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+
data/lib/railj.rb CHANGED
@@ -1,4 +1,8 @@
1
+ require 'i18n/i18n'
2
+ require 'routes/routes'
3
+
1
4
  require 'helpers/defaulted'
2
5
 
3
6
  require 'validations/validations'
4
7
  require 'validations/form_helper'
8
+
@@ -0,0 +1,71 @@
1
+ require(File.dirname(__FILE__) + '/../config/environment') unless defined?(Rails)
2
+
3
+ module Railj
4
+ module Rack
5
+ class Routes
6
+ def initialize app, options = {}
7
+ @app = app
8
+ @options = options
9
+ end
10
+
11
+ def call env
12
+ if env['PATH_INFO'] =~ /^\/javascripts\/routes.js$/
13
+ response = rails_route_function
14
+
15
+ routes = ActionController::Routing::Routes.routes.collect do |route|
16
+ host = "#{env['rack.url_scheme']}://#{env['HTTP_HOST']}"
17
+
18
+ path = route.segments.inject('') { |str,s| str << s.to_s }
19
+
20
+ named_route = ActionController::Routing::Routes.
21
+ named_routes.routes.index(route).to_s
22
+
23
+ if named_route != ''
24
+ response << route_function("#{named_route}_path", path)
25
+ response << route_function("#{named_route}_url", host + path)
26
+ end
27
+ end
28
+
29
+ [200, {'Content-Type' => 'application/javascript'}, [response]]
30
+ else
31
+ @app.call env
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def rails_route_function
38
+ <<EOF
39
+ function rails_route(path, var_pairs) {
40
+ var pair_index = 0,
41
+ path_copy = path;
42
+ for(; pair_index < var_pairs.length; pair_index++) {
43
+ path_copy = path_copy.replace(
44
+ ':' + var_pairs[pair_index][0],
45
+ var_pairs[pair_index][1]
46
+ );
47
+ }
48
+ return(
49
+ path_copy
50
+ .replace(/[(][.]:.+[)][?]/g, '')
51
+ .replace(/[(]|[)][?]/g, '')
52
+ );
53
+ }
54
+ EOF
55
+ end
56
+
57
+ def route_function name, path
58
+ <<EOF
59
+ function #{name}(variables) {
60
+ var var_pairs = [];
61
+ for(var key in variables) {
62
+ var_pairs.push([key, variables[key]]);
63
+ }
64
+ return(rails_route('#{path}', var_pairs));
65
+ }
66
+ EOF
67
+ end
68
+ end
69
+ end
70
+ end
71
+
@@ -11,20 +11,20 @@ module Railj
11
11
  attr_names[0],
12
12
  attr_names[1]
13
13
 
14
- eval(get_return_value attr_names)
14
+ eval(get_return_value attr_names)
15
15
  end
16
-
16
+
17
17
  def validates_acceptance_of *attr_names
18
18
  # TODO: Check attr_names[1] existance
19
- add_js_validation_value :validates_acceptance_of,
19
+ add_js_validation_value :validates_acceptance_of,
20
20
  attr_names[0],
21
21
  attr_names[1]
22
22
 
23
23
  eval(get_return_value attr_names)
24
24
  end
25
-
25
+
26
26
  def validates_presence_of *attr_names
27
- add_js_validation_value :validates_presence_of,
27
+ add_js_validation_value :validates_presence_of,
28
28
  attr_names[0],
29
29
  attr_names[1]
30
30
 
@@ -32,54 +32,54 @@ module Railj
32
32
  end
33
33
 
34
34
  def validates_length_of *attr_names
35
- add_js_validation_value :validates_length_of,
35
+ add_js_validation_value :validates_length_of,
36
36
  attr_names[0],
37
37
  attr_names[1]
38
38
 
39
- eval(get_return_value attr_names)
39
+ eval(get_return_value attr_names)
40
40
  end
41
-
41
+
42
42
  def validates_uniqueness_of *attr_names
43
43
  # TODO: Create uniqueness options
44
44
 
45
45
  eval(get_return_value attr_names)
46
46
  end
47
-
47
+
48
48
  def validates_format_of *attr_names
49
- # TODO: JavaScript regexp converter
50
- add_js_validation_value :validates_format_of,
49
+ # TODO: JavaScript regexp converter
50
+ add_js_validation_value :validates_format_of,
51
51
  attr_names[0],
52
52
  attr_names[1]
53
-
54
- eval(get_return_value attr_names)
53
+
54
+ eval(get_return_value attr_names)
55
55
  end
56
56
 
57
57
  def validates_inclusion_of *attr_names
58
- add_js_validation_value :validates_inclusion_of,
58
+ add_js_validation_value :validates_inclusion_of,
59
59
  attr_names[0],
60
60
  attr_names[1]
61
61
 
62
62
  eval(get_return_value attr_names)
63
63
  end
64
-
64
+
65
65
  def validates_exclusion_of *attr_names
66
- add_js_validation_value :validates_exclusion_of,
66
+ add_js_validation_value :validates_exclusion_of,
67
67
  attr_names[0],
68
68
  attr_names[1]
69
-
69
+
70
70
  eval(get_return_value attr_names)
71
71
  end
72
-
72
+
73
73
  def validates_associated *attr_names
74
74
  # TODO: How it wrap to JavaScript?!
75
-
75
+
76
76
  eval(get_return_value attr_names)
77
77
  end
78
-
78
+
79
79
  def validates_numericality_of *attr_names
80
80
  # TODO: How it wrap to JavaScript?!
81
-
82
- eval(get_return_value attr_names)
81
+
82
+ eval(get_return_value attr_names)
83
83
  end
84
84
 
85
85
  def get_validation_rules field_name
@@ -93,29 +93,29 @@ module Railj
93
93
  attr_names.each_index do |index|
94
94
  return_array << "attr_names[#{index}]"
95
95
  end
96
- "super #{return_array.join ', '}"
96
+ "super #{return_array.join ', '}"
97
97
  end
98
-
98
+
99
99
  def add_js_validation_value method_name, field_name, options
100
100
  options_json = ''
101
-
101
+
102
102
  if options
103
103
  # Prepare options hash to JSON
104
-
104
+
105
105
  copied_options = options.clone
106
106
  copied_options.each_pair do |key, value|
107
107
  copied_options[key] = value.to_s if value.class == Range
108
108
  end
109
-
109
+
110
110
  options_json = copied_options.to_json
111
111
  end
112
112
 
113
113
  # Create @@validation_rules structure if it needed
114
-
114
+
115
115
  @@validation_rules = Hash.new unless defined? @@validation_rules
116
116
  @@validation_rules[field_name] = Hash.new unless \
117
117
  defined?(@@validation_rules[field_name]) == true
118
-
118
+
119
119
  @@validation_rules[field_name]["data-#{method_name.to_s.gsub('_', '-')}"] = options_json
120
120
  end
121
121
  end
@@ -123,3 +123,4 @@ module Railj
123
123
  end
124
124
 
125
125
  ActiveRecord::Base.class_eval { include Railj::Validations }
126
+
data/railj.gemspec ADDED
@@ -0,0 +1,61 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{railj}
8
+ s.version = "0.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Aleksandr Koss"]
12
+ s.date = %q{2009-11-16}
13
+ s.description = %q{Porno with Rails and JavaScript in leading roles}
14
+ s.email = %q{kossnocorp@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.textile",
17
+ "README.textile"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ "LICENSE.textile",
22
+ "README.textile",
23
+ "Rakefile",
24
+ "doc/images/defaulted_screenshot.png",
25
+ "generators/railj_defaulted/railj_defaulted_generator.rb",
26
+ "generators/railj_defaulted/templates/jquery.defaulted.js",
27
+ "init.rb",
28
+ "install.rb",
29
+ "lib/helpers/defaulted.rb",
30
+ "lib/i18n/i18n.rb",
31
+ "lib/railj.rb",
32
+ "lib/routes/routes.rb",
33
+ "lib/validations/form_helper.rb",
34
+ "lib/validations/validations.rb",
35
+ "railj.gemspec",
36
+ "tasks/rails.js_tasks.rake",
37
+ "test/rails.js_test.rb",
38
+ "test/test_helper.rb",
39
+ "uninstall.rb"
40
+ ]
41
+ s.homepage = %q{http://github.com/kossnocorp/railj}
42
+ s.rdoc_options = ["--charset=UTF-8"]
43
+ s.require_paths = ["lib"]
44
+ s.rubygems_version = %q{1.3.5}
45
+ s.summary = %q{Railj}
46
+ s.test_files = [
47
+ "test/test_helper.rb",
48
+ "test/rails.js_test.rb"
49
+ ]
50
+
51
+ if s.respond_to? :specification_version then
52
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
+ s.specification_version = 3
54
+
55
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
56
+ else
57
+ end
58
+ else
59
+ end
60
+ end
61
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railj
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksandr Koss
@@ -9,31 +9,36 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-07 00:00:00 +06:00
12
+ date: 2009-11-16 00:00:00 +06:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
16
  description: Porno with Rails and JavaScript in leading roles
17
- email: kossnocorp@gmail.ru
17
+ email: kossnocorp@gmail.com
18
18
  executables: []
19
19
 
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
- - README
23
+ - LICENSE.textile
24
+ - README.textile
24
25
  files:
25
26
  - .gitignore
26
- - MIT-LICENSE
27
- - README
27
+ - LICENSE.textile
28
+ - README.textile
28
29
  - Rakefile
30
+ - doc/images/defaulted_screenshot.png
29
31
  - generators/railj_defaulted/railj_defaulted_generator.rb
30
32
  - generators/railj_defaulted/templates/jquery.defaulted.js
31
33
  - init.rb
32
34
  - install.rb
33
35
  - lib/helpers/defaulted.rb
36
+ - lib/i18n/i18n.rb
34
37
  - lib/railj.rb
38
+ - lib/routes/routes.rb
35
39
  - lib/validations/form_helper.rb
36
40
  - lib/validations/validations.rb
41
+ - railj.gemspec
37
42
  - tasks/rails.js_tasks.rake
38
43
  - test/rails.js_test.rb
39
44
  - test/test_helper.rb
data/MIT-LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2009 [name of plugin creator]
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 DELETED
@@ -1,13 +0,0 @@
1
- Rails.js
2
- ========
3
-
4
- Introduction goes here.
5
-
6
-
7
- Example
8
- =======
9
-
10
- Example goes here.
11
-
12
-
13
- Copyright (c) 2009 [name of plugin creator], released under the MIT license