jtplparser 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'nokogiri', '1.4.4'
4
+
5
+ group :development do
6
+ gem 'rspec', '~> 2.3.0'
7
+ gem 'bundler', ' ~> 1.0.0'
8
+ gem 'jeweler', ' ~> 1.6.0'
9
+ gem 'rcov', '>= 0'
10
+ gem 'rake', '0.8.7'
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ git (1.2.5)
6
+ jeweler (1.6.0)
7
+ bundler (~> 1.0.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ nokogiri (1.4.4)
11
+ rake (0.8.7)
12
+ rcov (0.9.9)
13
+ rspec (2.3.0)
14
+ rspec-core (~> 2.3.0)
15
+ rspec-expectations (~> 2.3.0)
16
+ rspec-mocks (~> 2.3.0)
17
+ rspec-core (2.3.1)
18
+ rspec-expectations (2.3.0)
19
+ diff-lcs (~> 1.1.2)
20
+ rspec-mocks (2.3.0)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ bundler (~> 1.0.0)
27
+ jeweler (~> 1.6.0)
28
+ nokogiri (= 1.4.4)
29
+ rake (= 0.8.7)
30
+ rcov
31
+ rspec (~> 2.3.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,18 @@
1
+ Permission is hereby granted, free of charge, to any person obtaining
2
+ a copy of this software and associated documentation files (the
3
+ "Software"), to deal in the Software without restriction, including
4
+ without limitation the rights to use, copy, modify, merge, publish,
5
+ distribute, sublicense, and/or sell copies of the Software, and to
6
+ permit persons to whom the Software is furnished to do so, subject to
7
+ the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be
10
+ included in all copies or substantial portions of the Software.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,15 @@
1
+ = jtplparser
2
+
3
+ Ruby port of http://jtpl.sourceforge.net/
4
+
5
+ Not much error checking, works well enough for my purposes, and has tests.
6
+
7
+ == Contributing to jtplparser
8
+
9
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
10
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
11
+ * Fork the project
12
+ * Start a feature/bugfix branch
13
+ * Commit and push until you are happy with your contribution
14
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
15
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "jtplparser"
18
+ gem.homepage = "http://github.com/himmel/jtplparser"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{ruby approximation of http//jtpl.sourceforge.net/}
21
+ gem.description = %Q{ruby approximation of http//jtpl.sourceforge.net/}
22
+ gem.email = "eric@rawsyntax.com"
23
+ gem.authors = ["Eric Himmelreich"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "jtplparser #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,74 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{jtplparser}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Eric Himmelreich"]
12
+ s.date = %q{2011-06-14}
13
+ s.description = %q{ruby approximation of http//jtpl.sourceforge.net/}
14
+ s.email = %q{eric@rawsyntax.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "jtplparser.gemspec",
29
+ "lib/jtplparser.rb",
30
+ "spec/fixtures/multi_var.jtpl",
31
+ "spec/fixtures/nested_tags.jtpl",
32
+ "spec/fixtures/single_tag.jtpl",
33
+ "spec/fixtures/single_tag_content.jtpl",
34
+ "spec/fixtures/single_tag_no_content.jtpl",
35
+ "spec/fixtures/single_tag_replace.jtpl",
36
+ "spec/fixtures/single_var.jtpl",
37
+ "spec/fixtures/two_tags.jtpl",
38
+ "spec/jtplparser_spec.rb",
39
+ "spec/spec_helper.rb"
40
+ ]
41
+ s.homepage = %q{http://github.com/himmel/jtplparser}
42
+ s.licenses = ["MIT"]
43
+ s.require_paths = ["lib"]
44
+ s.rubygems_version = %q{1.5.2}
45
+ s.summary = %q{ruby approximation of http//jtpl.sourceforge.net/}
46
+
47
+ if s.respond_to? :specification_version then
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_runtime_dependency(%q<nokogiri>, ["= 1.4.4"])
52
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
53
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
54
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
55
+ s.add_development_dependency(%q<rcov>, [">= 0"])
56
+ s.add_development_dependency(%q<rake>, ["= 0.8.7"])
57
+ else
58
+ s.add_dependency(%q<nokogiri>, ["= 1.4.4"])
59
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
60
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
61
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
62
+ s.add_dependency(%q<rcov>, [">= 0"])
63
+ s.add_dependency(%q<rake>, ["= 0.8.7"])
64
+ end
65
+ else
66
+ s.add_dependency(%q<nokogiri>, ["= 1.4.4"])
67
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
68
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
69
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
70
+ s.add_dependency(%q<rcov>, [">= 0"])
71
+ s.add_dependency(%q<rake>, ["= 0.8.7"])
72
+ end
73
+ end
74
+
data/lib/jtplparser.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+
3
+ class JtplParser
4
+
5
+ def self.blocks(string)
6
+ blocks = string.strip.scan(/(\<!\s*--)(.*?)(--\s*\>)/m)
7
+
8
+ unless blocks == []
9
+ blocks = blocks.map do |b|
10
+ {:name => b[1].strip.gsub("BEGIN: ", "").gsub("END: ", "") }
11
+ end
12
+
13
+ # eliminate invalid named blocks
14
+ blocks = blocks.select {|b| b[:name].gsub(/\w*/, '').empty? }
15
+ end
16
+
17
+ blocks.uniq
18
+ end
19
+
20
+ def self.variables(string)
21
+ string.strip.scan(/\{.*?\}/).map {|s| s.gsub('{', '').gsub('}', '') }
22
+ end
23
+ end
@@ -0,0 +1,10 @@
1
+ <!-- BEGIN: main -->
2
+ <html>
3
+ <head>
4
+ <title>{title}</title>
5
+ </head>
6
+ <body>
7
+ <p>{paragraph}</p>
8
+ </body>
9
+ </html>
10
+ <!-- END: main -->
@@ -0,0 +1,12 @@
1
+ <!-- BEGIN: main -->
2
+ <html>
3
+ <head>
4
+ <title>title</title>
5
+ </head>
6
+ <body>
7
+ <!-- BEGIN: content -->
8
+ <p>testing is fun</p>
9
+ <!-- END: content -->
10
+ </body>
11
+ </html>
12
+ <!-- END: main -->
@@ -0,0 +1,10 @@
1
+ <!-- BEGIN: main -->
2
+ <html>
3
+ <head>
4
+ <title>title</title>
5
+ </head>
6
+ <body>
7
+ <p>testing is fun</p>
8
+ </body>
9
+ </html>
10
+ <!-- END: main -->
@@ -0,0 +1,8 @@
1
+ <html>
2
+ <head>
3
+ <title>title</title>
4
+ </head>
5
+ <body>
6
+ <p>testing is fun</p>
7
+ </body>
8
+ </html>
@@ -0,0 +1,2 @@
1
+ <!-- BEGIN: main -->
2
+ <!-- END: main -->
@@ -0,0 +1,10 @@
1
+ <!-- BEGIN: main -->
2
+ <html>
3
+ <head>
4
+ <title>{TITLE}</title>
5
+ </head>
6
+ <body>
7
+ testing is fun
8
+ </body>
9
+ </html>
10
+ <!-- END: main -->
@@ -0,0 +1,10 @@
1
+ <!-- BEGIN: main -->
2
+ <html>
3
+ <head>
4
+ <title>{title}</title>
5
+ </head>
6
+ <body>
7
+ <p>testing is fun</p>
8
+ </body>
9
+ </html>
10
+ <!-- END: main -->
@@ -0,0 +1,6 @@
1
+ <!-- BEGIN: first -->
2
+ <p>first content</p>
3
+ <!-- END: first -->
4
+ <!-- BEGIN: second -->
5
+ <p>second content</p>
6
+ <!-- END: second -->
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe JtplParser do
4
+
5
+ let(:single_tag) { File.open('./spec/fixtures/single_tag.jtpl').read.strip }
6
+ let(:nested_tags) { File.open('./spec/fixtures/nested_tags.jtpl').read.strip }
7
+ let(:two_tags) { File.open('./spec/fixtures/two_tags.jtpl').read.strip }
8
+ let(:single_tag_no_content) {
9
+ File.open('./spec/fixtures/single_tag_no_content.jtpl').read.strip
10
+ }
11
+ let(:single_tag_content) {
12
+ File.open('./spec/fixtures/single_tag_content.jtpl').read.strip
13
+ }
14
+
15
+ let(:single_var) { File.open('./spec/fixtures/single_var.jtpl').read.strip }
16
+ let(:multi_var) { File.open('./spec/fixtures/multi_var.jtpl').read.strip }
17
+
18
+ describe 'blocks' do
19
+ it 'should identify a beginning and ending comment' do
20
+ JtplParser.blocks(single_tag)
21
+ .should == [{:name => "main"}]
22
+ end
23
+
24
+ it 'should identify nested comments' do
25
+ JtplParser.blocks(nested_tags).should ==
26
+ [{:name => "main"}, {:name => "content"}]
27
+ end
28
+
29
+ it 'should identify sequential comments' do
30
+ JtplParser.blocks(two_tags).should ==
31
+ [{:name => "first"}, {:name => "second"}]
32
+
33
+ end
34
+ end
35
+
36
+ describe 'variables' do
37
+ it 'should identify a single variable' do
38
+ JtplParser.variables(single_var).should ==
39
+ ['title']
40
+ end
41
+
42
+ it 'should identify many variables' do
43
+ JtplParser.variables(multi_var).should ==
44
+ [ 'title', 'paragraph']
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'jtplparser'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jtplparser
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Eric Himmelreich
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-06-14 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: nokogiri
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.4.4
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 2.3.0
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: bundler
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.0
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: jeweler
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 1.6.0
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: rcov
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: rake
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - "="
77
+ - !ruby/object:Gem::Version
78
+ version: 0.8.7
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *id006
82
+ description: ruby approximation of http//jtpl.sourceforge.net/
83
+ email: eric@rawsyntax.com
84
+ executables: []
85
+
86
+ extensions: []
87
+
88
+ extra_rdoc_files:
89
+ - LICENSE.txt
90
+ - README.rdoc
91
+ files:
92
+ - .document
93
+ - .rspec
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.rdoc
98
+ - Rakefile
99
+ - VERSION
100
+ - jtplparser.gemspec
101
+ - lib/jtplparser.rb
102
+ - spec/fixtures/multi_var.jtpl
103
+ - spec/fixtures/nested_tags.jtpl
104
+ - spec/fixtures/single_tag.jtpl
105
+ - spec/fixtures/single_tag_content.jtpl
106
+ - spec/fixtures/single_tag_no_content.jtpl
107
+ - spec/fixtures/single_tag_replace.jtpl
108
+ - spec/fixtures/single_var.jtpl
109
+ - spec/fixtures/two_tags.jtpl
110
+ - spec/jtplparser_spec.rb
111
+ - spec/spec_helper.rb
112
+ has_rdoc: true
113
+ homepage: http://github.com/himmel/jtplparser
114
+ licenses:
115
+ - MIT
116
+ post_install_message:
117
+ rdoc_options: []
118
+
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ hash: -2646409932083893848
127
+ segments:
128
+ - 0
129
+ version: "0"
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: "0"
136
+ requirements: []
137
+
138
+ rubyforge_project:
139
+ rubygems_version: 1.5.2
140
+ signing_key:
141
+ specification_version: 3
142
+ summary: ruby approximation of http//jtpl.sourceforge.net/
143
+ test_files: []
144
+