script_flow 0.0.1 → 0.0.2
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.
- data/.gitignore +2 -14
- data/CHANGELOG +0 -0
- data/Gemfile +0 -0
- data/LICENSE.txt +0 -0
- data/README.md +0 -0
- data/Rakefile +0 -0
- data/lib/script_flow/controller.rb +24 -0
- data/lib/script_flow/engine.rb +4 -0
- data/lib/script_flow/helpers.rb +25 -0
- data/lib/script_flow/model/map.rb +36 -0
- data/lib/script_flow/railtie.rb +17 -0
- data/lib/script_flow/version.rb +1 -1
- data/lib/script_flow.rb +4 -4
- data/script_flow.gemspec +4 -4
- metadata +11 -5
data/.gitignore
CHANGED
data/CHANGELOG
ADDED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/LICENSE.txt
CHANGED
File without changes
|
data/README.md
CHANGED
File without changes
|
data/Rakefile
CHANGED
File without changes
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'script_flow/model/map'
|
2
|
+
|
3
|
+
module ScriptFlow
|
4
|
+
module ControllerExtension
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
helper_method :script_flow
|
9
|
+
end
|
10
|
+
|
11
|
+
def script_flow
|
12
|
+
@script_flow ||= ScriptFlow::Map.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def _render_template(options)
|
16
|
+
if lookup_context.rendered_format == :js
|
17
|
+
super + script_flow.render
|
18
|
+
else
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module ScriptFlow
|
2
|
+
module Helpers
|
3
|
+
|
4
|
+
def script(content = nil, &block)
|
5
|
+
if content || block_given?
|
6
|
+
if block_given?
|
7
|
+
content = capture(&block)
|
8
|
+
end
|
9
|
+
if content
|
10
|
+
if request.xhr?
|
11
|
+
script_flow.add_script(content)
|
12
|
+
nil
|
13
|
+
else
|
14
|
+
javascript_tag(content)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def script_for(identifier, content = nil, &block)
|
21
|
+
content_for(identifier, script(content, &block))
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module ScriptFlow
|
2
|
+
class Map
|
3
|
+
attr_reader :content
|
4
|
+
|
5
|
+
delegate :any?, :empty?, :to => :content
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@content = ActiveSupport::OrderedHash.new { |h,k| h[k] = ActiveSupport::SafeBuffer.new }
|
9
|
+
end
|
10
|
+
|
11
|
+
# Called by _layout_for to read stored values.
|
12
|
+
def get(key)
|
13
|
+
@content[key]
|
14
|
+
end
|
15
|
+
|
16
|
+
# Called by each renderer object to set the layout contents.
|
17
|
+
def set(key, value)
|
18
|
+
@content[key] = value
|
19
|
+
end
|
20
|
+
|
21
|
+
# Called by content_for
|
22
|
+
def append(key, value)
|
23
|
+
@content[key] << value
|
24
|
+
end
|
25
|
+
alias_method :append!, :append
|
26
|
+
|
27
|
+
def add_script(script)
|
28
|
+
set(script.hash, script)
|
29
|
+
end
|
30
|
+
|
31
|
+
def render
|
32
|
+
@content.values.join("\n").html_safe
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
module ScriptFlow
|
4
|
+
class Railtie < ::Rails::Railtie
|
5
|
+
config.before_initialize do
|
6
|
+
ActiveSupport.on_load(:action_view) do
|
7
|
+
require 'script_flow/helpers'
|
8
|
+
include Helpers
|
9
|
+
end
|
10
|
+
ActiveSupport.on_load(:action_controller) do
|
11
|
+
require 'script_flow/controller'
|
12
|
+
include ControllerExtension
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/lib/script_flow/version.rb
CHANGED
data/lib/script_flow.rb
CHANGED
data/script_flow.gemspec
CHANGED
@@ -8,15 +8,15 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = ScriptFlow::VERSION
|
9
9
|
gem.authors = ["Valery Kvon"]
|
10
10
|
gem.email = ["addagger@gmail.com"]
|
11
|
-
gem.description = %q{
|
12
|
-
gem.summary = %q{
|
11
|
+
gem.description = %q{When you rendering the ERB templates/partials, utility remembers javascript syntax and add it to the end of JS response body}
|
12
|
+
gem.summary = %q{Auto load script from rendered ERB during Ajax request}
|
13
13
|
gem.homepage = ""
|
14
|
-
|
14
|
+
gem.homepage = %q{http://vkvon.ru/projects/script_flow}
|
15
15
|
|
16
16
|
gem.files = `git ls-files`.split($/)
|
17
17
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
20
|
-
|
20
|
+
gem.licenses = ['MIT']
|
21
21
|
|
22
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: script_flow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,9 +9,10 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-04 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
14
|
+
description: When you rendering the ERB templates/partials, utility remembers javascript
|
15
|
+
syntax and add it to the end of JS response body
|
15
16
|
email:
|
16
17
|
- addagger@gmail.com
|
17
18
|
executables: []
|
@@ -19,11 +20,17 @@ extensions: []
|
|
19
20
|
extra_rdoc_files: []
|
20
21
|
files:
|
21
22
|
- .gitignore
|
23
|
+
- CHANGELOG
|
22
24
|
- Gemfile
|
23
25
|
- LICENSE.txt
|
24
26
|
- README.md
|
25
27
|
- Rakefile
|
26
28
|
- lib/script_flow.rb
|
29
|
+
- lib/script_flow/controller.rb
|
30
|
+
- lib/script_flow/engine.rb
|
31
|
+
- lib/script_flow/helpers.rb
|
32
|
+
- lib/script_flow/model/map.rb
|
33
|
+
- lib/script_flow/railtie.rb
|
27
34
|
- lib/script_flow/version.rb
|
28
35
|
- script_flow.gemspec
|
29
36
|
homepage: http://vkvon.ru/projects/script_flow
|
@@ -50,6 +57,5 @@ rubyforge_project:
|
|
50
57
|
rubygems_version: 1.8.24
|
51
58
|
signing_key:
|
52
59
|
specification_version: 3
|
53
|
-
summary:
|
54
|
-
syntax and add it to the end of JS response body
|
60
|
+
summary: Auto load script from rendered ERB during Ajax request
|
55
61
|
test_files: []
|