jquery_expand_assets 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ 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
18
+ tags
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in expand_assets.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Matt Fletcher
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,53 @@
1
+ # jquery.expand assets
2
+
3
+ A Sprockets processor that wraps html in a jquery.expand function. It is specifically meant to work within the Rails asset pipeline.
4
+
5
+ The processor outputs CoffeeScript, so you'll need to have the result be processed by the CoffeeScript processor.
6
+
7
+ ## Creating and using templates
8
+
9
+ Create your templates in a directory named `app/assets/javascripts/templates`. Organize your templats within subdirectories. I personally organize them based on what resource they're associated with.
10
+
11
+ Write your template and wrap it in a root element.
12
+
13
+ Example: `app/assets/javascripts/templates/articles/_entry.js.coffee.expand`
14
+ <div>
15
+ <h2 class='name'></h2>
16
+ <p class='content'></p>
17
+ </div>
18
+
19
+ Your template is now available to Javascript as a function on the `JST` object. Pass an expand directive to the function and you'll be given the result minus the wrapper element.
20
+
21
+ Example: see `articles/_entry.js.coffee.expand` above
22
+ directive = { name: 'Joe', content: 'I love Smurfs.' }
23
+ html = JST['articles/entry'](directive)
24
+ $('body').append(html)
25
+
26
+ In this example, the result html will be:
27
+ <h2 class='name'>Joe<h2>
28
+ <p class='content'>I love Smurfs.</p>
29
+
30
+ ## Naming conventions
31
+
32
+ Templates are named on the `JST` object based on their filename. Directories under `app/assets/javascripts/templates` are preserved. If the template's filename starts with an underscore, the underscore is removed from the name.
33
+
34
+ Examples:
35
+
36
+ `articles/_entry.js.coffee.expand` becomes `articles/entry`
37
+ `articles/comments/_comment.js.coffee.expand` becomes `articles/comments/comment`
38
+ `articles/response.js.coffee.expand` becomes `articles/response`
39
+
40
+ ## Resources
41
+
42
+ * [jquery.expand](https://github.com/atomicobject/jquery.expand)
43
+ * [jquery.expand examples](http://spin.atomicobject.com/2011/07/10/jquery-expand-examples/)
44
+
45
+ ## Thanks so much!
46
+
47
+ I'd like to give a huge 'thank you' to the [Sprockets](https://github.com/sstephenson/sprockets), [haml_assets](https://github.com/infbio/haml_assets), and [haml_coffee_assets](https://github.com/netzpirat/haml_coffee_assets) projects. Without their examples, I'm not sure I would have figured out the code required to create the Rails engine and Tilt template.
48
+
49
+ Authors
50
+ =======
51
+ * Matt Fletcher (fletcher@atomicobject.com)
52
+ * © 2012 [Atomic Object](http://www.atomicobject.com/)
53
+ * More Atomic Object [open source](http://www.atomicobject.com/pages/Software+Commons) projects
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs = %w[ lib ]
7
+ t.warning = true
8
+ t.verbose = true
9
+ t.test_files = FileList['test/*_test.rb']
10
+ end
11
+
12
+ task default: :test
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/jquery_expand_assets/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Matt Fletcher"]
6
+ gem.email = ["fletcher@atomicobject.com"]
7
+ gem.description = %q{Sprockets processor for jquery.expand templates}
8
+ gem.summary = %q{Sprockets processor for jquery.expand templates}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "jquery_expand_assets"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = JqueryExpandAssets::VERSION
17
+
18
+ gem.add_runtime_dependency 'tilt', '~>1'
19
+
20
+ gem.add_development_dependency 'rake', '~>0.9'
21
+ gem.add_development_dependency 'minitest', '~>3'
22
+ end
@@ -0,0 +1,8 @@
1
+ module JqueryExpandAssets
2
+ class Engine < ::Rails::Engine
3
+ initializer "sprockets.jquery-expand", :after => "sprockets.environment", :group => :all do |app|
4
+ next unless app.assets
5
+ app.assets.register_engine('.expand', JqueryExpandProcessor)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,22 @@
1
+ require 'tilt'
2
+
3
+ module JqueryExpandAssets
4
+ class JqueryExpandProcessor < Tilt::Template
5
+ # implemented for the superclass's template method
6
+ def prepare; end
7
+
8
+ def evaluate(scope, locals, &block)
9
+ name = scope.logical_path.sub(/^templates\//, '').sub(%r{/?_(.*)$}, '/\1')
10
+ <<-COFFEE
11
+ this.JST ||= {}
12
+ template = null
13
+ html = """
14
+ #{data}
15
+ """
16
+ this.JST[#{name.inspect}] = (directive) ->
17
+ template ||= $(html)
18
+ template.expand(directive).children()
19
+ COFFEE
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module JqueryExpandAssets
2
+ VERSION = '0.0.3'
3
+ end
@@ -0,0 +1,6 @@
1
+ require 'jquery_expand_assets/version'
2
+ require 'jquery_expand_assets/engine'
3
+
4
+ module JqueryExpandAssets
5
+ autoload :JqueryExpandProcessor, 'jquery_expand_assets/jquery_expand_processor'
6
+ end
@@ -0,0 +1,54 @@
1
+ require 'minitest/autorun'
2
+ require 'ostruct'
3
+ require 'jquery_expand_assets/jquery_expand_processor'
4
+
5
+ class JqueryExpandProcessorTest < MiniTest::Unit::TestCase
6
+ def test_wraps_content_with_expand_function
7
+ result = process content: "<p><div>butters cookies</div></p>"
8
+
9
+ assert_match "<p><div>butters cookies</div></p>", result
10
+ assert_match %r{\.expand\(directive\)\.children\(\)}, result
11
+ end
12
+
13
+ def test_names_the_template_after_the_file_name
14
+ result = process filename: 'templates/projects/_comment'
15
+
16
+ assert_match 'this.JST["projects/comment"]', result
17
+ end
18
+
19
+ def test_handles_file_names_with_multiple_levels_of_nesting
20
+ result = process filename: 'templates/projects/comments/concerns/_alert'
21
+
22
+ assert_match 'this.JST["projects/comments/concerns/alert"]', result
23
+ end
24
+
25
+ def test_does_not_yet_handle_file_names_with_one_level_of_nesting
26
+ result = process filename: 'templates/_comment'
27
+
28
+ refute_match 'this.JST["comment"]', result
29
+ end
30
+
31
+ def test_handles_template_names_without_leading_underscore
32
+ result = process filename: 'templates/users/avatar'
33
+
34
+ assert_match 'this.JST["users/avatar"]', result
35
+ end
36
+
37
+ private
38
+ def process(optz)
39
+ content, filename = optz.values_at(:content, :filename)
40
+ content ||= "<b>grover</b>"
41
+ filename ||= "butters/_cookies"
42
+
43
+ processor = JqueryExpandAssets::JqueryExpandProcessor.new do content end
44
+ processor.evaluate(os(logical_path: filename), nil)
45
+ end
46
+
47
+ def build_with_content(content='')
48
+ JqueryExpandAssets::JqueryExpandProcessor.new do content end
49
+ end
50
+ alias_method :build, :build_with_content
51
+
52
+ def scope(logical_path = ''); os(logical_path: logical_path); end
53
+ def os(*args); OpenStruct.new(*args); end
54
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jquery_expand_assets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matt Fletcher
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: tilt
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '0.9'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '0.9'
46
+ - !ruby/object:Gem::Dependency
47
+ name: minitest
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3'
62
+ description: Sprockets processor for jquery.expand templates
63
+ email:
64
+ - fletcher@atomicobject.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE
72
+ - README.md
73
+ - Rakefile
74
+ - jquery_expand_assets.gemspec
75
+ - lib/jquery_expand_assets.rb
76
+ - lib/jquery_expand_assets/engine.rb
77
+ - lib/jquery_expand_assets/jquery_expand_processor.rb
78
+ - lib/jquery_expand_assets/version.rb
79
+ - test/jquery_expand_processor_test.rb
80
+ homepage: ''
81
+ licenses: []
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ segments:
93
+ - 0
94
+ hash: -3627693289123550229
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ segments:
102
+ - 0
103
+ hash: -3627693289123550229
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 1.8.24
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: Sprockets processor for jquery.expand templates
110
+ test_files:
111
+ - test/jquery_expand_processor_test.rb