eldr-rendering 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d787d66a0ecb3a6bf7a69033fac49a4ea43f7965
4
+ data.tar.gz: eeba2a2db886349a417012a910cddc6a5ed7de15
5
+ SHA512:
6
+ metadata.gz: d39945cb24ee674da4780260e41f5fc9008a69bbf0fad57546aba269cba3e475a12265eb08d841569fbf537adcdcad30871c947663f4f267975bee3192d77d08
7
+ data.tar.gz: 7b39f66dd927448d76546fe42a79d8f215e41238964a45d06b5b3c4ae3ea7de11f44f9958c0bf3dc05d21006e9a6ac09dc5a4fe9722c8d919dddf801fee0d483
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.bundle
10
+ *.so
11
+ *.o
12
+ *.a
13
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format progress
3
+ --require ./spec/spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,25 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ Style/AndOr:
4
+ Enabled: false
5
+
6
+ Metrics/AbcSize:
7
+ Max: 40
8
+
9
+ Metrics/MethodLength:
10
+ Max: 20
11
+
12
+ Metrics/ClassLength:
13
+ Max: 130
14
+
15
+ Metrics/LineLength:
16
+ Max: 120
17
+
18
+ Style/FileName:
19
+ Enabled: false
20
+
21
+ AllCops:
22
+ Exclude:
23
+ - 'spec/**/*'
24
+ - 'Gemfile'
25
+ - 'eldr-rendering.gemspec'
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,53 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2015-01-24 23:47:36 -0800 using RuboCop version 0.28.0.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 2
9
+ # Configuration parameters: AlignWith, SupportedStyles.
10
+ Lint/EndAlignment:
11
+ Enabled: false
12
+
13
+ # Offense count: 1
14
+ # Cop supports --auto-correct.
15
+ Lint/UnusedBlockArgument:
16
+ Enabled: false
17
+
18
+ # Offense count: 2
19
+ # Cop supports --auto-correct.
20
+ Lint/UnusedMethodArgument:
21
+ Enabled: false
22
+
23
+ # Offense count: 1
24
+ # Cop supports --auto-correct.
25
+ Style/Alias:
26
+ Enabled: false
27
+
28
+ # Offense count: 5
29
+ Style/Documentation:
30
+ Enabled: false
31
+
32
+ # Offense count: 3
33
+ # Cop supports --auto-correct.
34
+ Style/ElseAlignment:
35
+ Enabled: false
36
+
37
+ # Offense count: 3
38
+ # Cop supports --auto-correct.
39
+ # Configuration parameters: Width.
40
+ Style/IndentationWidth:
41
+ Enabled: false
42
+
43
+ # Offense count: 1
44
+ # Cop supports --auto-correct.
45
+ # Configuration parameters: AllowAsExpressionSeparator.
46
+ Style/Semicolon:
47
+ Enabled: false
48
+
49
+ # Offense count: 2
50
+ # Cop supports --auto-correct.
51
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
52
+ Style/SignalException:
53
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,109 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ eldr-rendering (0.0.1)
5
+ activesupport (~> 4.2)
6
+ eldr (~> 0.0)
7
+ tilt (~> 1.4)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (4.2.0)
13
+ i18n (~> 0.7)
14
+ json (~> 1.7, >= 1.7.7)
15
+ minitest (~> 5.1)
16
+ thread_safe (~> 0.3, >= 0.3.4)
17
+ tzinfo (~> 1.1)
18
+ ast (2.0.0)
19
+ astrolabe (1.3.0)
20
+ parser (>= 2.2.0.pre.3, < 3.0)
21
+ coveralls (0.7.3)
22
+ multi_json (~> 1.10)
23
+ rest-client (~> 1.7)
24
+ simplecov (~> 0.9.1)
25
+ term-ansicolor (~> 1.3)
26
+ thor (~> 0.19.1)
27
+ diff-lcs (1.2.5)
28
+ docile (1.1.5)
29
+ eldr (0.0.3)
30
+ fast_blank (= 0.0.2)
31
+ mustermann (= 0.4.0)
32
+ rack (~> 1.5)
33
+ fast_blank (0.0.2)
34
+ i18n (0.7.0)
35
+ json (1.8.2)
36
+ mime-types (2.4.3)
37
+ mini_portile (0.6.2)
38
+ minitest (5.5.1)
39
+ multi_json (1.10.1)
40
+ mustermann (0.4.0)
41
+ tool (~> 0.2)
42
+ netrc (0.10.2)
43
+ nokogiri (1.6.6.2)
44
+ mini_portile (~> 0.6.0)
45
+ parser (2.2.0.2)
46
+ ast (>= 1.1, < 3.0)
47
+ powerpack (0.0.9)
48
+ rack (1.6.0)
49
+ rack-test (0.6.3)
50
+ rack (>= 1.0)
51
+ rainbow (2.0.0)
52
+ rake (10.4.2)
53
+ rest-client (1.7.2)
54
+ mime-types (>= 1.16, < 3.0)
55
+ netrc (~> 0.7)
56
+ rspec (3.1.0)
57
+ rspec-core (~> 3.1.0)
58
+ rspec-expectations (~> 3.1.0)
59
+ rspec-mocks (~> 3.1.0)
60
+ rspec-core (3.1.7)
61
+ rspec-support (~> 3.1.0)
62
+ rspec-expectations (3.1.2)
63
+ diff-lcs (>= 1.2.0, < 2.0)
64
+ rspec-support (~> 3.1.0)
65
+ rspec-html-matchers (0.6.1)
66
+ nokogiri (~> 1)
67
+ rspec (~> 3)
68
+ rspec-mocks (3.1.3)
69
+ rspec-support (~> 3.1.0)
70
+ rspec-support (3.1.2)
71
+ rubocop (0.28.0)
72
+ astrolabe (~> 1.3)
73
+ parser (>= 2.2.0.pre.7, < 3.0)
74
+ powerpack (~> 0.0.6)
75
+ rainbow (>= 1.99.1, < 3.0)
76
+ ruby-progressbar (~> 1.4)
77
+ ruby-progressbar (1.7.1)
78
+ simplecov (0.9.1)
79
+ docile (~> 1.1.0)
80
+ multi_json (~> 1.0)
81
+ simplecov-html (~> 0.8.0)
82
+ simplecov-html (0.8.0)
83
+ slim (3.0.1)
84
+ temple (~> 0.7.3)
85
+ tilt (>= 1.3.3, < 2.1)
86
+ temple (0.7.5)
87
+ term-ansicolor (1.3.0)
88
+ tins (~> 1.0)
89
+ thor (0.19.1)
90
+ thread_safe (0.3.4)
91
+ tilt (1.4.1)
92
+ tins (1.3.3)
93
+ tool (0.2.3)
94
+ tzinfo (1.2.2)
95
+ thread_safe (~> 0.1)
96
+
97
+ PLATFORMS
98
+ ruby
99
+
100
+ DEPENDENCIES
101
+ bundler (~> 1.7)
102
+ coveralls (~> 0.7)
103
+ eldr-rendering!
104
+ rack-test (= 0.6.3)
105
+ rake (= 10.4.2)
106
+ rspec (= 3.1.0)
107
+ rspec-html-matchers (= 0.6.1)
108
+ rubocop (= 0.28.0)
109
+ slim (= 3.0.1)
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 K-2052
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # Eldr::Rendering [![Build Status](https://travis-ci.org/eldr-rb/eldr-rendering.svg)](https://travis-ci.org/eldr-rb/eldr-rendering) [![Code Climate](https://codeclimate.com/github/eldr-rb/eldr-rendering/badges/gpa.svg)](https://codeclimate.com/github/eldr-rb/eldr-rendering) [![Coverage Status](https://coveralls.io/repos/eldr-rb/eldr-rendering/badge.svg?branch=master)](https://coveralls.io/r/eldr-rb/eldr-rendering?branch=master) [![Dependency Status](https://gemnasium.com/eldr-rb/eldr-rendering.svg)](https://gemnasium.com/eldr-rb/eldr-rendering) [![Inline docs](https://inch-ci.org/github/eldr-rb/eldr-rendering.svg?branch=master)](http://inch-ci.org/github/eldr-rb/eldr-rendering) [![Gratipay](https://img.shields.io/gratipay/k2052.svg)](https://www.gratipay.com/k2052)
2
+
3
+ Template helpers for Eldr apps and compatible Rack apps.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'eldr-rendering'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install eldr-rendering
20
+
21
+ ## Usage
22
+
23
+ To use the render helper create an Eldr::App and call it in a route's handler:
24
+
25
+ ```ruby
26
+ class App < Eldr::App
27
+ include Eldr::Rendering
28
+ set :views_dir, File.join(__dir__, 'views')
29
+
30
+ get '/cats' do
31
+ render 'cats.slim'
32
+ end
33
+ end
34
+ ```
35
+
36
+ It will wrap the template up in a Rack::Response and return it.
37
+
38
+ Inside your template you can make use of the tag helpers. Eldr::Rendering currently provides just two html helpers; tag() and content_tag().
39
+
40
+ You can use tag() for one line tags like links:
41
+
42
+ ```ruby
43
+ tag(:a, :data => { :remote => true, :method => 'post'})
44
+ ```
45
+
46
+ And content_tag for html tags that need to be outputted with a block of content:
47
+
48
+ ```ruby
49
+ content_tag(:p, :class => 'large', :id => 'star') { "Demo" }
50
+ ```
51
+
52
+ Eldr::Rendering is usable in any valid Rakc that has a configuration object that responds to `views_dir` and `engine`. You can use it in [eldr-action](https://github.com/eldr-rb/eldr-action) or any valid Rack app.
53
+
54
+ For example:
55
+
56
+ ```ruby
57
+ class App
58
+ include Eldr::Rendering
59
+
60
+ attr_accessor :configuration
61
+
62
+ def initialize
63
+ @configuration = Struct.new(:views_dir, :engine)
64
+ @configuration.views_dir = File.join(__dir__, 'views')
65
+ @configuratio.engine = 'slim'
66
+ end
67
+
68
+ def call(env)
69
+ render 'cats.slim'
70
+ end
71
+ end
72
+
73
+ run App.new
74
+ ```
75
+
76
+ See [examples/app.ru](https://github.com/eldr-rb/eldr-rendering/tree/master/examples/app.ru) for an example app.
77
+
78
+ ## Contributing
79
+
80
+ 1. Fork. it
81
+ 2. Create. your feature branch (git checkout -b cat-evolver)
82
+ 3. Commit. your changes (git commit -am 'Add Cat Evolution')
83
+ 4. Test. your changes (always be testing)
84
+ 5. Push. to the branch (git push origin cat-evolver)
85
+ 6. Pull. Request. (for extra points include funny gif and or pun in comments)
86
+
87
+ To remember this you can use the easy to remember and totally not tongue-in-check initialism: FCCTPP.
88
+
89
+ I don't want any of these steps to scare you off. If you don't know how to do something or are struggle getting it to work feel free to create a pull request or issue anyway. I'll be happy to help you get your contributions up to code and into the repo!
90
+
91
+ ## License
92
+
93
+ Licensed under MIT by K-2052.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'rubocop/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ RuboCop::RakeTask.new(:rubocop)
6
+
7
+ task :default do
8
+ Rake::Task['spec'].execute
9
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'eldr/rendering/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'eldr-rendering'
8
+ spec.version = Eldr::Rendering::VERSION
9
+ spec.authors = ['K-2052']
10
+ spec.email = ['k@2052.me']
11
+ spec.summary = %q{Template helpers for Eldr apps and compatible Rack apps}
12
+ spec.homepage = 'https://github.com/eldr-rb/eldr-rendering'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'eldr', '~> 0.0'
21
+ spec.add_dependency 'tilt', '~> 1.4'
22
+ spec.add_dependency 'activesupport', '~> 4.2'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.7'
25
+ spec.add_development_dependency 'rake', '10.4.2'
26
+ spec.add_development_dependency 'rspec', '3.1.0'
27
+ spec.add_development_dependency 'rubocop', '0.28.0'
28
+ spec.add_development_dependency 'rack-test', '0.6.3'
29
+ spec.add_development_dependency 'coveralls', '~> 0.7'
30
+ spec.add_development_dependency 'slim', '3.0.1'
31
+ spec.add_development_dependency 'rspec-html-matchers', '0.6.1'
32
+ end
data/examples/app.ru ADDED
@@ -0,0 +1,18 @@
1
+ require 'eldr'
2
+ require 'slim'
3
+ require_relative '../lib/eldr/rendering'
4
+
5
+ class App < Eldr::App
6
+ include Eldr::Rendering
7
+ set :views_dir, File.join(__dir__, 'views')
8
+
9
+ get '/cats' do
10
+ render 'cats.slim'
11
+ end
12
+
13
+ get '/no-template' do
14
+ render 'template.slim'
15
+ end
16
+ end
17
+
18
+ run App
@@ -0,0 +1 @@
1
+ h1 Cats!
@@ -0,0 +1 @@
1
+ require_relative 'eldr/rendering'
@@ -0,0 +1,32 @@
1
+ require 'tilt'
2
+
3
+ require_relative 'rendering/output_helpers'
4
+ require_relative 'rendering/tag_helpers'
5
+
6
+ module Eldr
7
+ module Rendering
8
+ class NotFound < StandardError
9
+ def call(env)
10
+ Rack::Response.new message, 404
11
+ end
12
+ end
13
+
14
+ def render(path, resp_code = 200)
15
+ Rack::Response.new Tilt.new(find_template(path)).render(self), resp_code
16
+ end
17
+
18
+ def find_template(path)
19
+ configuration.engine ||= 'slim'
20
+ raise StandardError, 'Eldr::Rendering requires you to set config.views_dir' unless configuration.views_dir
21
+ template = Pathname.new(File.join(configuration.views_dir, path))
22
+ template = Pathname.new(template.to_s + '.' + configuration.engine) if template.extname.blank?
23
+ raise NotFound, 'Template Not Found' unless File.exist? template
24
+ template.to_s
25
+ end
26
+
27
+ def self.included(klass)
28
+ klass.include Tags
29
+ klass.include Output
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,10 @@
1
+ module Eldr
2
+ module Rendering
3
+ module Output
4
+ def capture_html(*args, &block)
5
+ yield(*args)
6
+ end
7
+ alias :capture :capture_html
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,115 @@
1
+ require 'active_support/core_ext/string/output_safety'
2
+ require 'active_support/core_ext/string/inflections'
3
+
4
+ module Eldr
5
+ module Rendering
6
+ module Tags
7
+ ESCAPE_VALUES = {
8
+ '&' => '&amp;',
9
+ '<' => '&lt;',
10
+ '>' => '&gt;',
11
+ '"' => '&quot;'
12
+ }.freeze
13
+
14
+ ESCAPE_REGEXP = Regexp.union(*ESCAPE_VALUES.keys).freeze
15
+
16
+ BOOLEAN_ATTRIBUTES = [
17
+ :autoplay,
18
+ :autofocus,
19
+ :formnovalidate,
20
+ :checked,
21
+ :disabled,
22
+ :hidden,
23
+ :loop,
24
+ :multiple,
25
+ :muted,
26
+ :readonly,
27
+ :required,
28
+ :selected,
29
+ :declare,
30
+ :defer,
31
+ :ismap,
32
+ :itemscope,
33
+ :noresize,
34
+ :novalidate
35
+ ].freeze
36
+
37
+ DATA_ATTRIBUTES = [
38
+ :method,
39
+ :remote,
40
+ :confirm
41
+ ].freeze
42
+
43
+ NEWLINE = "\n".html_safe.freeze
44
+
45
+ def tag(name, options = nil, open = false)
46
+ options = parse_data_options(name, options)
47
+ attributes = tag_attributes(options)
48
+ "<#{name}#{attributes}#{open ? '>' : ' />'}".html_safe
49
+ end
50
+
51
+ def content_tag(name, content = nil, options = nil, &block)
52
+ if block_given?
53
+ options = content if content.is_a?(Hash)
54
+ content = capture_html(&block)
55
+ end
56
+
57
+ options = parse_data_options(name, options)
58
+ attributes = tag_attributes(options)
59
+ output = ActiveSupport::SafeBuffer.new
60
+ output.safe_concat "<#{name}#{attributes}>"
61
+ if content.respond_to?(:each) && !content.is_a?(String)
62
+ content.each { |item| output.concat item; output.safe_concat NEWLINE }
63
+ else
64
+ output.concat content.to_s
65
+ end
66
+ output.safe_concat "</#{name}>"
67
+
68
+ output
69
+ end
70
+
71
+ private
72
+
73
+ def tag_attributes(options)
74
+ return '' unless options
75
+ options.inject('') do |all, (key, value)|
76
+ next all unless value
77
+ all << ' ' if all.empty?
78
+ all << if value.is_a?(Hash)
79
+ nested_values(key, value)
80
+ elsif BOOLEAN_ATTRIBUTES.include?(key)
81
+ %(#{key}="#{key}" )
82
+ else
83
+ %(#{key}="#{escape_value(value)}" )
84
+ end
85
+ end.chomp!(' ')
86
+ end
87
+
88
+ def escape_value(string)
89
+ string.to_s.gsub(ESCAPE_REGEXP) { |char| ESCAPE_VALUES[char] }
90
+ end
91
+
92
+ def nested_values(attribute, hash)
93
+ hash.inject('') do |all, (key, value)|
94
+ attribute_with_name = "#{attribute}-#{key.to_s.dasherize}"
95
+ all << if value.is_a?(Hash)
96
+ nested_values(attribute_with_name, value)
97
+ else
98
+ %(#{attribute_with_name}="#{escape_value(value)}" )
99
+ end
100
+ end
101
+ end
102
+
103
+ def parse_data_options(tag, options)
104
+ return unless options
105
+ parsed_options = options.dup
106
+ options.each do |key, value|
107
+ next if !DATA_ATTRIBUTES.include?(key) || (tag.to_s == 'form' && key == :method)
108
+ parsed_options["data-#{key}"] = parsed_options.delete(key)
109
+ parsed_options[:rel] = 'nofollow' if key == :method
110
+ end
111
+ parsed_options
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,5 @@
1
+ module Eldr
2
+ module Rendering
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
data/spec/app_spec.rb ADDED
@@ -0,0 +1,25 @@
1
+ describe 'ExampleApp' do
2
+ let(:app) do
3
+ path = File.expand_path('../examples/app.ru', File.dirname(__FILE__))
4
+ Rack::Builder.parse_file(path).first
5
+ end
6
+
7
+ let(:rt) do
8
+ Rack::Test::Session.new(app)
9
+ end
10
+
11
+ describe 'GET /cats' do
12
+ it 'returns a template' do
13
+ response = rt.get '/cats'
14
+ file_path = File.expand_path('../examples/views/cats.slim', File.dirname(__FILE__))
15
+ expect(response.body).to eq Tilt.new(file_path).render()
16
+ end
17
+ end
18
+
19
+ describe 'GET /no-template' do
20
+ it 'returns 404 when template not found' do
21
+ response = rt.get '/no-template'
22
+ expect(response.status).to eq(404)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,31 @@
1
+ require 'eldr'
2
+ require 'slim'
3
+
4
+ if ENV['COVERALLS_REPO_TOKEN']
5
+ require 'coveralls'
6
+ Coveralls.wear!
7
+ end
8
+
9
+ require_relative '../lib/eldr/rendering'
10
+
11
+ require 'rack/test'
12
+ require 'rack'
13
+ require 'rspec-html-matchers'
14
+
15
+ module GlobalConfig
16
+ extend RSpec::SharedContext
17
+ let(:rt) do
18
+ Rack::Test::Session.new(app)
19
+ end
20
+
21
+ let(:app) do
22
+ App.new()
23
+ end
24
+ end
25
+
26
+ RSpec.configure do |config|
27
+ config.include Rack::Test::Methods
28
+ config.include GlobalConfig
29
+ config.include Eldr::Rendering::Output
30
+ config.include Eldr::Rendering::Tags
31
+ end
@@ -0,0 +1,65 @@
1
+ describe Eldr::Rendering::Tags do
2
+ describe '#tag' do
3
+ it 'supports tags with no content and no attributes' do
4
+ expect(tag(:br)).to have_tag(:br)
5
+ end
6
+
7
+ it 'supports tags with no content with attributes' do
8
+ html = tag(:br, :style => 'clear:both', :class => 'yellow')
9
+ expect(html).to have_tag('br', :with => {:class => 'yellow', :style => 'clear:both'})
10
+ end
11
+
12
+ it 'supports selected attribute by using "selected" if true' do
13
+ html = tag(:option, :selected => true)
14
+ expect(html).to have_tag('option', :with => {:selected => 'selected'})
15
+ end
16
+
17
+ it 'supports data attributes' do
18
+ html = tag(:a, :data => { :remote => true, :method => 'post'})
19
+ expect(html).to have_tag('a', :with => {'data-remote' => 'true', 'data-method' => 'post'})
20
+ end
21
+
22
+ it 'supports nested attributes' do
23
+ html = tag(:div, :data => {:dojo => {:type => 'dijit.form.TextBox', :props => 'readOnly: true'}})
24
+ expect(html).to have_tag('div', :with => {'data-dojo-type' => 'dijit.form.TextBox', 'data-dojo-props' => 'readOnly: true'})
25
+ end
26
+
27
+ it 'supports open tags' do
28
+ html = tag(:p, { :class => 'demo' }, true)
29
+ expect("<p class=\"demo\">").to eq html
30
+ end
31
+
32
+ it 'escapes html' do
33
+ html = tag(:br, :class => 'Example <foo> & "bar"')
34
+ expect("<br class=\"Example &lt;foo&gt; &amp; &quot;bar&quot;\" />").to eq html
35
+ end
36
+ end
37
+
38
+ describe '#content_tag' do
39
+ it 'supports tags with content as parameter' do
40
+ html = content_tag(:p, "Demo", :class => 'large', :id => 'thing')
41
+ expect(html).to have_tag('p.large#thing', :text => "Demo")
42
+ end
43
+
44
+ it 'supports tags with content as block' do
45
+ html = content_tag(:p, :class => 'large', :id => 'star') { "Demo" }
46
+ expect(html).to have_tag('p.large#star', :text => "Demo")
47
+ end
48
+
49
+ it 'escapes non-html-safe content' do
50
+ html = content_tag(:p, :class => 'large', :id => 'star') { "<>" }
51
+ expect(html).to have_tag('p.large#star')
52
+ expect("<p class=\"large\" id=\"star\">&lt;&gt;</p>").to eq html
53
+ end
54
+
55
+ it 'does not escape html-safe content' do
56
+ html = content_tag(:p, :class => 'large', :id => 'star') { "<>" }
57
+ expect(html).to have_tag('p.large#star', :text => "<>")
58
+ end
59
+
60
+ it 'converts to a string if the content is not a string' do
61
+ html = content_tag(:p, 97)
62
+ expect(html).to have_tag('p', :text => "97")
63
+ end
64
+ end
65
+ end
metadata ADDED
@@ -0,0 +1,223 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eldr-rendering
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - K-2052
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: eldr
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: tilt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 10.4.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 10.4.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 3.1.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 3.1.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 0.28.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 0.28.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: rack-test
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 0.6.3
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 0.6.3
125
+ - !ruby/object:Gem::Dependency
126
+ name: coveralls
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.7'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.7'
139
+ - !ruby/object:Gem::Dependency
140
+ name: slim
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '='
144
+ - !ruby/object:Gem::Version
145
+ version: 3.0.1
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '='
151
+ - !ruby/object:Gem::Version
152
+ version: 3.0.1
153
+ - !ruby/object:Gem::Dependency
154
+ name: rspec-html-matchers
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '='
158
+ - !ruby/object:Gem::Version
159
+ version: 0.6.1
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '='
165
+ - !ruby/object:Gem::Version
166
+ version: 0.6.1
167
+ description:
168
+ email:
169
+ - k@2052.me
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".gitignore"
175
+ - ".rspec"
176
+ - ".rubocop.yml"
177
+ - ".rubocop_todo.yml"
178
+ - ".travis.yml"
179
+ - Gemfile
180
+ - Gemfile.lock
181
+ - LICENSE
182
+ - README.md
183
+ - Rakefile
184
+ - eldr-rendering.gemspec
185
+ - examples/app.ru
186
+ - examples/views/cats.slim
187
+ - lib/eldr-rendering.rb
188
+ - lib/eldr/rendering.rb
189
+ - lib/eldr/rendering/output_helpers.rb
190
+ - lib/eldr/rendering/tag_helpers.rb
191
+ - lib/eldr/rendering/version.rb
192
+ - spec/app_spec.rb
193
+ - spec/spec_helper.rb
194
+ - spec/tag_helpers_spec.rb
195
+ homepage: https://github.com/eldr-rb/eldr-rendering
196
+ licenses:
197
+ - MIT
198
+ metadata: {}
199
+ post_install_message:
200
+ rdoc_options: []
201
+ require_paths:
202
+ - lib
203
+ required_ruby_version: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - ">="
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ required_rubygems_version: !ruby/object:Gem::Requirement
209
+ requirements:
210
+ - - ">="
211
+ - !ruby/object:Gem::Version
212
+ version: '0'
213
+ requirements: []
214
+ rubyforge_project:
215
+ rubygems_version: 2.2.2
216
+ signing_key:
217
+ specification_version: 4
218
+ summary: Template helpers for Eldr apps and compatible Rack apps
219
+ test_files:
220
+ - spec/app_spec.rb
221
+ - spec/spec_helper.rb
222
+ - spec/tag_helpers_spec.rb
223
+ has_rdoc: