smithycms 0.5.2 → 0.5.99

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: 39561e91c08df383f68cdd2ab7ff4696f4ece727
4
- data.tar.gz: ab0a854d38401f183bec49e954983aac63967480
3
+ metadata.gz: 50a9ee949cfb2971b60f14b209dd95c3beec69de
4
+ data.tar.gz: a200f12370e77bb8bea791e11869d87bfd3f6d79
5
5
  SHA512:
6
- metadata.gz: 31cd8bf890e4e25f63b3f57d03ad46c7fa5ee7d9da10959b9ee16cda5d2296a71982540c015b8188b4dbc909e814e1051e570f1b7b4394b132d807a67cad36ef
7
- data.tar.gz: badd9f440124104d63627981895dc5828621ca9804ee47ef04b4bdbe2579e68d78a78d8a4bfc1c635661a72e08a2f39ae55fd0edfcb6bc2fac5d60566e25cc4d
6
+ metadata.gz: 06d59457aabae1d90fa979d84a88a1b0f906928b0ee812c5d911443519a51acd0c0d383bd58c55bb595ac24a08abb6adf81037c1996cf3f0db9f5bfc5a8303a1
7
+ data.tar.gz: c9a7ab5481b04448a95180de110624c45a364bf5b9a073a828750251bba8789767b9d125020c5c05262cf0d74ef4d4a95624931618a3a92a43dcd066526f7199
@@ -14,6 +14,13 @@ module Smithy
14
14
  respond_with @asset
15
15
  end
16
16
 
17
+ def show
18
+ @asset = Asset.find(params[:id])
19
+ respond_with @asset do |format|
20
+ format.html { redirect_to @asset.url }
21
+ end
22
+ end
23
+
17
24
  def create
18
25
  @asset = Asset.new(filtered_params)
19
26
  @asset.save
@@ -59,10 +59,14 @@ module Smithy
59
59
  'file_height' => self.file_height,
60
60
  'file_size' => self.file_size,
61
61
  'remote_url' => self.file.remote_url,
62
- 'url' => self.file.url
62
+ 'url' => self.url
63
63
  }
64
64
  end
65
65
 
66
+ def url
67
+ self.file.url
68
+ end
69
+
66
70
  private
67
71
  def set_content_types
68
72
  set_content_type(self.file, :content_type)
@@ -12,10 +12,14 @@ module Smithy
12
12
  default_scope -> { order(:name) }
13
13
 
14
14
  def liquid_template
15
- @liquid_template ||= ::Liquid::Template.parse(self.content)
15
+ @liquid_template ||= ::Liquid::Template.parse(content_with_fixed_asset_links)
16
16
  end
17
17
 
18
18
  private
19
+ def content_with_fixed_asset_links
20
+ content.gsub(/\/smithy\/assets\/([0-9]+)/) { Smithy::Asset.find($1).url }
21
+ end
22
+
19
23
  def touch_page_contents
20
24
  self.page_contents.each(&:touch)
21
25
  end
@@ -26,10 +26,14 @@ module Smithy
26
26
 
27
27
  def liquid_template
28
28
  @liquid_template ||= Rails.cache.fetch("#{self.cache_key}-liquid_template") do
29
- ::Liquid::Template.parse(self.content)
29
+ ::Liquid::Template.parse(self.content_with_fixed_asset_links)
30
30
  end
31
31
  end
32
32
 
33
+ def content_with_fixed_asset_links
34
+ content.gsub(/\/smithy\/assets\/([0-9]+)/) { Smithy::Asset.find($1).url }
35
+ end
36
+
33
37
  private
34
38
  def load_containers
35
39
  return unless self.template_type == 'template'
@@ -2,10 +2,15 @@ module Smithy
2
2
  class Formatter < ::Slodown::Formatter
3
3
 
4
4
  def render
5
- self.complete.to_s
5
+ fix_asset_links.complete.to_s
6
6
  end
7
7
 
8
8
  private
