shortcode 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/shortcode.rb CHANGED
@@ -1,47 +1,35 @@
1
1
  require 'parslet'
2
2
  require 'haml'
3
3
  require 'erb'
4
- require 'facets/module/mattr'
5
4
 
6
5
  module Shortcode
6
+ extend self
7
7
 
8
- # Sets the template parser to use, supports :erb and :haml, default is :haml
9
- mattr_accessor :template_parser
10
- @@template_parser = :haml
8
+ attr_accessor :configuration
11
9
 
12
- # Sets the template parser to use, supports :erb and :haml, default is :haml
13
- mattr_accessor :template_path
14
- @@template_path = "app/views/shortcode_templates"
15
-
16
- # Set the supported block_tags
17
- mattr_accessor :block_tags
18
- @@block_tags = [:quote]
19
-
20
- # Set the supported self_closing_tags
21
- mattr_accessor :self_closing_tags
22
- @@self_closing_tags = [:youtube]
23
-
24
- def self.setup
25
- yield self
10
+ def setup
11
+ self.configuration ||= Configuration.new
12
+ yield configuration
26
13
  end
27
14
 
28
- def self.process(code)
15
+ def process(code)
29
16
  transformer.apply(parser.parse(code))
30
17
  end
31
18
 
32
19
  private
33
20
 
34
- def self.parser
21
+ def parser
35
22
  @@parser ||= Shortcode::Parser.new
36
23
  end
37
24
 
38
- def self.transformer
25
+ def transformer
39
26
  @@transformer ||= Shortcode::Transformer.new
40
27
  end
41
28
 
42
29
  end
43
30
 
44
31
  require 'shortcode/version'
32
+ require 'shortcode/configuration'
45
33
  require 'shortcode/parser'
46
34
  require 'shortcode/transformer'
47
35
  require 'shortcode/tag'
@@ -0,0 +1,17 @@
1
+ class Shortcode::Configuration
2
+ # Sets the template parser to use, supports :erb and :haml, default is :haml
3
+ attr_accessor :template_parser
4
+ @template_parser = :haml
5
+
6
+ # Sets the template parser to use, supports :erb and :haml, default is :haml
7
+ attr_accessor :template_path
8
+ @template_path = "app/views/shortcode_templates"
9
+
10
+ # Set the supported block_tags
11
+ attr_accessor :block_tags
12
+ @block_tags = [:quote]
13
+
14
+ # Set the supported self_closing_tags
15
+ attr_accessor :self_closing_tags
16
+ @self_closing_tags = [:youtube]
17
+ end
@@ -1,7 +1,7 @@
1
1
  class Shortcode::Parser < Parslet::Parser
2
2
 
3
- rule(:block_tag) { match_any_of Shortcode.block_tags }
4
- rule(:self_closing_tag) { match_any_of Shortcode.self_closing_tags }
3
+ rule(:block_tag) { match_any_of Shortcode.configuration.block_tags }
4
+ rule(:self_closing_tag) { match_any_of Shortcode.configuration.self_closing_tags }
5
5
 
6
6
  rule(:quotes) { str('"') }
7
7
 
data/lib/shortcode/tag.rb CHANGED
@@ -26,23 +26,23 @@ class Shortcode::Tag
26
26
  private
27
27
 
28
28
  def render_template
29
- case Shortcode.template_parser
29
+ case Shortcode.configuration.template_parser
30
30
  when :haml
31
31
  Haml::Engine.new(markup, ugly: true).render(binding)
32
32
  when :erb
33
33
  ERB.new(markup).result(binding)
34
34
  else
35
- raise Shortcode::TemplateParserNotSupported, Shortcode.template_parser
35
+ raise Shortcode::TemplateParserNotSupported, Shortcode.configuration.template_parser
36
36
  end
37
37
  end
38
38
 
39
39
  def template_files
40
40
  template_paths.map do |filename|
41
- File.join Shortcode.template_path, filename
41
+ File.join Shortcode.configuration.template_path, filename
42
42
  end
43
43
  end
44
44
 
45
45
  def template_paths
46
- [ "#{@name}.html.#{Shortcode.template_parser.to_s}", "#{@name}.#{Shortcode.template_parser.to_s}" ]
46
+ [ "#{@name}.html.#{Shortcode.configuration.template_parser.to_s}", "#{@name}.#{Shortcode.configuration.template_parser.to_s}" ]
47
47
  end
48
48
  end
@@ -1,3 +1,3 @@
1
1
  module Shortcode
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/shortcode.gemspec CHANGED
@@ -19,8 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "parslet", "1.5.0"
22
- spec.add_dependency "haml", "4.0.0"
23
- spec.add_dependency "facets", "2.9.3"
22
+ spec.add_dependency "haml", "~> 4.0"
24
23
 
25
24
  spec.add_development_dependency "bundler", "~> 1.3"
26
25
  spec.add_development_dependency "rake"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shortcode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-07 00:00:00.000000000 Z
12
+ date: 2013-08-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parslet
@@ -32,33 +32,17 @@ dependencies:
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - '='
36
- - !ruby/object:Gem::Version
37
- version: 4.0.0
38
- type: :runtime
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - '='
44
- - !ruby/object:Gem::Version
45
- version: 4.0.0
46
- - !ruby/object:Gem::Dependency
47
- name: facets
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - '='
35
+ - - ~>
52
36
  - !ruby/object:Gem::Version
53
- version: 2.9.3
37
+ version: '4.0'
54
38
  type: :runtime
55
39
  prerelease: false
56
40
  version_requirements: !ruby/object:Gem::Requirement
57
41
  none: false
58
42
  requirements:
59
- - - '='
43
+ - - ~>
60
44
  - !ruby/object:Gem::Version
61
- version: 2.9.3
45
+ version: '4.0'
62
46
  - !ruby/object:Gem::Dependency
63
47
  name: bundler
64
48
  requirement: !ruby/object:Gem::Requirement
@@ -121,6 +105,7 @@ files:
121
105
  - README.md
122
106
  - Rakefile
123
107
  - lib/shortcode.rb
108
+ - lib/shortcode/configuration.rb
124
109
  - lib/shortcode/exceptions.rb
125
110
  - lib/shortcode/parser.rb
126
111
  - lib/shortcode/tag.rb