oxymoron 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1aebed8d250f7ed6f893a2562ceccd8526d23d4
4
- data.tar.gz: d2807e171b9724dd518495790105edbec6591251
3
+ metadata.gz: 9bc0b4a2bc12a7d9377e2f4dc90ea3d045eb85ae
4
+ data.tar.gz: 43859c4cfa58dc84c60fc95d34eb5474d03969e6
5
5
  SHA512:
6
- metadata.gz: 0a9df72d98dbbb29b9279b740f689ccc552874325f6e763b2f7ec5271351d5028ee4edae21e8c32ca4177e1418320f6da32bdc625ad2e0d5084503bd53f30b3a
7
- data.tar.gz: 9618f50e6826f690ad841a4abea6d88309803c26dc10d20b8dce03142339073f2a2f96c2d57ccac0d36e500c8ae2c105ea068254e4444bdb8460bb6569d0bec1
6
+ metadata.gz: 92457106bff8e557875a22fea33e90393cbf8c03eabff082bcbfee16866b16ed9f266df74fee89609c88bce25396895668a4aff0adaa2edfa4386459bf77e338
7
+ data.tar.gz: 037d991888c83b6bc7ae5420c098ea8c72e92f6c184b453d83f540a2ae35f5ab1ff67e95a47ae4343ce2defa0a748ab4f331fce415caf13188a4838c039d4a96
data/LICENCE ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2016, Kononenko Pavel
3
+
4
+ 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:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ 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.
9
+
data/README.RU.md CHANGED
@@ -31,6 +31,24 @@ gem "oxymoron", git: "https://github.com/storuky/oxymoron.git", branch: :master
31
31
  */
32
32
  ```
33
33
 
34
+ ## Дополнительные настройки
35
+
36
+
37
+ **config/initializers/oxymoron.rb**
38
+ ```
39
+ Oxymoron::Config.setup do |c|
40
+ # изменить путь сохранения генерируемого oxymoron.js
41
+ c.oxymoron_js_path = Rails.root.join('app', 'assets', 'javascripts', 'public')
42
+
43
+ # Изменить конструктор форм. По умолчанию используется OxymoronFormBuilder
44
+ c.form_builder = MyFormBuilder
45
+
46
+ # Запретить переопределение form_for из ActionView::FormHelper. В этом случае используйте хэлперы oxymoron_form_for и oxymoron_field_for
47
+ c.rewrite_form_for = false
48
+ end
49
+ ```
50
+
51
+
34
52
  ##Использование
35
53
 
36
54
  Далее необходимо заинжектить 'oxymoron' и 'ui.router' в ваше AngularJS-приложение
data/README.md CHANGED
@@ -33,6 +33,23 @@ Add dependencies to your application.js and application.css
33
33
  */
34
34
  ```
35
35
 
36
+ ## Advanced settings
37
+
38
+
39
+ **config/initializers/oxymoron.rb**
40
+ ```
41
+ Oxymoron::Config.setup do |c|
42
+ # change path for generated oxymoron.js
43
+ c.oxymoron_js_path = Rails.root.join('app', 'assets', 'javascripts', 'public')
44
+
45
+ # Change form builder. By default used OxymoronFormBuilder
46
+ c.form_builder = MyFormBuilder
47
+
48
+ # Disabled rewrite form_for method in ActionView::FormHelper. In this case use helpers oxymoron_form_for and oxymoron_field_for
49
+ c.rewrite_form_for = false
50
+ end
51
+ ```
52
+
36
53
  ##Usage
37
54
 
38
55
  Next, you need to inject required modules 'oxymoron' and 'ui.router'
@@ -7,18 +7,10 @@ angular.module("oxymoron.notifier", [])
7
7
  type: 'info'
8
8
  });
9
9
 
