simplesnippets 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in simplesnippets.gemspec
4
+ gemspec
5
+
6
+
7
+ gem 'RedCloth'
@@ -0,0 +1,11 @@
1
+ h1. Snippets
2
+
3
+ <%= snippet('intro') %>
4
+
5
+ <%= snippet('intro') do %>
6
+ This is some default introduction.
7
+ The client will take it from here.
8
+ <% end %>
9
+
10
+ Copyright (c) 2008 Damian Janowski for CitrusByte, released under the MIT license
11
+
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,7 @@
1
+ require 'snippet'
2
+ require 'simplesnippets/parsers/html'
3
+ require 'simplesnippets/parsers/plain_text'
4
+ require 'simplesnippets/parsers/textile'
5
+
6
+ module Simplesnippets
7
+ end
@@ -0,0 +1,8 @@
1
+ module Simplesnippets
2
+ module Helper
3
+ def snippet(slug, options = {}, &block)
4
+ text = capture(&block) if block_given?
5
+ Snippet.get(slug, {:text => text}.merge(options))
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ module Simplesnippets
2
+ module Parsers
3
+ class Html
4
+ def self.parse(text)
5
+ text.to_s
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ require 'erb'
2
+
3
+ module Simplesnippets
4
+ module Parsers
5
+ class PlainText
6
+ def self.parse(text)
7
+ ERB::Util.h(text)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ unless defined?(RedCloth)
2
+ gem 'RedCloth'
3
+ require 'RedCloth'
4
+ end
5
+
6
+ module Simplesnippets
7
+ module Parsers
8
+ class Textile
9
+ def self.parse(text)
10
+ textilized = RedCloth.new(text, [ :hard_breaks ])
11
+ textilized.hard_breaks = true if textilized.respond_to?("hard_breaks=")
12
+ textilized.to_html
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Simplesnippets
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,64 @@
1
+ class Snippet < ActiveRecord::Base
2
+ validates_uniqueness_of :slug
3
+ validates_presence_of :slug
4
+
5
+ before_save :compile_text
6
+
7
+ class << self
8
+ def get(slug, options = {})
9
+ snippet = find_by_slug(slug.to_s.downcase) || create!(options.merge(:slug => slug))
10
+ end
11
+
12
+ def parse(text, parser = nil)
13
+ parser = Snippet.default_parser if parser.blank?
14
+ klass = Simplesnippets::Parsers.const_get(parser.to_s.classify)
15
+ klass.parse(text)
16
+ end
17
+
18
+ def default_parser
19
+ 'html'
20
+ end
21
+ end
22
+
23
+ def to_s
24
+ compiled_text.to_s
25
+ end
26
+
27
+ def %(*args)
28
+ if args.size == 1 && args.first.kind_of?(Hash)
29
+ text = to_s
30
+
31
+ args.first.each do |key,value|
32
+ text = text.gsub("{{#{key}}}", value)
33
+ end
34
+
35
+ text
36
+ else
37
+ sprintf(to_s, *args)
38
+ end
39
+ end
40
+
41
+ def empty?
42
+ to_s.empty?
43
+ end
44
+
45
+ def blank?
46
+ to_s.blank?
47
+ end
48
+
49
+ def inspect
50
+ to_s.inspect
51
+ end
52
+
53
+ def ==(other)
54
+ to_s.eql?(other)
55
+ end
56
+
57
+ private
58
+
59
+ def compile_text
60
+ self.parser = Snippet.default_parser if parser.blank?
61
+ self.compiled_text = Snippet.parse(text, parser)
62
+ end
63
+
64
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "simplesnippets/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "simplesnippets"
7
+ s.version = Simplesnippets::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Andy Schmidt, Damian Janowski"]
10
+ s.email = ["andyschmidtatwork@gmail.com"]
11
+ s.homepage = "http://rubygems.org/gems/simplesnippets"
12
+ s.summary = %q{Include snippets of content in your Rails views and let the client modify them.}
13
+ s.description = %q{All credit for this code goes to Damian Janowski. I've simply moved this into a Rails 3 compatible gem.'}
14
+
15
+ s.rubyforge_project = "simplesnippets"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency "rails", "3.0.1"
23
+ s.add_dependency "RedCloth"
24
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simplesnippets
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
11
+ platform: ruby
12
+ authors:
13
+ - Andy Schmidt, Damian Janowski
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-19 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rails
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - "="
28
+ - !ruby/object:Gem::Version
29
+ hash: 5
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 1
34
+ version: 3.0.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: RedCloth
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ description: All credit for this code goes to Damian Janowski. I've simply moved this into a Rails 3 compatible gem.'
52
+ email:
53
+ - andyschmidtatwork@gmail.com
54
+ executables: []
55
+
56
+ extensions: []
57
+
58
+ extra_rdoc_files: []
59
+
60
+ files:
61
+ - .gitignore
62
+ - Gemfile
63
+ - README.textile
64
+ - Rakefile
65
+ - lib/simplesnippets.rb
66
+ - lib/simplesnippets/helper.rb
67
+ - lib/simplesnippets/parsers/html.rb
68
+ - lib/simplesnippets/parsers/plain_text.rb
69
+ - lib/simplesnippets/parsers/textile.rb
70
+ - lib/simplesnippets/version.rb
71
+ - lib/snippet.rb
72
+ - simplesnippets.gemspec
73
+ has_rdoc: true
74
+ homepage: http://rubygems.org/gems/simplesnippets
75
+ licenses: []
76
+
77
+ post_install_message:
78
+ rdoc_options: []
79
+
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ requirements: []
101
+
102
+ rubyforge_project: simplesnippets
103
+ rubygems_version: 1.3.7
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: Include snippets of content in your Rails views and let the client modify them.
107
+ test_files: []
108
+