snippetize 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 16288e774d1e8f03ed8c4dcc9f86500a354a1869
4
+ data.tar.gz: db0a56fa7f2379bf4e8d3d5f310150b6dbdc4b7f
5
+ SHA512:
6
+ metadata.gz: 5d715d1306b85d7ce619835c27ff3d9d484f8b717bd8748919c53a1fccc1cb77304c3648445e5abc73073fe9e1d0eeb0e3d7d0bcd9f599b1b06f1a31e83cda68
7
+ data.tar.gz: 1b84d0ea2aa4e6c54cb397db7c14d1e06f7c17612919341a07cec96d9b5eef29b8a392001d35ff9a7442928bdf24b800d1cd178f3991270c362567b22a352cd5
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/README.md CHANGED
@@ -1,14 +1,20 @@
1
1
  # Snippetize
2
2
 
3
- Snippetize allows you to include re-usable code and partials in html or plain text fields. Stay dry and reuse your partials using shortcode. Use it for including forms, videos, maps or simply preformated html snippets.
3
+ Snippetize allows you to include partials in html or plain text fields. Stay dry and reuse your partials using shortcode. Use it for including forms, videos, maps or simply preformated html snippets.
4
4
 
5
5
  ## Why
6
6
 
7
- If you want dynamic partials to be displayed and you save your html output to a, let's say, a content column of a Article instance.
7
+ If you want users to be able to add partials without editing html.
8
8
 
9
+ So this:
10
+ ```ruby
9
11
  Article.new(content: "<div class='widget'>I need my awesome widget that displays everywhere on the site.</div>")
12
+ ```
10
13
 
11
- Or sometimes you want a form and want to keep the authentication token for instance or any ruby code that has to stay dynamic and can't be kept static in the database.
14
+ Becomes:
15
+ ```ruby
16
+ Article.new(content: "{{widget}}")
17
+ ```
12
18
 
13
19
  ## Installation
14
20
 
@@ -44,10 +50,15 @@ The result could look like this:
44
50
 
45
51
  "<div class='widget'><div class='my-awesome-widget'>This lives in my partial.</div></div>"
46
52
 
53
+ You can also pass variables to you partial like you would normaly to a partial
54
+
55
+ text = "<div class='widget'>{{awesome_widget, count: 2, category: test}}</div>"
56
+
47
57
  ## Contributing
48
58
 
49
59
  1. Fork it
50
60
  2. Create your feature branch (`git checkout -b my-new-feature`)
51
- 3. Commit your changes (`git commit -am 'Add some feature'`)
52
- 4. Push to the branch (`git push origin my-new-feature`)
53
- 5. Create new Pull Request
61
+ 3. Test your changes (`rspec spec`)
62
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
63
+ 5. Push to the branch (`git push origin my-new-feature`)
64
+ 6. Create new Pull Request
@@ -1,13 +1,27 @@
1
1
  module Snippetize
2
- class Snippet
2
+ class Snippet
3
3
 
4
- attr_accessor :partial, :path, :locals
4
+ attr_accessor :partial, :locals
5
5
 
6
- def initialize(snippet)
7
- @partial, params = snippet.split(/[\s]/, 2)
8
- @locals = Rack::Utils.parse_nested_query(params).try(:symbolize_keys!)
9
- @path = "#{Snippetize.location}/#{@partial}"
10
- end
6
+ def initialize(snippet_value)
7
+ values = snippet_value.split(',')
8
+ @partial = values[0]
9
+ @locals = Snippet.parse_locals values[1..-1]
10
+ end
11
11
 
12
- end
12
+ def self.parse_locals locals={}
13
+ hash = {}
14
+ return hash if locals.nil?
15
+ locals.each do |option|
16
+ options = option.split(':')
17
+ key = options[0].strip.to_sym
18
+ hash[key] = options[1].strip.to_s
19
+ end
20
+ hash
21
+ end
22
+
23
+ def path
24
+ "#{Snippetize.location}/#{@partial}"
25
+ end
26
+ end
13
27
  end
@@ -1,3 +1,3 @@
1
1
  module Snippetize
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/snippetize.rb CHANGED
@@ -4,26 +4,11 @@ require 'snippetize/action_view_extensions/snippetize_helper'
4
4
 
5
5
  module Snippetize
6
6
 
7
- mattr_accessor :delimiters
8
- @@delimiters = %w({ })
9
-
10
7
  mattr_accessor :location
11
8
  @@location = 'snippets'
12
9
 
13
- mattr_accessor :templating_engine
14
- @@templating_engine = 'erb'
15
-
16
10
  def self.setup
17
11
  yield self
18
12
  end
19
13
 
20
- protected
21
-
22
- def start_delimiter
23
- @start_delimiter ||= Snippetize.delimiters[0]
24
- end
25
-
26
- def end_delimiter
27
- @end_delimiter ||= Snippetize.delimiters[1]
28
- end
29
14
  end
data/snippetize.gemspec CHANGED
@@ -6,7 +6,7 @@ require 'snippetize/version'
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "snippetize"
8
8
  gem.version = Snippetize::VERSION
9
- gem.authors = ["Mathieu Gagné"]
9
+ gem.authors = ["Mathieu Gagné", "Alexandre Croteau-Pothier"]
10
10
  gem.email = ["mathieu@motioneleven.com"]
11
11
  gem.description = %q{Ruby gem allowing you to include re-usable code and partials in html or plain text fields.}
12
12
  gem.summary = %q{Ruby gem allowing you to include re-usable code and partials in html or plain text fields. Stay dry and reuse your partials using shortcode. Use it for including forms, videos, maps or simply preformated html snippets.}
@@ -16,4 +16,9 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency 'rspec'
21
+ gem.add_development_dependency 'active_support'
22
+ gem.add_development_dependency 'rack'
23
+ gem.add_development_dependency 'actionpack'
19
24
  end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ include Snippetize::ActionViewExtensions::SnippetizeHelper
3
+
4
+ describe Snippetize::ActionViewExtensions::SnippetizeHelper do
5
+ before :each do
6
+ @view = ActionView::Base.new
7
+ @view.stub :render
8
+ end
9
+
10
+ it "should treat nil as an empty string" do
11
+ snippetize().should eq("")
12
+ end
13
+
14
+ it "should render the corresponding partial" do
15
+ @view.should_receive(:render).with({partial: "snippets/test", locals: {}})
16
+ @view.snippetize("one two {{test}} three")
17
+ end
18
+
19
+ it "should render multiple partials" do
20
+ @view.should_receive(:render).twice
21
+ @view.snippetize("one two {{test}} three {{test2}}")
22
+ end
23
+
24
+ it "should pass the local variables" do
25
+ @view.should_receive(:render).with({partial: "snippets/test", locals: {count: "2", tag: "test"}})
26
+ @view.snippetize("one two {{test, count: 2, tag: test}} three")
27
+ end
28
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Snippetize::Snippet do
4
+
5
+ describe '.new' do
6
+ it "should create a new instance" do
7
+ Snippetize::Snippet.new("test").should be_a Snippetize::Snippet
8
+ end
9
+
10
+ it "should create a path form the string" do
11
+ Snippetize::Snippet.new("test").path.should eq("snippets/test")
12
+ end
13
+
14
+ it "should store the locals in a hash" do
15
+ Snippetize::Snippet.new("test, one: one, two: two").locals.should eq({one:"one", two:"two"})
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ RSpec.configure do |config|
2
+ config.treat_symbols_as_metadata_keys_with_true_values = true
3
+ config.run_all_when_everything_filtered = true
4
+ config.filter_run :focus
5
+
6
+ config.order = 'random'
7
+ end
8
+
9
+ require 'active_support/core_ext/module'
10
+ require 'active_support/core_ext/class'
11
+ require 'active_support/core_ext/hash'
12
+ require 'action_view'
13
+ require 'rack/utils'
14
+
15
+ require_relative '../lib/snippetize.rb'
metadata CHANGED
@@ -1,16 +1,72 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snippetize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
- prerelease:
4
+ version: 0.0.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mathieu Gagné
8
+ - Alexandre Croteau-Pothier
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-07 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2013-07-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: active_support
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rack
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: actionpack
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
14
70
  description: Ruby gem allowing you to include re-usable code and partials in html
15
71
  or plain text fields.
16
72
  email:
@@ -20,6 +76,7 @@ extensions: []
20
76
  extra_rdoc_files: []
21
77
  files:
22
78
  - .gitignore
79
+ - .rspec
23
80
  - Gemfile
24
81
  - LICENSE.txt
25
82
  - README.md
@@ -29,30 +86,35 @@ files:
29
86
  - lib/snippetize/snippet.rb
30
87
  - lib/snippetize/version.rb
31
88
  - snippetize.gemspec
89
+ - spec/lib/snippetize/action_view_extensions/snippetize_helper_spec.rb
90
+ - spec/lib/snippetize/snippet_spec.rb
91
+ - spec/spec_helper.rb
32
92
  homepage: https://github.com/motioneleven/snippetize
33
93
  licenses: []
94
+ metadata: {}
34
95
  post_install_message:
35
96
  rdoc_options: []
36
97
  require_paths:
37
98
  - lib
38
99
  required_ruby_version: !ruby/object:Gem::Requirement
39
- none: false
40
100
  requirements:
41
- - - ! '>='
101
+ - - '>='
42
102
  - !ruby/object:Gem::Version
43
103
  version: '0'
44
104
  required_rubygems_version: !ruby/object:Gem::Requirement
45
- none: false
46
105
  requirements:
47
- - - ! '>='
106
+ - - '>='
48
107
  - !ruby/object:Gem::Version
49
108
  version: '0'
50
109
  requirements: []
51
110
  rubyforge_project:
52
- rubygems_version: 1.8.18
111
+ rubygems_version: 2.0.3
53
112
  signing_key:
54
- specification_version: 3
113
+ specification_version: 4
55
114
  summary: Ruby gem allowing you to include re-usable code and partials in html or plain
56
115
  text fields. Stay dry and reuse your partials using shortcode. Use it for including
57
116
  forms, videos, maps or simply preformated html snippets.
58
- test_files: []
117
+ test_files:
118
+ - spec/lib/snippetize/action_view_extensions/snippetize_helper_spec.rb
119
+ - spec/lib/snippetize/snippet_spec.rb
120
+ - spec/spec_helper.rb