10
- $rootScope.$on('loading:finish', function (h, res) {
11
- callback('success', res)
12
- })
13
-
14
- $rootScope.$on('loading:error', function (h, res, p) {
15
- callback('error', res)
16
- })
17
-
18
- function callback (type, res) {
10
+ $rootScope.notify_callback = function(type, res) {
19
11
  if (res.data && angular.isObject(res.data)) {
20
- if (res.data.msg) {
21
- ngNotify.set(res.data.msg, type);
12
+ if (res.data.msg || res.data.error) {
13
+ ngNotify.set(res.data.msg || res.data.error, type);
22
14
  }
23
15
 
24
16
  if (res.data.errors) {
@@ -36,4 +28,14 @@ angular.module("oxymoron.notifier", [])
36
28
  }
37
29
  }
38
30
  }
31
+
32
+ $rootScope.$on('loading:finish', function (h, res) {
33
+ $rootScope.notify_callback('success', res)
34
+ })
35
+
36
+ $rootScope.$on('loading:error', function (h, res, p) {
37
+ $rootScope.notify_callback('error', res)
38
+ })
39
+
40
+
39
41
  }])
@@ -7,6 +7,6 @@ angular.module("oxymoron.services.resources", [])
7
7
 
8
8
  <% @resources.each do |key, value| %>
9
9
  .factory('<%= key %>', ['$resource', 'resourceDecorator', function ($resource, resourceDecorator) {
10
- return resourceDecorator($resource('<%= value[:url] %>.json', <%= value[:default_params].to_json%>, <%= value[:actions].to_json %>));
10
+ return resourceDecorator($resource('<%= value[:url] %>.json', <%= value[:default_params].to_json%>, <%= JSON.pretty_generate(value[:actions]).split("\n").map{|l| (' ' * 6) + l}.join("\n").strip %>));
11
11
  }])
12
12
  <% end %>
data/lib/oxymoron.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  if defined?(::Rails)
2
+ require "oxymoron/oxymoron_form_builder"
3
+ require "oxymoron/config"
4
+ require "oxymoron/extensions/form_helper"
2
5
  require "oxymoron/engine"
3
6
  end
4
7
 
@@ -9,7 +12,7 @@ module Oxymoron
9
12
  Rails.application.reload_routes!
10
13
  @routes, @states, @resources = {}, {}, {}
11
14
 
12
- @app_routes = Rails.application.routes.routes.select{|route| route.name.present? && route.constraints[:request_method]}
15
+ @app_routes = Rails.application.routes.routes.select{|route| route.name.present? && route.verb}
13
16
  @app_routes_by_controller = @app_routes.select{|route| ['new', 'edit', 'show', 'index'].exclude?(route.defaults[:action])}.group_by{|route| route.defaults[:controller]}.delete_if {|k,v| k.nil?}
14
17
 
15
18
  @app_routes.each do |route|
@@ -29,7 +32,7 @@ module Oxymoron
29
32
  end
30
33
 
31
34
  def set_states route
32
- if route.constraints[:request_method].match("GET")
35
+ if route.verb.match("GET")
33
36
  path = route.path.spec.to_s.gsub('(.:format)', '')
34
37
  url_matcher = "'#{path}'"
35
38
 
@@ -84,7 +87,7 @@ module Oxymoron
84
87
  for_hash[route.defaults[:action]] ||= {
85
88
  url: route.path.spec.to_s.gsub('(.:format)', '.json'),
86
89
  isArray: route.defaults[:is_array],
87
- method: /GET|POST|PUT|PATCH|DELETE/.match(route.constraints[:request_method].to_s).to_s
90
+ method: /GET|POST|PUT|PATCH|DELETE/.match(route.verb.to_s).to_s
88
91
  }
89
92
  end
90
93
 
@@ -0,0 +1,20 @@
1
+ module Oxymoron
2
+
3
+ class Config
4
+ class << self
5
+
6
+ attr_accessor :oxymoron_js_path
7
+ attr_accessor :rewrite_form_for
8
+ attr_accessor :form_builder
9
+
10
+ def setup
11
+ yield self
12
+ end
13
+
14
+ end
15
+ @rewrite_form_for = true
16
+ @form_builder = OxymoronFormBuilder
17
+
18
+ end
19
+
20
+ end
@@ -2,10 +2,22 @@ require 'oxymoron/concern'
2
2
 
3
3
  module Oxymoron
4
4
  class Engine < ::Rails::Engine
5
-
6
5
  initializer 'oxymoron.dependent_on_routes', after: "sprockets.environment" do
