script_flow 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,17 +1,5 @@
1
+ .DS_Store
1
2
  *.gem
2
- *.rbc
3
3
  .bundle
4
- .config
5
- .yardoc
6
4
  Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
5
+ pkg/*
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,4 @@
1
+ module ScriptFlow #:nodoc:
2
+ class Engine < ::Rails::Engine #:nodoc:
3
+ end
4
+ 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
@@ -1,3 +1,3 @@
1
1
  module ScriptFlow
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/script_flow.rb CHANGED
@@ -2,9 +2,9 @@ require "script_flow/version"
2
2
 
3
3
  module ScriptFlow
4
4
  def self.load!
5
- require 'script_flow/engine'
6
- require 'script_flow/railtie'
7
- end
5
+ require 'script_flow/engine'
6
+ require 'script_flow/railtie'
7
+ end
8
8
  end
9
9
 
10
- Script.load!
10
+ ScriptFlow.load!
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{Auto load script from rendered ERB during JS runtime}
12
- gem.summary = %q{When you rendering the ERB templates/partials, utility remembers javascript syntax and add it to the end of JS response body }
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
- gem.homepage = %q{http://vkvon.ru/projects/script_flow}
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
- gem.licenses = ['MIT']
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.1
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: 2012-12-08 00:00:00.000000000 Z
12
+ date: 2013-01-04 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: Auto load script from rendered ERB during JS runtime
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: When you rendering the ERB templates/partials, utility remembers javascript
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: []