scajax 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.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +61 -0
- data/Rakefile +4 -0
- data/lib/generators/scajax/USAGE +33 -0
- data/lib/generators/scajax/scajax_generator.rb +135 -0
- data/lib/scajax/version.rb +3 -0
- data/lib/scajax.rb +4 -0
- data/scajax.gemspec +24 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MmNhNjY1YWI2MzZjYWI4YmUzNmQ1ZDUwYzY5OTUyZWU4OWVjNzlmZA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZTlhOTRmMjM5MWM5MjI2Njc5ZDc3YTk5ODJjNzJiZTkwZmRkMmJhMQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YzExMWEyNWNjMzY2ODJiNDk2YzdkNjBlMDljZmExMmUyOTNlNDJiYTdiN2Uz
|
10
|
+
NTkwOTBiNDY1Njc5NzkzYjk2ODJmYzQ0MzkzMWY3OTllNWI2ZmMyZDRmYjA2
|
11
|
+
ODdlMTBmZWM1ODM4MDkyNzIzMzU2MWQyNWIzOWY4ODJmMWZjOTM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
Y2RkNDNhZTkyYmJiYzM2YWZmZWUwMDRhOGVkYmRhYzYxOGYwNTg3ZGQ5ZWQy
|
14
|
+
ZDAwMzYxNmMwNTBkZGU5ZjlkYTg5Njg3NTFlMGUyZmRmZGMyYzFiMDkwOTc5
|
15
|
+
YmU3MGEzYWI3MzcxZWZlMmM3ODUwNzlkOWM5M2Y0ZGE2MjA5MGU=
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 menuitem
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Scajax [](https://travis-ci.org/menuitem/scajax)
|
2
|
+
|
3
|
+
This gem adds basic ajax functionality to generated scaffold in rails.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'scajax'
|
10
|
+
|
11
|
+
or for latest version of the gem add:
|
12
|
+
|
13
|
+
gem 'scajax', git: 'git@github.com:menuitem/scajax.git'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Also you can install it yourself in your system gems as:
|
20
|
+
|
21
|
+
$ gem install scajax
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
$ rails g scajax [RESOURCE_NAME]
|
26
|
+
|
27
|
+
Example:
|
28
|
+
|
29
|
+
add scajax to your application's Gemfile:
|
30
|
+
|
31
|
+
gem 'scajax'
|
32
|
+
|
33
|
+
or for latest version of the gem add:
|
34
|
+
|
35
|
+
gem 'scajax', git: 'git@github.com:menuitem/scajax.git'
|
36
|
+
|
37
|
+
and run 'bundle' to install this gem in your project.
|
38
|
+
|
39
|
+
$ bundle
|
40
|
+
|
41
|
+
Generate new scaffold called e.g posts:
|
42
|
+
|
43
|
+
$ rails generate scaffold post title body:text published:boolean
|
44
|
+
|
45
|
+
Don't forget to run migration:
|
46
|
+
|
47
|
+
$ rake db:migrate
|
48
|
+
|
49
|
+
Generate ajax for posts scaffold with scajax generator
|
50
|
+
|
51
|
+
$ rails g scajax post
|
52
|
+
|
53
|
+
Open your project in a browser.
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
1. Fork it
|
58
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
59
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
60
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
61
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
Description:
|
2
|
+
|
3
|
+
This gem adds basic ajax functionality to generated scaffold.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
rails g scajax [RESOURCE_NAME]
|
8
|
+
|
9
|
+
Example:
|
10
|
+
|
11
|
+
add scajax to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'scajax'
|
14
|
+
|
15
|
+
or for latest version of the gem add:
|
16
|
+
|
17
|
+
gem 'scajax', git: 'git@github.com:menuitem/scajax.git'
|
18
|
+
|
19
|
+
and run 'bundle' to install this gem in your project.
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Generate new scaffold called e.g posts:
|
24
|
+
|
25
|
+
$ rails generate scaffold post title body:text published:boolean
|
26
|
+
|
27
|
+
Don't forget to run migration:
|
28
|
+
|
29
|
+
$ rake db:migrate
|
30
|
+
|
31
|
+
Generate ajax for posts scaffold with scajax generator
|
32
|
+
|
33
|
+
$ rails g scajax post
|
@@ -0,0 +1,135 @@
|
|
1
|
+
class ScajaxGenerator < Rails::Generators::NamedBase
|
2
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
|
+
#application.html.erb
|
4
|
+
def modify_application_html_erb_file
|
5
|
+
file_path = "app/views/layouts/application.html.erb"
|
6
|
+
inject_into_file "#{file_path}", "\n<div id=\"scajax\"></div>", after: "<%= yield %>"
|
7
|
+
end
|
8
|
+
#show.js.erb
|
9
|
+
def create_show_js_erb_file
|
10
|
+
create_file "app/views/#{plural_name}/show.js.erb", <<-FILE
|
11
|
+
$('#scajax').html("<%= escape_javascript(render 'show')%>")
|
12
|
+
FILE
|
13
|
+
end
|
14
|
+
#destroy.js.erb
|
15
|
+
def create_destroy_js_erb_file
|
16
|
+
create_file "app/views/#{plural_name}/destroy.js.erb", <<-FILE
|
17
|
+
$('table tr td').find('a[href="/#{plural_name}/<%= @#{plural_name.singularize}.id %>"]').parent().parent()
|
18
|
+
.remove();
|
19
|
+
$('#scajax').html('');
|
20
|
+
FILE
|
21
|
+
end
|
22
|
+
#edit.js.erb
|
23
|
+
def create_edit_js_erb_file
|
24
|
+
create_file "app/views/#{plural_name}/edit.js.erb", <<-FILE
|
25
|
+
$("#scajax").html("<%= escape_javascript(render 'form')%>");
|
26
|
+
FILE
|
27
|
+
end
|
28
|
+
#new.js.erb
|
29
|
+
def create_new_js_erb_file
|
30
|
+
create_file "app/views/#{plural_name}/new.js.erb", <<-FILE
|
31
|
+
$("#scajax").html("<%= escape_javascript(render 'form')%>");
|
32
|
+
FILE
|
33
|
+
end
|
34
|
+
#create.js.erb
|
35
|
+
def create_create_js_erb_file
|
36
|
+
create_file "app/views/#{plural_name}/create.js.erb", <<-FILE
|
37
|
+
$('table').append('<%= j render(@#{plural_name.singularize}) %>');
|
38
|
+
$("#scajax").html("<%= escape_javascript(render 'show', notice:
|
39
|
+
"#{plural_name.singularize.capitalize} created successful.") %>");
|
40
|
+
FILE
|
41
|
+
end
|
42
|
+
#update.js.erb
|
43
|
+
def create_update_js_erb_file
|
44
|
+
create_file "app/views/#{plural_name}/update.js.erb", <<-FILE
|
45
|
+
$('table tr td').find('a[href="/#{plural_name}/<%= @#{plural_name.singularize}.id %>"]').
|
46
|
+
parent().parent().replaceWith("<%= escape_javascript render(@#{plural_name.singularize}) %>");
|
47
|
+
$("#scajax").html("<%= escape_javascript(render 'show', notice: "Update successful.") %>");
|
48
|
+
FILE
|
49
|
+
end
|
50
|
+
#_show.html.erb
|
51
|
+
def create__show_html_erb_file
|
52
|
+
file_path = "app/views/#{plural_name}/show.html.erb"
|
53
|
+
file_in_array = IO.readlines(file_path)
|
54
|
+
file_in_array.each {|line| line.gsub!(/ ?, ?:remote=> ?true| ?, ?remote: ?true/,'')}
|
55
|
+
file_in_array.each_index do |i|
|
56
|
+
if (file_in_array[i].include?("link_to")) and (!file_in_array[i].match(/Back/i))
|
57
|
+
until file_in_array[i].sub!(/%>/,', :remote=> true %>')
|
58
|
+
i+=1
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
create_file "app/views/#{plural_name}/_show.html.erb","#{file_in_array.join}"
|
63
|
+
end
|
64
|
+
#resource_controller
|
65
|
+
def modify_controller #adding forma.js ir rails version <4
|
66
|
+
file_path = "app/controllers/#{plural_name}_controller.rb"
|
67
|
+
file_in_array = IO.readlines(file_path)
|
68
|
+
file_in_array.each_index do |i|
|
69
|
+
if (file_in_array[i] =~/format.json(.*)/)
|
70
|
+
if !file_in_array[i+1].include?('format.js')
|
71
|
+
file_in_array.insert(i+1," format.js")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
file = File.open(file_path,"w")
|
76
|
+
file.puts file_in_array
|
77
|
+
file.close
|
78
|
+
puts " \033[96mmodified \033[39m #{file_path}"
|
79
|
+
end
|
80
|
+
#index.htm.erb
|
81
|
+
def modify_index_file #add remote:true
|
82
|
+
file_path = "app/views/#{plural_name}/index.html.erb"
|
83
|
+
file_in_array = IO.readlines(file_path)
|
84
|
+
file_in_array.each {|line| line.gsub!(/ ?, ?:remote=> ?true| ?, ?remote: ?true/,'')}
|
85
|
+
file_in_array.each_index do |i|
|
86
|
+
if (file_in_array[i].include?("link_to")) and (!file_in_array[i].match(/Back/i))
|
87
|
+
until file_in_array[i].sub!(/%>/,', :remote=> true %>')
|
88
|
+
i+=1
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
file = File.open(file_path,"w")
|
93
|
+
file.puts file_in_array
|
94
|
+
file.close
|
95
|
+
puts " \033[96mmodified \033[39m #{file_path}"
|
96
|
+
end
|
97
|
+
#_form.html.erb
|
98
|
+
def modify__form_file #add remote:true
|
99
|
+
file_path = "app/views/#{plural_name}/_form.html.erb"
|
100
|
+
file_in_array = IO.readlines(file_path)
|
101
|
+
file_in_array.each {|line| line.gsub!(/ ?, ?:remote=> ?true| ?, ?remote: ?true/,'')}
|
102
|
+
file_in_array.each_index do |i|
|
103
|
+
if (file_in_array[i].include?("form_for"))
|
104
|
+
until file_in_array[i].sub!("@#{plural_name.singularize}","@#{plural_name.singularize}, :remote=> true")
|
105
|
+
i+=1
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
file = File.open(file_path,"w")
|
110
|
+
file.puts file_in_array
|
111
|
+
file.close
|
112
|
+
puts " \033[96mmodified \033[39m #{file_path}"
|
113
|
+
end
|
114
|
+
#_resource.html.erb
|
115
|
+
def create_instance_partial_html_erb_file
|
116
|
+
file_in_array = IO.readlines("app/views/#{plural_name}/index.html.erb")
|
117
|
+
start_copy, stop_copy = 0
|
118
|
+
file_in_array.each_index do |i|
|
119
|
+
if (file_in_array[i].include?("@#{plural_name.singularize}"))
|
120
|
+
start_copy = i+1
|
121
|
+
end
|
122
|
+
if (file_in_array[i].include?("<% end %>"))
|
123
|
+
stop_copy = i
|
124
|
+
|
125
|
+
end
|
126
|
+
end
|
127
|
+
out_file = []
|
128
|
+
(start_copy...stop_copy).each{|i| out_file<<file_in_array[i]}
|
129
|
+
out_file.each do |line|
|
130
|
+
line.gsub!(" #{plural_name.singularize}."," @#{plural_name.singularize}.")
|
131
|
+
line.gsub!("(#{plural_name.singularize}","(@#{plural_name.singularize}")
|
132
|
+
end
|
133
|
+
create_file "app/views/#{plural_name}/_#{plural_name.singularize}.html.erb","#{out_file.join}"
|
134
|
+
end
|
135
|
+
end
|
data/lib/scajax.rb
ADDED
data/scajax.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'scajax/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "scajax"
|
8
|
+
spec.version = Scajax::VERSION
|
9
|
+
spec.authors = ["Lucjan Stepien"]
|
10
|
+
spec.email = ["lucjanstepien@gmail.com"]
|
11
|
+
spec.description = %q{Simply ajaxify your scaffold}
|
12
|
+
spec.summary = %q{Ajax Generator for Scaffolds}
|
13
|
+
spec.homepage = "http://github.com/menuitem/scajax"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rails", "~> 3.2.0"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: scajax
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lucjan Stepien
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.2.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.2.0
|
55
|
+
description: Simply ajaxify your scaffold
|
56
|
+
email:
|
57
|
+
- lucjanstepien@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- CHANGELOG.md
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/generators/scajax/USAGE
|
69
|
+
- lib/generators/scajax/scajax_generator.rb
|
70
|
+
- lib/scajax.rb
|
71
|
+
- lib/scajax/version.rb
|
72
|
+
- scajax.gemspec
|
73
|
+
homepage: http://github.com/menuitem/scajax
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.0.6
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Ajax Generator for Scaffolds
|
97
|
+
test_files: []
|