7
6
  Rails.application.config.after_initialize do
8
- JS_ASSETS_PATH = Rails.root.join('app', 'assets', 'javascripts')
7
+
8
+ if Config.rewrite_form_for
9
+ ActionView::Base.send :include, ActionViewExtensions::FormHelperRewrite
10
+ end
11
+
12
+ ActionView::Base.send :include, ActionViewExtensions::FormHelper
13
+
14
+ module ActionView::Helpers
15
+ class FormBuilder
16
+ include ActionViewExtensions::FormBuilder
17
+ end
18
+ end
19
+
20
+ Config.oxymoron_js_path ||= Rails.root.join('app', 'assets', 'javascripts')
9
21
  routes_watch unless Rails.env.production?
10
22
  write_assets
11
23
  end
@@ -29,7 +41,7 @@ module Oxymoron
29
41
  end
30
42
 
31
43
  def write_assets
32
- File.write(JS_ASSETS_PATH.join("oxymoron.js"), Oxymoron.generate("oxymoron.js.erb"))
44
+ File.write(File.join(Config.oxymoron_js_path, "oxymoron.js"), Oxymoron.generate("oxymoron.js.erb"))
33
45
  end
34
46
  end
35
47
  end
@@ -0,0 +1,82 @@
1
+ module Oxymoron
2
+ module ActionViewExtensions
3
+
4
+ module FormHelperRewrite
5
+ def form_for(record, options = {}, &block)
6
+ raise ArgumentError, "Missing block" unless block_given?
7
+ options[:html] ||= {}
8
+ html_options = options[:html].with_indifferent_access
9
+
10
+ case record
11
+ when String, Symbol
12
+ object_name = record
13
+ object = nil
14
+ else
15
+ object = record.is_a?(Array) ? record.last : record
16
+ raise ArgumentError, "First argument in form cannot contain nil or be empty" unless object
17
+ object_name = options[:as] || model_name_from_record_or_class(object).param_key
18
+ apply_form_for_options!(record, object, options)
19
+ end
20
+
21
+ html_options[:data] = options.delete(:data) if options.has_key?(:data)
22
+ html_options[:remote] = options.delete(:remote) if options.has_key?(:remote)
23
+ html_options[:method] = options.delete(:method) if options.has_key?(:method)
24
+ html_options[:enforce_utf8] = options.delete(:enforce_utf8) if options.has_key?(:enforce_utf8)
25
+ html_options[:authenticity_token] = options.delete(:authenticity_token)
26
+
27
+ builder = instantiate_builder(object_name, object, options)
28
+ output = capture(builder, &block)
29
+ html_options[:multipart] ||= builder.multipart?
30
+ prefix = html_options["ng-submit-prefix"] || options[:prefix] || 'ctrl'
31
+ html_options["ng-submit"] ||= "formQuery = #{prefix}.save({form_name: '#{object_name}', id: #{prefix}.#{object_name}.id, #{object_name}: #{prefix}.#{object_name}}); $event.preventDefault();"
32
+
33
+ html_options[:name] ||= object_name
34
+
35
+ html_options = html_options_for_form(options[:url] || {}, html_options)
36
+ form_tag_with_body(html_options, output)
37
+ end
38
+ end
39
+
40
+
41
+ module FormHelper
42
+
43
+ def oxymoron_form_for(record, options = {}, &block)
44
+ options[:builder] ||= Config.form_builder
45
+
46
+ case record
47
+ when String, Symbol
48
+ object_name = record
49
+ else
50
+ object = record.is_a?(Array) ? record.last : record
51
+ raise ArgumentError, "First argument in form cannot contain nil or be empty" unless object
52
+ object_name = options[:as] || model_name_from_record_or_class(object).param_key
53
+ end
54
+
55
+ html_options = options[:html] ||= {}
56
+ html_options[:name] ||= object_name
57
+ prefix = html_options["ng-submit-prefix"] || options[:prefix] || 'ctrl'
58
+ html_options["ng-submit"] ||= "formQuery = #{prefix}.save({form_name: '#{object_name}', id: #{prefix}.#{object_name}.id, #{object_name}: #{prefix}.#{object_name}}); $event.preventDefault();"
59
+
60
+ options[:html].merge!(html_options)
61
+ form_for record, options, &block
62
+ end
63
+
64
+ def oxymoron_fields_for(record_name, record_object = nil, options = {}, &block)
65
+ options[:builder] ||= Config.form_builder
66
+ fields_for record_name, record_object, options, &block
67
+ end
68
+
69
+ end
70
+
71
+ module FormBuilder
72
+
73
+ def oxymoron_fields_for(record_name, record_object = nil, fields_options = {}, &block)
74
+ options[:builder] ||= Config.form_builder
75
+ fields_for record_name, record_object, fields_options, &block
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+ end
82
+
@@ -1,3 +1,3 @@
1
1
  module Oxymoron
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oxymoron
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kononenko Paul
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-11 00:00:00.000000000 Z
11
+ date: 2016-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -90,6 +90,7 @@ files:
90
90
  - ".DS_Store"
