client_pages 0.0.3.beta → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 651585c4dbeab42b84039c22aec54878b9f54426
4
- data.tar.gz: df24efef446ba402721bf025295c0d978103dfd4
3
+ metadata.gz: d193fa65ba3d80471b486aff88d4ab9392ef39e2
4
+ data.tar.gz: 9ca9c1d6e184188d711b08f04e32f6788b01b264
5
5
  SHA512:
6
- metadata.gz: 4f859d580c6ba704bec2fd9dcbb05baa4208bae91c355c6c8618f55d9a46ce32bceeaa0b4bab8622ca4b2279dcd7a6d577908a33bfc664e39e4b391b122071d6
7
- data.tar.gz: 9812ecd03067ce9907d6fe3d0c1fd58d6625877fb1f2d44a67af5ec5535e373187abc1aa4313cb82db0184968cf472ffa59c32d0d4b14a459988942aecad49f2
6
+ metadata.gz: 782054588bfe71e9483a492e95e1ace9b51fd37839f507796fb5a560136cfd123f14274fd68780bcae2edb9aed7289b9cc07f0bf853b6fc693e7e3b20835eaee
7
+ data.tar.gz: fa2bb9d7498d84aa797089b1cbb6faae58d89da9061cc3094b4470e46730e41ac35a642a64203a8b9740605946f7ac6fab82414b3428e290fe659b2faf980a80
data/README.md CHANGED
@@ -72,7 +72,7 @@ no framework? pure rack?
72
72
  for convenience you can add ``` include ClientPages::MarkdownContent ``` to your application controller/view_helper/presenter/... or something which is responsible for building html
73
73
  so that you can call ```render_content``` there.
74
74
 
75
- or if you're riding the real blank slate, just call ```ClientPages::MarkdownContent.render_content``` directly. **WRONG!!!**
75
+ or if you're riding the real blank slate, just call ```ClientPages.render_content``` directly.
76
76
 
77
77
  sinatra?
78
78
 
@@ -106,9 +106,10 @@ sinatra?
106
106
  - by default...
107
107
  - content_path
108
108
  - if you go the full remote path without fallback, you might consider to turn on caching.
109
+ - s3 ?
109
110
 
