shuffling code so it can be reused outside the engine
This commit is contained in:
parent
ab1f8ef4a8
commit
c58b5fc4ba
@ -1,35 +1,8 @@
|
|||||||
require "redcarpet"
|
|
||||||
|
|
||||||
module Merged
|
module Merged
|
||||||
module MergedHelper
|
module MergedHelper
|
||||||
include OptionsHelper
|
include OptionsHelper
|
||||||
|
include SharedHelper
|
||||||
def renderer
|
|
||||||
options = {hard_wrap: true , autolink: true, no_intra_emphasis: true ,
|
|
||||||
safe_links_only: true, no_styles: true ,
|
|
||||||
link_attributes: { target: '_blank' }}
|
|
||||||
html = Redcarpet::Render::HTML.new(options)
|
|
||||||
Redcarpet::Markdown.new(html, options)
|
|
||||||
end
|
|
||||||
|
|
||||||
def prose_classes
|
|
||||||
classes = "prose lg:prose-lg "
|
|
||||||
classes += "prose-headings:text-inherit "
|
|
||||||
{ class: classes }
|
|
||||||
end
|
|
||||||
|
|
||||||
def markdown_image(section)
|
|
||||||
return "" unless section.text
|
|
||||||
down = self.renderer.render(section.text)
|
|
||||||
image = image_for(section)
|
|
||||||
down.gsub("IMAGE" , image).html_safe
|
|
||||||
end
|
|
||||||
|
|
||||||
def markdown(text)
|
|
||||||
text = text.text unless text.is_a?(String)
|
|
||||||
return "" if text.blank?
|
|
||||||
self.renderer.render(text).html_safe
|
|
||||||
end
|
|
||||||
|
|
||||||
def aspect_ratio image
|
def aspect_ratio image
|
||||||
x , y = image.aspect_ratio
|
x , y = image.aspect_ratio
|
||||||
|
@ -25,34 +25,28 @@ module Merged
|
|||||||
end
|
end
|
||||||
|
|
||||||
def copy()
|
def copy()
|
||||||
image = Image.new name: "#{name}_copy" , type: type , tags: (tags || "")
|
image = Image.new name: "#{name}_copy" , type: type , tags: (tags || "") ,
|
||||||
|
width: width , height: height, size: size
|
||||||
Image.insert(image) # assigns next id
|
Image.insert(image) # assigns next id
|
||||||
FileUtils.cp full_filename , image.full_filename
|
FileUtils.cp full_filename , image.full_filename
|
||||||
image.init_file_data
|
|
||||||
image
|
image
|
||||||
end
|
end
|
||||||
|
|
||||||
#save an io as new image. The filename is the id, type taken from io
|
#save an io as new image. The filename is the id, type taken from io
|
||||||
def self.create_new(name , tags, io)
|
def self.create_new(name , tags, io)
|
||||||
original , ending = io.original_filename.split("/").last.split(".")
|
original , end_ = io.original_filename.split("/").last.split(".")
|
||||||
|
magick_image = MiniMagick::Image.read(io)
|
||||||
|
ending = magick_image.type.downcase
|
||||||
name = original if( name.blank? )
|
name = original if( name.blank? )
|
||||||
image = Image.new name: name , type: ending , tags: (tags || "")
|
image = Image.new name: name , type: ending , tags: (tags || "") ,
|
||||||
|
width: magick_image.width, height: magick_image.height ,
|
||||||
|
size: (magick_image.size/1024).to_i
|
||||||
self.insert(image) # assigns next id
|
self.insert(image) # assigns next id
|
||||||
full_filename = image.id.to_s + "." + ending
|
full_filename = image.id.to_s + "." + ending
|
||||||
File.open(Rails.root.join("app/assets/images/cms/", full_filename), "wb") do |file|
|
magick_image.write(Rails.root.join("app/assets/images/cms/", full_filename))
|
||||||
file.write( io.read )
|
|
||||||
end
|
|
||||||
image.init_file_data
|
|
||||||
image
|
image
|
||||||
end
|
end
|
||||||
|
|
||||||
def init_file_data
|
|
||||||
image = MiniMagick::Image.new(full_filename)
|
|
||||||
self.width = image.width
|
|
||||||
self.height = image.height
|
|
||||||
self.size = (image.size/1024).to_i
|
|
||||||
end
|
|
||||||
|
|
||||||
def destroy(editor)
|
def destroy(editor)
|
||||||
File.delete self.full_filename
|
File.delete self.full_filename
|
||||||
delete_save!(editor)
|
delete_save!(editor)
|
||||||
|
@ -4,6 +4,7 @@ require "ruby2js/es2015"
|
|||||||
require "ruby2js/filter/functions"
|
require "ruby2js/filter/functions"
|
||||||
require "ruby2js/haml"
|
require "ruby2js/haml"
|
||||||
require "ruby2js/filter/vue"
|
require "ruby2js/filter/vue"
|
||||||
|
require "merged/shared_helper"
|
||||||
|
|
||||||
module Merged
|
module Merged
|
||||||
class Engine < ::Rails::Engine
|
class Engine < ::Rails::Engine
|
||||||
|
34
lib/merged/shared_helper.rb
Normal file
34
lib/merged/shared_helper.rb
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
require "redcarpet"
|
||||||
|
|
||||||
|
module Merged
|
||||||
|
module SharedHelper
|
||||||
|
|
||||||
|
def renderer
|
||||||
|
options = {hard_wrap: true , autolink: true, no_intra_emphasis: true ,
|
||||||
|
safe_links_only: true, no_styles: true ,
|
||||||
|
link_attributes: { target: '_blank' }}
|
||||||
|
html = Redcarpet::Render::HTML.new(options)
|
||||||
|
Redcarpet::Markdown.new(html, options)
|
||||||
|
end
|
||||||
|
|
||||||
|
def prose_classes
|
||||||
|
classes = "prose lg:prose-lg "
|
||||||
|
classes += "prose-headings:text-inherit "
|
||||||
|
{ class: classes }
|
||||||
|
end
|
||||||
|
|
||||||
|
def markdown_image(section)
|
||||||
|
return "" unless section.text
|
||||||
|
down = self.renderer.render(section.text)
|
||||||
|
image = image_for(section)
|
||||||
|
down.gsub("IMAGE" , image).html_safe
|
||||||
|
end
|
||||||
|
|
||||||
|
def markdown(text)
|
||||||
|
text = text.text unless text.is_a?(String)
|
||||||
|
return "" if text.blank?
|
||||||
|
self.renderer.render(text).html_safe
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user