91
91
  - ".gitignore"
92
92
  - Gemfile
93
+ - LICENCE
93
94
  - MIT-LICENSE
94
95
  - README.RU.md
95
96
  - README.md
@@ -116,12 +117,13 @@ files:
116
117
  - app/assets/javascripts/oxymoron/services/sign.js
117
118
  - app/assets/javascripts/oxymoron/services/validate.js
118
119
  - app/assets/javascripts/oxymoron/states.js.erb
119
- - app/helpers/form_helper.rb
120
- - app/helpers/oxymoron_form_builder.rb
121
120
  - lib/.DS_Store
122
121
  - lib/oxymoron.rb
123
122
  - lib/oxymoron/concern.rb
123
+ - lib/oxymoron/config.rb
124
124
  - lib/oxymoron/engine.rb
125
+ - lib/oxymoron/extensions/form_helper.rb
126
+ - lib/oxymoron/oxymoron_form_builder.rb
125
127
  - lib/oxymoron/version.rb
126
128
  - lib/tasks/oxymoron_tasks.rake
127
129
  - oxymoron.gemspec
@@ -958,7 +960,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
958
960
  version: '0'
959
961
  requirements: []
960
962
  rubyforge_project:
961
- rubygems_version: 2.5.1
963
+ rubygems_version: 2.6.1
962
964
  signing_key:
963
965
  specification_version: 4
964
966
  summary: It's using AngularJS and Rails >= 4.2
@@ -1,35 +0,0 @@
1
- module FormHelper
2
- def form_for(record, options = {}, &block)
3
- raise ArgumentError, "Missing block" unless block_given?
4
- options[:html] ||= {}
5
- html_options = options[:html].with_indifferent_access
6
-
7
- case record
8
- when String, Symbol
9
- object_name = record
10
- object = nil
11
- else
12
- object = record.is_a?(Array) ? record.last : record
13
- raise ArgumentError, "First argument in form cannot contain nil or be empty" unless object
14
- object_name = options[:as] || model_name_from_record_or_class(object).param_key
15
- apply_form_for_options!(record, object, options)
16
- end
17
-
18
- html_options[:data] = options.delete(:data) if options.has_key?(:data)
19
- html_options[:remote] = options.delete(:remote) if options.has_key?(:remote)
20
- html_options[:method] = options.delete(:method) if options.has_key?(:method)
21
- html_options[:enforce_utf8] = options.delete(:enforce_utf8) if options.has_key?(:enforce_utf8)
22
- html_options[:authenticity_token] = options.delete(:authenticity_token)
23
-
24
- builder = instantiate_builder(object_name, object, options)
25
- output = capture(builder, &block)
26
- html_options[:multipart] ||= builder.multipart?
27
- prefix = html_options["ng-submit-prefix"] || 'ctrl'
28
- html_options["ng-submit"] ||= "formQuery = #{prefix}.save({form_name: '#{object_name}', id: #{prefix}.#{object_name}.id, #{object_name}: #{prefix}.#{object_name}}); $event.preventDefault();"
29
-
30
- html_options[:name] ||= object_name
31
-
32
- html_options = html_options_for_form(options[:url] || {}, html_options)
33
- form_tag_with_body(html_options, output)
34
- end
35
- end