110
111
  ```
111
- ClientPages.config do |c|
112
+ ClientPages.configure do |c|
112
113
  c.remote = true
113
114
  c.remote_content_path = 'https://dl.dropboxusercontent.com/u/363312/rackedy_rack'
114
115
  c.content_path = 'content'
data/client_pages.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.homepage = ''
18
18
  s.license = 'MIT'
19
19
 
20
- s.files = `git ls-files`.split($/)
20
+ s.files = `git ls-files`.split($/) - Dir['examples/**/*'] - %w(.gitignore)
21
21
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
22
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
23
23
  s.require_paths = ['lib']
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
27
27
  s.add_development_dependency 'bundler', '~> 1.5.3'
28
28
  s.add_development_dependency 'rake', '~> 10.1.1'
29
29
  s.add_development_dependency 'rspec', '~> 2.14.1'
30
- s.add_development_dependency 'webmock', '~> 1.17.3'
30
+ s.add_development_dependency 'webmock', '~> 1.17.4'
31
31
  s.add_development_dependency 'pry-plus', '~> 1.0.0'
32
32
  s.add_development_dependency 'rubocop', '~> 0.18.1'
33
33
  s.add_development_dependency 'flog', '~> 4.2.0'
@@ -1,6 +1,6 @@
1
1
  module ClientPages
2
2
  class Configuration
3
- attr_accessor :content_path, :remote, :remote_content_path, :caching, :fallback, :i18n, :raw_markdown
3
+ attr_accessor :content_path, :remote, :remote_content_path, :caching, :raw_markdown
4
4
  attr_reader :render_options, :markdown_extensions
5
5
 
6
6
  def initialize
@@ -10,20 +10,15 @@ module ClientPages
10
10
  end
11
11
 
12
12
  def render_options=(options)
13
- @render_options.merge!(options)
13
+ render_options.merge!(options)
14
14
  end
15
15
 
16
16
  def markdown_extensions=(options)
17
- @markdown_extensions.merge!(options)
17
+ markdown_extensions.merge!(options)
18
18
  end
19
19
 
20
20
  def to_hash
21
- # TODO: instance vars get
22
- {
23
- content_path: content_path,
24
- render_options: render_options,
25
- markdown_extensions: markdown_extensions
26
- }
21
+ Hash[instance_variables.map { |name| [name[1..-1].to_sym, instance_variable_get(name)] }]
27
22
  end
28
23
  end
29
24
  end
@@ -41,7 +41,7 @@ module ClientPages
41
41
 
42
42
  def conditions(tag, line, condition)
43
43
  return yield if condition.nil?
44
- if condition.respond_to?(:call) && condition.call(Matcher.new(tag, line))
44
+ if condition.respond_to?(:call) && Matcher.new(tag, line).instance_exec(&condition)
45
45
  yield
46
46
  elsif condition.is_a?(Hash) && Matcher.new(tag, line).match_all?(condition)
47
47
  yield
@@ -2,9 +2,9 @@ module ClientPages
2
2
  module MarkdownContent
3
3
  class Renderer
4
4
  class << self
5
- def render_content(file, options = {})
5
+ def render_content(file, options = {}, &block)
6
6
  html = new(file, options).html
7
- block_given? ? yield(ContentBuilder.new(html)) : html.strip
7
+ block_given? ? ContentBuilder.new(html).instance_eval(&block) : html.strip
8
8
  rescue OpenURI::HTTPError
9
9
  "404: could not find '#{file}'"
10
10
  rescue Errno::ENOENT
@@ -22,7 +22,7 @@ module ClientPages
22
22
 
23
23
  def html
24
24
  html = html_from_markdown
25
- html = template.call(ContentBuilder.new(html)) if options.key?(:template)
25
+ html = template(html) if options.key?(:template)
26
26
  html
27
27
  end
28
28
 
@@ -40,8 +40,8 @@ module ClientPages
40
40
  Redcarpet::Markdown.new(html_renderer, extensions).render(markdown)
41
41
  end
42
42
 
43
- def template
44
- ClientPages.template[options[:template]]
43
+ def template(html)
44
+ ContentBuilder.new(html).instance_eval(&Template[options[:template]])
45
45
  end
46
46
 
47
47
  def markdown
@@ -1,7 +1,21 @@
1
1
  module ClientPages
2
2
  class Template
3
- def set(name, &settings)
4
- ClientPages.template[name] = Proc.new(&settings)
3
+ class << self
4
+ def templates
5
+ @templates ||= {}
6
+ end
7
+
8
+ def template(name, &settings)
9
+ templates[name] = Proc.new(&settings)
10
+ end
11
+
12
+ def [](template)
13
+ templates[template]
14
+ end
15
+
16
+ def templating(&block)
17
+ instance_eval(&block)
18
+ end
5
19
  end
6
20
  end
7
21
  end
@@ -1,3 +1,3 @@
1
1
  module ClientPages
2
- VERSION = '0.0.3.beta'
2
+ VERSION = '0.0.5'
3
3
  end
data/lib/client_pages.rb CHANGED
@@ -14,19 +14,18 @@ module ClientPages
14
14
  end
15
15
 
16
16
  class << self
17
+ extend Forwardable
17
18
  attr_accessor :configuration
18
19
 
20
+ def_delegator MarkdownContent::Renderer, :render_content
21
+ def_delegator Template, :templating
22
+
19
23
  def config
20
24
  self.configuration ||= Configuration.new
21
- block_given? ? yield(configuration) : configuration
22
- end
23
-
24
- def template
25
- @template ||= {}
26
25
  end
27
26
 
28
- def templates(&block)
29
- yield Template.new
27
+ def configure
28
+ yield(config)
30
29
  end
31
30
 
32
31
  def cache
@@ -2,25 +2,25 @@ require 'spec_helper'
2
2
 
3
3
  module ClientPages
4
4
  describe 'MarkdownContent' do
5
- subject { ClientPages::MarkdownContent::Renderer }
5
+ subject { ClientPages }
6
6
 
7
7
  describe 'invalid path' do
8
- before { ClientPages.config { |c| c.content_path = 'not_there' } }
8
+ before { ClientPages.configure { |c| c.content_path = 'not_there' } }
9
9
  it { expect(subject.render_content(:bar)).to eql('No such file or directory - bar') }
10
10
  end
11
11
 
12
12
  describe 'valid path' do
13
- before { ClientPages.config { |c| c.content_path = 'spec/fixtures/foo' } }
13
+ before { ClientPages.configure { |c| c.content_path = 'spec/fixtures/foo' } }
14
14
  it { expect(subject.render_content(:bar)).to eql("<h1>foo</h1>\n\n<p>bar</p>") }
15
15
  end
16
16
 
17
17
  it 'blends' do
18
18
  expect(
19
- subject.render_content(:test_content) do |c|
20
- c.modify :h1, with: { class: 'mycss_class', 'data-foo' => 'bar' }, if: ->(m) { m.includes?('Content') }
21
- c.modify :a, with: { class: 'fancy', title: 'woah' }, if: { href: 'http://somewhere.com' }
22
- c.wrap :h1, :div, with: { id: 'my-id', class: 'foo' }
23
- c.replace :p, :span, with: { class: 'bar', 'data-p' => 'no-more' }
19
+ subject.render_content(:test_content) do
20
+ modify :h1, with: { class: 'mycss_class', 'data-foo' => 'bar' }, if: -> { includes?('Content') }
21
+ modify :a, with: { class: 'fancy', title: 'woah' }, if: { href: 'http://somewhere.com' }
22
+ wrap :h1, :div, with: { id: 'my-id', class: 'foo' }
23
+ replace :p, :span, with: { class: 'bar', 'data-p' => 'no-more' }
24
24
  end
25
25
  ).to eql(
26
26
  "<div id=\"my-id\" class=\"foo\"><h1 class=\"mycss_class\" data-foo=\"bar\">Content from "\
@@ -35,7 +35,7 @@ module ClientPages
35
35
  let(:markdown) { fixture('test_content') }
36
36
 
37
37
  before do
38
- ClientPages.config do |c|
38
+ ClientPages.configure do |c|
39
39
  c.remote = true
40
40
  c.caching = false
41
41
  c.remote_content_path = 'http://somewhere.com'
@@ -53,7 +53,7 @@ module ClientPages
53
53
 
54
54
  describe 'raw markdown' do
55
55
  before do
56
- ClientPages.config { |c| c.raw_markdown = true }
56
+ ClientPages.configure { |c| c.raw_markdown = true }
57
57
  end
58
58
 
59
59
  it 'renders HTML content for given markdown' do
@@ -78,9 +78,9 @@ module ClientPages
78
78
 
79
79
  it 'modifies tags and html attributes' do
80
80
  expect(
81
- subject.render_content(:test_content) do |c|
82
- c.modify :h1, with: { class: 'mycss_class', 'data-foo' => 'bar' }
83
- c.modify :a, with: { class: 'fancy', title: 'woah' }
81
+ subject.render_content(:test_content) do
82
+ modify :h1, with: { class: 'mycss_class', 'data-foo' => 'bar' }
83
+ modify :a, with: { class: 'fancy', title: 'woah' }
84
84
  end
85
85
  ).to include(
86
86
  '<h1 class="mycss_class" data-foo="bar">'\
@@ -91,9 +91,9 @@ module ClientPages
91
91
 
92
92
  it 'adds attributes conditionally' do
93
93
  expect(
94
- subject.render_content(:test_content) do |c|
95
- c.modify :h1, with: { class: 'add_me cool' }, if: true
96
- c.modify :a, with: { class: 'add_me_not' }, if: false
94
+ subject.render_content(:test_content) do
95
+ modify :h1, with: { class: 'add_me cool' }, if: true
96
+ modify :a, with: { class: 'add_me_not' }, if: false
97
97
  end
98
98
  ).to include(
99
99
  '<h1 class="add_me cool">Content from <a href="http://somewhere.com">somewhere</a></h1>'
@@ -102,10 +102,10 @@ module ClientPages
102
102
 
103
103
  it 'adds any attribute conditionally and selective' do
104
104
  expect(
105
- subject.render_content(:link_list) do |c|
106
- c.modify :li, with: { class: 'yay' }, if: ->(m) { m.match_any?(:href, '/link1') }
107
- c.modify :a, with: { class: 'active' }, if: { href: '/link2' }
108
- c.modify :a, with: { class: 'important', 'data-foo' => 'bar' }, if: { title: 'i haz title' }
105
+ subject.render_content(:link_list) do
106
+ modify :li, with: { class: 'yay' }, if: -> { match_any?(:href, '/link1') }
107
+ modify :a, with: { class: 'active' }, if: { href: '/link2' }
108
+ modify :a, with: { class: 'important', 'data-foo' => 'bar' }, if: { title: 'i haz title' }
109
109
  end
110
110
  ).to include(
111
111
  "<li class=\"yay\"><a href=\"/link1\">link1</a></li>\n"\
@@ -116,9 +116,9 @@ module ClientPages
116
116
 
117
117
  it 'wraps multiple tags with container' do
118
118
  expect(
119
- subject.render_content(:text_list) do |c|
120
- c.wrap :ul, :div, with: { class: 'wrapper foo' }
121
- c.wrap :em, :span, with: { class: 'special' }, if: ->(m) { m.includes?('Bar') }
119
+ subject.render_content(:text_list) do
120
+ wrap :ul, :div, with: { class: 'wrapper foo' }
121
+ wrap :em, :span, with: { class: 'special' }, if: -> { includes?('Bar') }
122
122
  end
123
123
  ).to eql(
124
124
  "<div class=\"wrapper foo\"><ul>\n"\
@@ -130,9 +130,9 @@ module ClientPages
130
130
 
131
131
  it 'wraps and modifies tags' do
132
132
  expect(
133
- subject.render_content(:text_list) do |c|
134
- c.wrap :ul, :div, with: { class: 'container' }
135
- c.modify :em, with: { style: 'color: #c0ffee' }
133
+ subject.render_content(:text_list) do
134
+ wrap :ul, :div, with: { class: 'container' }
135
+ modify :em, with: { style: 'color: #c0ffee' }
136
136
  end
137
137
  ).to eql(
138
138
  "<div class=\"container\"><ul>\n"\
@@ -144,9 +144,9 @@ module ClientPages
144
144
 
145
145
  it 'replaces tags and adds class' do
146
146
  expect(
147
- subject.render_content(:test_content) do |c|
148
- c.replace :p, :div, with: { class: 'byebye' }
149
- c.replace :em, :span, with: { id: 'i-am', class: 'cool', 'data-u' => 'r-not' }
147
+ subject.render_content(:test_content) do
148
+ replace :p, :div, with: { class: 'byebye' }
149
+ replace :em, :span, with: { id: 'i-am', class: 'cool', 'data-u' => 'r-not' }
150
150
  end
151
151
  ).to eql(
152
152
  "<h1>Content from <a href=\"http://somewhere.com\">somewhere</a></h1>\n\n"\
@@ -159,10 +159,10 @@ module ClientPages
159
159
 
160
160
  it 'wraps and replaces conditionally' do
161
161
  expect(
162
- subject.render_content(:test_content) do |c|
163
- c.wrap :a, :span, with: { class: 'btn' }, if: { href: 'http://somewhere.com' }
164
- c.replace :p, :div, if: ->(m) { m.includes?('Lorem') }
165
- c.replace :em, :span, with: { class: 'replaced' }, if: ->(m) { m.includes?('incididunt') }
162
+ subject.render_content(:test_content) do
163
+ wrap :a, :span, with: { class: 'btn' }, if: { href: 'http://somewhere.com' }
164
+ replace :p, :div, if: -> { includes?('Lorem') }
165
+ replace :em, :span, with: { class: 'replaced' }, if: -> { includes?('incididunt') }
166
166
  end
167
167
  ).to eql(
168
168
  "<h1>Content from <span class=\"btn\"><a href=\"http://somewhere.com\">somewhere</a></span></h1>\n\n"\
@@ -174,11 +174,11 @@ module ClientPages
174
174
 
175
175
  describe 'with caching' do
176
176
  before(:each) { ClientPages.cache.clear }
177
- after { ClientPages.config { |c| c.caching = false } }
177
+ after { ClientPages.configure { |c| c.caching = false } }
178
178
 
179
179
  context 'enabled' do
180
180
  before do
181
- ClientPages.config do |c|
181
+ ClientPages.configure do |c|
182
182
  c.caching = true
183
183
  c.remote = true
184
184
  c.remote_content_path = 'http://c.ly'
@@ -203,7 +203,7 @@ module ClientPages
203
203
 
204
204
  context 'disabled' do
205
205
  before do
206
- ClientPages.config do |c|
206
+ ClientPages.configure do |c|
207
207
  c.caching = false
208
208
  c.remote = true
209
209
  c.remote_content_path = 'http://c.ly'
@@ -226,19 +226,19 @@ module ClientPages
226
226
 
227
227
  describe 'default templates' do
228
228
  before do
229
- ClientPages.templates do |t|
230
- t.set(:basic) do |c|
231
- c.modify :h1, with: { class: 'headers' }
232
- c.wrap :a, :span, with: { class: 'links' }, if: ->(m) { m.includes?('somewhere') }
233
- c.replace :p, :div
229
+ ClientPages.templating do
230
+ template :basic do
231
+ modify :h1, with: { class: 'headers' }
232
+ wrap :a, :span, with: { class: 'links' }, if: -> { includes?('somewhere') }
233
+ replace :p, :div
234
234
  end
235
235
  end
236
236
  end
237
237
 
238
238
  it 'uses templates and accepts additional block' do
239
239
  expect(
240
- subject.render_content(:test_content, template: :basic) do |c|
241
- c.modify :h1, with: { 'data-foo' => 'bar' }
240
+ subject.render_content(:test_content, template: :basic) do
241
+ modify :h1, with: { 'data-foo' => 'bar' }
242
242
  end
243
243
  ).to eql(
244
244
  "<h1 class=\"headers\" data-foo=\"bar\">Content from <span class=\"links\">"\
@@ -256,7 +256,7 @@ module ClientPages
256
256
 
257
257
  it 'is configurable with a block' do
258
258
  expect {
259
- subject.config do |c|
259
+ subject.configure do |c|
260
260
  c.content_path = 'somewhere'
261
261
  c.render_options = { foo: 'bar' }
262
262
  c.markdown_extensions = { bam: true }
data/spec/spec_helper.rb CHANGED
@@ -25,7 +25,7 @@ RSpec.configure do |config|
25
25
  end
26
26
 
27
27
  config.before(:each) do
28
- ClientPages.config do |c|
28
+ ClientPages.configure do |c|
29
29
  c.remote = false
30
30
  c.caching = false
31
31
  c.content_path = 'spec/fixtures/content'
@@ -1,16 +1,29 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module ClientPages
4
- describe 'Template' do
5
- let(:templates) { {} }
4
+ describe Template do
5
+ subject { described_class }
6
6
 
7
- before do
8
- expect(ClientPages).to receive(:template) { templates }
9
- Template.new.set(:foo) { |args| 'foobar' + args }
7
+ describe '#template' do
8
+ before do
9
+ subject.template(:foo) { |args| 'foobar' + args }
10
+ end
11
+
12
+ it 'saves a referenceable block with arguments' do
13
+ expect(subject.templates[:foo].call('bam')).to eql('foobarbam')
14
+ end
10
15
  end
11
16
 
12
- it 'saves a referenceable block with arguments' do
13
- expect(templates[:foo].call('bam')).to eql('foobarbam')
17
+ context 'in a templating block' do
18
+ before do
19
+ subject.templating do
20
+ template(:bar) { '42' }
21
+ template(:baz) { 'yay' }
22
+ end
23
+ end
24
+
25
+ it { expect(subject[:bar].call).to eql('42') }
26
+ it { expect(subject[:baz].call).to eql('yay') }
14
27
  end
15
28
  end
16
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: client_pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.beta
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Schaden
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-07 00:00:00.000000000 Z
11
+ date: 2014-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - ~>
74
74
  - !ruby/object:Gem::Version
75
- version: 1.17.3
75
+ version: 1.17.4
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ~>
81
81
  - !ruby/object:Gem::Version
82
- version: 1.17.3
82
+ version: 1.17.4
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: pry-plus
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -146,7 +146,6 @@ executables: []
146
146
  extensions: []
147
147
  extra_rdoc_files: []
148
148
  files:
149
- - .gitignore
150
149
  - .rubocop.yml
151
150
  - Gemfile
152
151
  - LICENSE.txt
@@ -186,9 +185,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
185
  version: '0'
187
186
  required_rubygems_version: !ruby/object:Gem::Requirement
188
187
  requirements:
189
- - - '>'
188
+ - - '>='
190
189
  - !ruby/object:Gem::Version
191
- version: 1.3.1
190
+ version: '0'
192
191
  requirements: []
193
192
  rubyforge_project:
194
193
  rubygems_version: 2.1.11
data/.gitignore DELETED
@@ -1,20 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- .rspec
7
- Gemfile.lock
8
- InstalledFiles
9
- _yardoc
10
- coverage
11
- doc/
12
- lib/bundler/man
13
- pkg
14
- rdoc
15
- spec/reports
16
- test/tmp
17
- test/version_tmp
18
- tmp
19
- .rvmrc
20
- *.notes