snippetize 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +25 -1
- data/lib/snippetize/action_view_extensions/snippetize_helper.rb +4 -2
- data/lib/snippetize/version.rb +1 -1
- data/snippetize.gemspec +2 -2
- metadata +4 -4
data/README.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
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.
|
4
4
|
|
5
|
+
## Why
|
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.
|
8
|
+
|
9
|
+
Article.new(content: "<div class='widget'>I need my awesome widget that displays everywhere on the site.</div>")
|
10
|
+
|
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.
|
12
|
+
|
5
13
|
## Installation
|
6
14
|
|
7
15
|
Add this line to your application's Gemfile:
|
@@ -16,9 +24,25 @@ Or install it yourself as:
|
|
16
24
|
|
17
25
|
$ gem install snippetize
|
18
26
|
|
27
|
+
## Defaults
|
28
|
+
|
29
|
+
All partials will be taken from a `snippets` folder in views. For instance, `{{awesome_widget}}` assumes you have the following file:
|
30
|
+
|
31
|
+
app/views/snippets/_awesome_widget.html.erb
|
32
|
+
|
19
33
|
## Usage
|
20
34
|
|
21
|
-
{
|
35
|
+
Insert the name of the partial within double brackets `{{}}`
|
36
|
+
|
37
|
+
text = "<div class='widget'>{{awesome_widget}}</div>"
|
38
|
+
|
39
|
+
Call `snippetize` and pass it your string
|
40
|
+
|
41
|
+
snippetize(text).html_safe
|
42
|
+
|
43
|
+
The result could look like this:
|
44
|
+
|
45
|
+
"<div class='widget'><div class='my-awesome-widget'>This lives in my partial.</div></div>"
|
22
46
|
|
23
47
|
## Contributing
|
24
48
|
|
@@ -2,8 +2,10 @@ module Snippetize
|
|
2
2
|
module ActionViewExtensions
|
3
3
|
module SnippetizeHelper
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
# Renders the first expression within double brackets {{}} as a partial
|
6
|
+
# Other variables are passed as parameters to the partial
|
7
|
+
def snippetize string=''
|
8
|
+
string.gsub(/\{\{(.*?)\}\}/) do |s|
|
7
9
|
snippet = Snippetize::Snippet.new($1)
|
8
10
|
render partial: snippet.path, locals: snippet.locals
|
9
11
|
end
|
data/lib/snippetize/version.rb
CHANGED
data/snippetize.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = Snippetize::VERSION
|
9
9
|
gem.authors = ["Mathieu Gagné"]
|
10
10
|
gem.email = ["mathieu@motioneleven.com"]
|
11
|
-
gem.description = %q{
|
12
|
-
gem.summary = %q{
|
11
|
+
gem.description = %q{Ruby gem allowing you to include re-usable code and partials in html or plain text fields.}
|
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.}
|
13
13
|
gem.homepage = "https://github.com/motioneleven/snippetize"
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snippetize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,9 +9,9 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-07 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
14
|
+
description: Ruby gem allowing you to include re-usable code and partials in html
|
15
15
|
or plain text fields.
|
16
16
|
email:
|
17
17
|
- mathieu@motioneleven.com
|
@@ -52,7 +52,7 @@ rubyforge_project:
|
|
52
52
|
rubygems_version: 1.8.18
|
53
53
|
signing_key:
|
54
54
|
specification_version: 3
|
55
|
-
summary:
|
55
|
+
summary: Ruby gem allowing you to include re-usable code and partials in html or plain
|
56
56
|
text fields. Stay dry and reuse your partials using shortcode. Use it for including
|
57
57
|
forms, videos, maps or simply preformated html snippets.
|
58
58
|
test_files: []
|