djanowski-snippets 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Damian Janowski for CitrusByte.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,10 @@
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
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require 'spec/rake/spectask'
5
+
6
+ gem_spec_file = 'snippets.gemspec'
7
+
8
+ gem_spec = eval(File.read(gem_spec_file)) rescue nil
9
+
10
+ desc 'Default: run all specs.'
11
+ task :default => :spec
12
+
13
+ desc "Run all specs in spec directory (excluding plugin specs)"
14
+ Spec::Rake::SpecTask.new(:spec) do |t|
15
+ # t.spec_opts = ['--options', File.join(File.dirname(__FILE__), 'spec', 'spec.opts')]
16
+ t.spec_files = FileList['spec/**/*_spec.rb']
17
+ end
18
+
19
+ desc 'Generate documentation for the snippets plugin.'
20
+ Rake::RDocTask.new(:rdoc) do |rdoc|
21
+ rdoc.rdoc_dir = 'rdoc'
22
+ rdoc.title = 'Snippets'
23
+ rdoc.options << '--line-numbers' << '--inline-source'
24
+ rdoc.rdoc_files.include('README.textile')
25
+ rdoc.rdoc_files.include('lib/**/*.rb')
26
+ end
27
+
28
+ desc "Generate the gemspec file."
29
+ task :gemspec do
30
+ require 'erb'
31
+
32
+ File.open(gem_spec_file, 'w') do |f|
33
+ f.write ERB.new(File.read("#{gem_spec_file}.erb")).result(binding)
34
+ end
35
+ end
data/lib/snippet.rb ADDED
@@ -0,0 +1,26 @@
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
+ snippet.compiled_text.to_s if snippet
11
+ end
12
+
13
+ def parse(text, parser = nil)
14
+ parser = 'html' if parser.blank?
15
+ klass = Snippets::Parsers.const_get(parser.to_s.classify)
16
+ klass.parse(text)
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def compile_text
23
+ self.compiled_text = Snippet.parse(text, parser)
24
+ end
25
+
26
+ end
data/lib/snippets.rb ADDED
@@ -0,0 +1,2 @@
1
+ module Snippets
2
+ end
@@ -0,0 +1,8 @@
1
+ module Snippets
2
+ module Helper
3
+ def snippet(slug, &block)
4
+ text = capture(&block) if block_given?
5
+ Snippet.get(slug, :text => text)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ require 'erb'
2
+
3
+ module Snippets
4
+ module Parsers
5
+ class Html
6
+ def self.parse(text)
7
+ ERB::Util.h(text)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ gem 'RedCloth'
2
+ require 'RedCloth'
3
+
4
+ module Snippets
5
+ module Parsers
6
+ class Textile
7
+ def self.parse(text)
8
+ textilized = RedCloth.new(text, [ :hard_breaks ])
9
+ textilized.hard_breaks = true if textilized.respond_to?("hard_breaks=")
10
+ textilized.to_html
11
+ end
12
+ end
13
+ end
14
+ end
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ ActionView::Base.send(:include, Snippets::Helper)
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: djanowski-snippets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Damian Janowski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-06 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: ""
17
+ email: damian.janowski@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.textile
24
+ files:
25
+ - lib/snippet.rb
26
+ - lib/snippets/helper.rb
27
+ - lib/snippets/parsers/html.rb
28
+ - lib/snippets/parsers/textile.rb
29
+ - lib/snippets.rb
30
+ - rails/init.rb
31
+ - README.textile
32
+ - MIT-LICENSE
33
+ - Rakefile
34
+ has_rdoc: true
35
+ homepage:
36
+ post_install_message:
37
+ rdoc_options:
38
+ - --line-numbers
39
+ - --inline-source
40
+ - --title
41
+ - tti
42
+ - --main
43
+ - README.textile
44
+ require_paths:
45
+ - lib
46
+ - lib/snippets
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.2.0
63
+ signing_key:
64
+ specification_version: 2
65
+ summary: Include snippets of content in your Rails views and let the client modify them.
66
+ test_files: []
67
+