snippr 0.13.1 → 0.13.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Snippr
2
2
  ## File based content management
3
+ ![Travis-CI](https://secure.travis-ci.org/blaulabs/snippr.png)
3
4
 
4
5
  A snippr file is a piece of HTML or raw text to be included in a website. They are plain text
5
6
  files stored on the file system. Snippr files end with ".snip" and are read from the Snippr path.
@@ -139,5 +140,16 @@ your views. You can then use the +snippr+ helper method to load snippr files.
139
140
  .topup.info
140
141
  = snippr :topup, :success
141
142
 
142
- ## Build Status
143
- ![Travis-CI](https://secure.travis-ci.org/blaulabs/snippr.png)
143
+ ## Configuration via railtie
144
+ Starting in version 0.13.2 you can configure snippr without the use of initializers when using Rails:
145
+
146
+ Edit `application.rb` (or the environment specific files in config/environments) and add:
147
+
148
+ class Application < Rails::Application
149
+ config.snippr.i18n = true
150
+ # Add a Normalizer:
151
+ config.snippr.normalizers = Snippr::Normalizer::DeRester.new
152
+ config.snippr.path = "my/path/to/snippets"
153
+ # or even for defered configuration with a lambda:
154
+ # config.snippr.path = lambda { SomeClassThatsAvailableLater.path }
155
+ end
@@ -1,3 +1,4 @@
1
+ # # -*- encoding : utf-8 -*-
1
2
  # = Snippr::Normalizer
2
3
  #
3
4
  # Provides methods to normalize snippr path elements.
@@ -9,6 +10,10 @@ module Snippr
9
10
  @normalizers ||= []
10
11
  end
11
12
 
13
+ def self.add(normalizer_or_normalizers)
14
+ @normalizers = Array(@normalizers) + Array(normalizer_or_normalizers)
15
+ end
16
+
12
17
  # Sends the given path element to all the configured normalizers and returns the result.
13
18
  def self.normalize(path_element)
14
19
  @normalizers.inject(path_element) {|e, normalizer| normalizer.normalize e}
data/lib/snippr/path.rb CHANGED
@@ -1,20 +1,22 @@
1
+ # # -*- encoding : utf-8 -*-
1
2
  # = Snippr::Path
2
3
  #
3
4
  # Provides methods for dealing with the path to snippr files.
4
5
  module Snippr
5
6
  module Path
6
7
 
7
- # The JVM property to set the path to the snippr files.
8
- JVM_PROPERTY = 'cms.snippet.path'
9
-
10
- # Returns the path to the snippr files (from JVM properties if available).
8
+ # Returns the path to the snippr files
11
9
  def self.path
12
- @@path ||= JavaLang::System.get_property(JVM_PROPERTY) rescue ""
10
+ if @@path.respond_to?(:call)
11
+ @@path_evaled ||= @@path.call
12
+ else
13
+ @@path.to_s
14
+ end
13
15
  end
14
16
 
15
17
  # Sets the path to the snippr files.
16
18
  def self.path=(path)
17
- @@path = path.to_s
19
+ @@path = path
18
20
  end
19
21
 
20
22
  # Builds a snippr name from an array of path parts.
@@ -37,14 +39,5 @@ module Snippr
37
39
  end.sort.map(&:to_sym)
38
40
  end
39
41
 
40
- private
41
-
42
- if RUBY_PLATFORM =~ /java/
43
- require 'java'
44
- module JavaLang
45
- include_package "java.lang"
46
- end
47
- end
48
-
49
42
  end
50
43
  end
@@ -0,0 +1,15 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Snippr
3
+
4
+ class Railtie < Rails::Railtie
5
+
6
+ config.snippr = ActiveSupport::OrderedOptions.new
7
+
8
+ initializer :setup_snippr, :group => :all do |app|
9
+ Snippr.i18n = app.config.snippr.i18n
10
+ Snippr.path = app.config.snippr.path
11
+ Snippr::Normalizer.add app.config.snippr.normalizers if app.config.snippr.normalizers
12
+ end
13
+
14
+ end
15
+ end
data/lib/snippr/snip.rb CHANGED
@@ -2,11 +2,10 @@
2
2
  # = Snippr::Snip
3
3
  #
4
4
  # Represents a single snip and provides methods to read data.
5
+
5
6
  module Snippr
6
7
  class Snip
7
8
 
8
- extend ActiveSupport::Memoizable
9
-
10
9
  FILE_EXTENSION = 'snip'
11
10
 
12
11
  def initialize(*names)
@@ -22,20 +21,20 @@ module Snippr
22
21
 
23
22
  # Returns the processed and decorated content.
24
23
  def content
25
- if missing?
26
- "<!-- missing snippr: #{name} -->"
27
- else
28
- content = Processor.process unprocessed_content, opts
29
- "<!-- starting snippr: #{name} -->\n#{content}\n<!-- closing snippr: #{name} -->"
24
+ @content ||= begin
25
+ if missing?
26
+ "<!-- missing snippr: #{name} -->"
27
+ else
28
+ content = Processor.process unprocessed_content, opts
29
+ "<!-- starting snippr: #{name} -->\n#{content}\n<!-- closing snippr: #{name} -->"
30
+ end
30
31
  end
31
32
  end
32
- memoize :content
33
33
  alias :to_s :content
34
34
 
35
35
  def raw_content
36
- missing? ? '' : File.read(@path).strip
36
+ @raw_content ||= missing? ? '' : File.read(@path).strip
37
37
  end
38
- memoize :raw_content
39
38
 
40
39
  # Returns whether the snip is missing or not.
41
40
  def missing?
data/lib/snippr.rb CHANGED
@@ -1,8 +1,24 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  require 'active_support/core_ext'
2
3
 
3
- Dir[File.expand_path '../snippr/*.rb', __FILE__].each {|f| require f}
4
- Dir[File.expand_path '../snippr/normalizer/*.rb', __FILE__].each {|f| require f}
5
- Dir[File.expand_path '../snippr/processor/*.rb', __FILE__].each {|f| require f}
4
+ require 'snippr/snippr'
5
+ require 'snippr/snip'
6
+ require 'snippr/i18n'
7
+ require 'snippr/links'
8
+ require 'snippr/meta_data'
9
+ require 'snippr/normalizer'
10
+ require 'snippr/path'
11
+ require 'snippr/processor'
12
+ require 'snippr/railtie' if defined?(Rails)
13
+ require 'snippr/view_helper'
14
+
15
+ require 'snippr/normalizer/camelizer'
16
+ require 'snippr/normalizer/de_rester'
17
+
18
+ require 'snippr/processor/dynamics'
19
+ require 'snippr/processor/functions'
20
+ require 'snippr/processor/links'
21
+ require 'snippr/processor/wikilinks'
6
22
 
7
23
  Snippr::Normalizer.normalizers << Snippr::Normalizer::Camelizer.new
8
24
  # don't use DeRester this for all apps, but configure it as needed
data/snippr.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = "snippr"
4
- s.version = "0.13.1"
4
+ s.version = "0.13.2"
5
5
  s.date = Time.now
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["Daniel Harrington", "Thomas Jachmann"]
@@ -16,12 +16,9 @@ Gem::Specification.new do |s|
16
16
  s.add_runtime_dependency "activesupport"
17
17
 
18
18
  s.add_development_dependency "ci_reporter", "~> 1.6.5"
19
- s.add_development_dependency "rspec", "~> 2.6.0"
20
- s.add_development_dependency "mocha", "0.9.12"
21
- s.add_development_dependency "rake", "~> 0.9.0"
22
- # pin down ZenTest so that autotest works without upgrading rubygems
23
- # see http://stackoverflow.com/questions/6802610/autotest-problem [mw, 2011-08-10]
24
- s.add_development_dependency "ZenTest", "4.5.0"
19
+ s.add_development_dependency "rspec", "~> 2.8.0"
20
+ s.add_development_dependency "mocha", "0.11.4"
21
+ s.add_development_dependency "rake", "~> 0.9.2"
25
22
 
26
23
  s.files = `git ls-files`.split("\n")
27
24
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -1,3 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  require "spec_helper"
2
3
 
3
4
  describe Snippr::Normalizer do
@@ -37,4 +38,23 @@ describe Snippr::Normalizer do
37
38
 
38
39
  end
39
40
 
41
+ describe ".add" do
42
+
43
+ before do
44
+ subject.normalizers.clear
45
+ subject.normalizers << Snippr::Normalizer::Camelizer.new
46
+ end
47
+
48
+ it "adds the normalizer if an class" do
49
+ subject.add(Snippr::Normalizer::DeRester.new)
50
+ subject.normalizers.should have(2).normalizers
51
+ end
52
+
53
+ it "adds the normalizers if an array" do
54
+ subject.add([Snippr::Normalizer::DeRester.new, Snippr::Normalizer::DeRester.new])
55
+ subject.normalizers.should have(3).normalizers
56
+ end
57
+
58
+ end
59
+
40
60
  end
@@ -1,23 +1,30 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  require "spec_helper"
2
3
 
3
4
  describe Snippr::Path do
4
5
 
5
6
  describe "path" do
6
7
 
7
- it "should store the path" do
8
+ before do
8
9
  subject.path = nil
10
+ end
11
+
12
+ it "stores the path if set as string" do
9
13
  subject.path.should == ''
10
14
  subject.path = 'path'
11
15
  subject.path.should == 'path'
12
16
  end
13
17
 
14
- # TODO test JVM path? [thomas, 2010-08-26]
18
+ it "stores and defers the path evaluation if passed a lambda" do
19
+ subject.path = lambda { "WOW LAMBDA ACTION!" }
20
+ subject.path.should == "WOW LAMBDA ACTION!"
21
+ end
15
22
 
16
23
  end
17
24
 
18
25
  describe ".normalize_name" do
19
26
 
20
- it "should call Snippr::Normalizer.normalize with all names and return normalized result" do
27
+ it "calls Snippr::Normalizer.normalize with all names and return normalized result" do
21
28
  seq = sequence "normalizers"
22
29
  Snippr::Normalizer.expects(:normalize).with("a").in_sequence(seq).returns("AA")
23
30
  Snippr::Normalizer.expects(:normalize).with(:b).in_sequence(seq).returns("BB")
@@ -32,11 +39,11 @@ describe Snippr::Path do
32
39
  subject.path = 'path'
33
40
  end
34
41
 
35
- it "should join path and name (with extension)" do
42
+ it "joins path and name (with extension)" do
36
43
  subject.path_from_name('name', 'snip').should == 'path/name.snip'
37
44
  end
38
45
 
39
- it "should join path and name (without extension)" do
46
+ it "joins path and name (without extension)" do
40
47
  subject.path_from_name('file').should == 'path/file'
41
48
  end
42
49
 
@@ -50,11 +57,11 @@ describe Snippr::Path do
50
57
  Snippr::I18n.enabled = false
51
58
  end
52
59
 
53
- it "should return a list of all snippr names" do
60
+ it "returns a list of all snippr names" do
54
61
  subject.list(:topup).should == [:some_error, :success]
55
62
  end
56
63
 
57
- it "should return an empty array for non existant dirs" do
64
+ it "returns an empty array for non existant dirs" do
58
65
  subject.list(:doesnotexist).should == []
59
66
  end
60
67
 
@@ -66,17 +73,17 @@ describe Snippr::Path do
66
73
  Snippr::I18n.enabled = true
67
74
  end
68
75
 
69
- it "should return a list of all snippr names of the current locale (de)" do
76
+ it "returns a list of all snippr names of the current locale (de)" do
70
77
  I18n.locale = :de
71
78
  subject.list(:i18n).should == [:list, :shop]
72
79
  end
73
80
 
74
- it "should return a list of all snippr names of the current locale (en)" do
81
+ it "returns a list of all snippr names of the current locale (en)" do
75
82
  I18n.locale = :en
76
83
  subject.list(:i18n).should == [:shop]
77
84
  end
78
85
 
79
- it "should return an empty array for non existant dirs" do
86
+ it "returns an empty array for non existant dirs" do
80
87
  subject.list(:doesnotexist).should == []
81
88
  end
82
89
 
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,8 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  require 'rubygems'
2
3
  require 'bundler'
4
+ require 'snippr'
5
+
3
6
  Bundler.require(:default, :development)
4
7
 
5
8
  RSpec.configure do |config|
@@ -8,11 +11,6 @@ RSpec.configure do |config|
8
11
  Snippr::I18n.enabled = nil
9
12
  Snippr::Links.adjust_urls_except = nil
10
13
  snippr_path = File.expand_path '../fixtures', __FILE__
11
- if RUBY_PLATFORM =~ /java/
12
- Snippr::Path.path = snippr_path
13
- Snippr::Path::JavaLang::System.set_property Snippr::Path::JVM_PROPERTY, snippr_path
14
- else
15
- Snippr::Path.path = snippr_path
16
- end
14
+ Snippr::Path.path = snippr_path
17
15
  end
18
16
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snippr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.1
4
+ version: 0.13.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-05-15 00:00:00.000000000 Z
13
+ date: 2012-06-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: i18n
17
- requirement: &2181996100 !ruby/object:Gem::Requirement
17
+ requirement: &2183725920 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2181996100
25
+ version_requirements: *2183725920
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activesupport
28
- requirement: &2181995660 !ruby/object:Gem::Requirement
28
+ requirement: &2183725480 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2181995660
36
+ version_requirements: *2183725480
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: ci_reporter
39
- requirement: &2181995160 !ruby/object:Gem::Requirement
39
+ requirement: &2183774080 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,51 +44,40 @@ dependencies:
44
44
  version: 1.6.5
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2181995160
47
+ version_requirements: *2183774080
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rspec
50
- requirement: &2181994660 !ruby/object:Gem::Requirement
50
+ requirement: &2183773580 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
54
54
  - !ruby/object:Gem::Version
55
- version: 2.6.0
55
+ version: 2.8.0
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *2181994660
58
+ version_requirements: *2183773580
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: mocha
61
- requirement: &2181994200 !ruby/object:Gem::Requirement
61
+ requirement: &2183773120 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - =
65
65
  - !ruby/object:Gem::Version
66
- version: 0.9.12
66
+ version: 0.11.4
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *2181994200
69
+ version_requirements: *2183773120
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rake
72
- requirement: &2181993740 !ruby/object:Gem::Requirement
72
+ requirement: &2183772660 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: 0.9.0
77
+ version: 0.9.2
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *2181993740
81
- - !ruby/object:Gem::Dependency
82
- name: ZenTest
83
- requirement: &2181993280 !ruby/object:Gem::Requirement
84
- none: false
85
- requirements:
86
- - - =
87
- - !ruby/object:Gem::Version
88
- version: 4.5.0
89
- type: :development
90
- prerelease: false
91
- version_requirements: *2181993280
80
+ version_requirements: *2183772660
92
81
  description: This gem provides ways to access file based cms resources from a rails
93
82
  app.
94
83
  email:
@@ -118,10 +107,10 @@ files:
118
107
  - lib/snippr/processor/functions.rb
119
108
  - lib/snippr/processor/links.rb
120
109
  - lib/snippr/processor/wikilinks.rb
110
+ - lib/snippr/railtie.rb
121
111
  - lib/snippr/snip.rb
122
112
  - lib/snippr/snippr.rb
123
113
  - lib/snippr/view_helper.rb
124
- - rails/init.rb
125
114
  - snippr.gemspec
126
115
  - spec/fixtures/a/path/aSnippet.snip
127
116
  - spec/fixtures/a/path/aSnippetWithParam.snip
data/rails/init.rb DELETED
@@ -1 +0,0 @@
1
- require "snippr"