9
+ def fix_asset_links
10
+ @current = @current.gsub(/\/smithy\/assets\/([0-9]+)/) { Smithy::Asset.find($1).url }
11
+ self
12
+ end
13
+
9
14
  def kramdown_options
10
15
  { coderay_css: 'style' }
11
16
  end
@@ -5,7 +5,7 @@ module Smithy
5
5
  _include = Smithy::Template.partials.where(:name => template_path).first
6
6
  raise ActiveRecord::RecordNotFound, "No such template '#{template_path}'" unless _include.present?
7
7
 
8
- _include.content
8
+ _include.content_with_fixed_asset_links
9
9
  end
10
10
  end
11
11
  end
@@ -15,7 +15,7 @@ module Smithy
15
15
  @alt = ''
16
16
  end
17
17
  else
18
- raise ::Liquid::SyntaxError.new("Syntax Error in '#{@tag_name}' - Valid syntax: image_tag <asset_id|path>")
18
+ raise ::Liquid::SyntaxError.new("Syntax Error in '#{@tag_name}' - Valid syntax: asset_image_tag <asset_id|path>")
19
19
  end
20
20
  super
21
21
  end
@@ -31,12 +31,12 @@ module Smithy
31
31
  if markup =~ Syntax
32
32
  @asset_id = $1.gsub('\'', '')
33
33
  if @asset = ::Smithy::Asset.find_by_id(@asset_id)
34
- @url = @asset.file.url
34
+ @url = @asset.url
35
35
  else
36
- @url = @asset_id
36
+ @url = controller.smithy_asset_path(@asset_id)
37
37
  end
38
38
  else
39
- raise ::Liquid::SyntaxError.new("Syntax Error in '#{@tag_name}' - Valid syntax: file_path <asset_id|path>")
39
+ raise ::Liquid::SyntaxError.new("Syntax Error in '#{@tag_name}' - Valid syntax: asset_file_path <asset_id|path>")
40
40
  end
41
41
  super
42
42
  end
@@ -1,3 +1,3 @@
1
1
  module Smithy
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.99"
3
3
  end
@@ -1,4 +1,32 @@
1
- # desc "Explaining what the task does"
2
- # task :smithy do
3
- # # Task goes here
4
- # end
1
+ namespace :smithy do
2
+ desc "Track down any usage of linking directly to Smithy Assets. Use /smithy/assets/1 instead"
3
+ task :find_direct_asset_links do
4
+ Smithy::Template.where('content LIKE ? OR content LIKE ?', '%s3.amazonaws.com%', '%/uploads/assets/%').each do |template|
5
+ puts "[WARNING] Direct Link found in the Template: #{template.name}"
6
+ find_and_print_matches(template.content)
7
+ end
8
+
9
+ Smithy::Content.where('content LIKE ? OR content LIKE ?', '%s3.amazonaws.com%', '%/uploads/assets/%').each do |content|
10
+ content.page_contents.each do |page_content|
11
+ puts "[WARNING] Direct Link found in the Page: #{page_content.page.title} - #{page_content.page.url}"
12
+ puts " Content Block(s): #{page_content.label}"
13
+ find_and_print_matches(content.content)
14
+ end
15
+ end
16
+ end
17
+
18
+ def find_and_print_matches(content)
19
+ asset_regex = /(?:https?:\/\/.*s3\.amazonaws\.com|\/uploads\/assets)[a-z0-9\/\._-]+/i
20
+ content.scan(asset_regex) do |match|
21
+ puts " #{match}\n"
22
+ if Smithy::Asset.where("file_name LIKE ?", "%#{File.basename(match)}%").size > 0
23
+ puts " Possible Match(es):"
24
+ Smithy::Asset.where("file_name LIKE ?", "%#{File.basename(match)}%").map{|a| "/smithy/assets/#{a.id}"}.each do |link|
25
+ puts " #{link}"
26
+ end
27
+ end
28
+ end
29
+ puts "\n"
30
+ end
31
+
32
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smithycms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.99
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Glen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-29 00:00:00.000000000 Z
11
+ date: 2016-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails