xhive 1.6.0 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -245,7 +245,7 @@ mapper = Xhive::Mapper.map_resource(site, posts_page, 'posts', 'index')
245
245
  If you want to map the page to a specific post
246
246
 
247
247
  ```ruby
248
- mapper = Xhive::Mapper.map_resource(site, posts_page, 'posts', 'index', post.id)
248
+ mapper = Xhive::Mapper.map_resource(site, posts_page, 'posts', 'show', post.id)
249
249
  ```
250
250
 
251
251
  From your posts controller, render the posts page
@@ -279,7 +279,7 @@ class MyPolicyClass
279
279
  end
280
280
  end
281
281
 
282
- mapper = Xhive::Mapper.map_resource(site, posts_page, 'posts', 'index', post.id, 'MyPolicyClass')
282
+ mapper = Xhive::Mapper.map_resource(site, posts_page, 'posts', 'show', post.id, 'MyPolicyClass')
283
283
 
284
284
  # It will only use the page if the user is an adult from the US
285
285
  render_page_with @post.id, :post => @post, :user => @user
@@ -371,6 +371,7 @@ Then you can add your inline page into your email page using the corresponding t
371
371
 
372
372
  ## TODO
373
373
 
374
+ * Transform inline stylesheet images URLs to absolute URLs to use with ActionMailer
374
375
  * Remove as many dependencies as possible
375
376
  * Improve test coverage
376
377
 
@@ -7,6 +7,7 @@ module Xhive
7
7
  include Rails.application.routes.url_helpers
8
8
 
9
9
  default_url_options[:host] = (Rails.application.config.action_mailer.default_url_options || {}).fetch(:host, 'localhost')
10
+ default_url_options[:port] = (Rails.application.config.action_mailer.default_url_options || {}).fetch(:port, '3000')
10
11
 
11
12
  def initialize(object)
12
13
  @object = object
@@ -31,5 +32,23 @@ module Xhive
31
32
  @object
32
33
  end
33
34
  end
35
+
36
+ # Private: returns the xhive url for the requested resource
37
+ #
38
+ def url_for(resource, params = {}, options = {})
39
+ Xhive.railtie_routes_url_helpers.send("#{resource}_url", params, options.merge(default_url_options))
40
+ end
41
+
42
+ # Private: returns the xhive url for the requested resource
43
+ #
44
+ def path_for(resource, params = {})
45
+ url_for(resource, params, :only_path => true)
46
+ end
47
+
48
+ # Private: returns the base images path
49
+ #
50
+ def base_images_path
51
+ path_for('image', 'sample.png').gsub('/sample.png', '')
52
+ end
34
53
  end
35
54
  end
@@ -17,7 +17,7 @@ module Xhive
17
17
  rescue => e
18
18
  log_error(e)
19
19
  ensure
20
- return result.to_s
20
+ return filter_images_urls(result.to_s)
21
21
  end
22
22
 
23
23
  # Public: renders the page title.
@@ -43,6 +43,12 @@ module Xhive
43
43
  {'page' => self, 'user' => safe_user}.merge(liquified.stringify_keys)
44
44
  end
45
45
 
46
+ def filter_images_urls(content)
47
+ images_path = base_images_path
48
+ # This only works if string is interpolated o_O
49
+ "#{content}".gsub(/src\=['"]?#{images_path}\/([^\'^\"]+)['"]?/) {|| "src='#{url_for('image', $1)}'"}
50
+ end
51
+
46
52
  def log_error(e)
47
53
  logger.error "#{e.class.name}: #{e.message}"
48
54
  logger.error e.backtrace.join("/n")
@@ -1,17 +1,21 @@
1
1
  module Xhive
2
2
  class StylesheetPresenter < Xhive::BasePresenter
3
3
  presents :stylesheet
4
- delegate :name, :content, :to => :stylesheet
4
+ delegate :name, :to => :stylesheet
5
5
 
6
6
  liquid_methods :name, :content, :compressed
7
7
 
8
+ def content
9
+ filter_images_urls(stylesheet.content)
10
+ end
11
+
8
12
  def compressed
9
- self.class.compress(stylesheet.content)
13
+ self.class.compress(content)
10
14
  end
11
15
 
12
16
  def self.all_compressed(stylesheets)
13
17
  stylesheets.inject('') do |result, stylesheet|
14
- result << compress(stylesheet.content)
18
+ result << compress(content)
15
19
  end
16
20
  end
17
21
 
@@ -27,5 +31,10 @@ module Xhive
27
31
  engine = Sass::Engine.new(content, :syntax => :scss, :style => :compressed)
28
32
  engine.render
29
33
  end
34
+
35
+ def filter_images_urls(content)
36
+ images_path = base_images_path
37
+ content.gsub(/url\(['"]?#{images_path}\/([^\'^\"]+)['"]?\)/) {|| "url('#{url_for('image', $1)}')"}
38
+ end
30
39
  end
31
40
  end
data/lib/xhive/engine.rb CHANGED
@@ -16,7 +16,7 @@ module Xhive
16
16
  self.class_variable_set('@@current_controller', nil)
17
17
  end
18
18
  end
19
- initializer "xhive.load_all_controller_classes", :after=> :disable_dependency_loading do
19
+ initializer "xhive.load_all_controller_classes", :after => :disable_dependency_loading do
20
20
  ActiveSupport.on_load(:action_controller) do
21
21
  Dir[Rails.root.join("app/controllers/**/*.rb")].each {|f| require f}
22
22
  Xhive::Router::Cells.process_routes
data/lib/xhive/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Xhive
2
- VERSION = "1.6.0"
2
+ VERSION = "1.6.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xhive
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.1
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: 2012-11-29 00:00:00.000000000 Z
12
+ date: 2012-12-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -284,7 +284,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
284
284
  version: '0'
285
285
  segments:
286
286
  - 0
287
- hash: 31275926893044133
287
+ hash: 4096513419802856694
288
288
  required_rubygems_version: !ruby/object:Gem::Requirement
289
289
  none: false
290
290
  requirements:
@@ -293,7 +293,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
293
293
  version: '0'
294
294
  segments:
295
295
  - 0
296
- hash: 31275926893044133
296
+ hash: 4096513419802856694
297
297
  requirements: []
298
298
  rubyforge_project:
299
299
  rubygems_version: 1.8.21