* Update rubocop-todo.yml with new violations * Fix Layout/EmptyLine* rules * Fix Layout/Indentation* rules * Fix remaining Layout/* rules * Fix Lint/DuplicateMethods by removing unused accessor * Fix Lint/IneffectiveAccessModifier * Fix Lint/MissingCopEnableDirective * Re-run rubocop auto gen config * Fix Layout/RescueEnsureAlignment * Fix Naming/* rules * Fix some RSpec/* rules * Fix typos * Fix RSpec/LetBeforeExamples * Series should only be an attr_writer, not an attr_accessor * Fix RSpec/InstanceVariable * Fix RSpec/InstanceVariable * Fix RSpec/RepeatedDescription and RSpec/RepeatedExample * Fix Style/ClassAndModuleChildren * Fix Style/ConditionalAssignment * Fix some Style/* rules * Trigger Travis CI build because failing tests are not failing locally * Revert "Fix Style/ClassAndModuleChildren" This reverts commit 1686801d8a1516ba1894f79e24401a20dea65f99.
41 lines
834 B
Ruby
41 lines
834 B
Ruby
class Block < ApplicationRecord
|
|
attr_accessor :publish_now
|
|
|
|
belongs_to :user
|
|
|
|
validate :permissions
|
|
|
|
before_save :process_html
|
|
before_save :process_javascript
|
|
before_save :process_css
|
|
|
|
def publish!
|
|
self.published_html = processed_html
|
|
self.published_javascript = processed_javascript
|
|
self.published_css = processed_css
|
|
self.featured = true
|
|
save
|
|
end
|
|
|
|
private
|
|
|
|
def process_html
|
|
self.processed_html = input_html
|
|
end
|
|
|
|
def process_javascript
|
|
self.processed_javascript = input_javascript
|
|
end
|
|
|
|
def process_css
|
|
scoped_scss = ".block-wrapper-#{id} { #{input_css}}"
|
|
se = Sass::Engine.new(scoped_scss, syntax: :scss)
|
|
self.processed_css = se.render
|
|
end
|
|
|
|
def permissions
|
|
return if user&.has_role?(:super_admin)
|
|
|
|
errors.add(:commentable_id, "is not valid.")
|
|
end
|
|
end
|