smithycms 0.0.3 → 0.4.0

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.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +4 -1
  3. data/Rakefile +6 -12
  4. data/app/controllers/smithy/assets_controller.rb +3 -3
  5. data/app/controllers/smithy/base_controller.rb +9 -0
  6. data/app/controllers/smithy/content_blocks_controller.rb +3 -3
  7. data/app/controllers/smithy/content_pieces_controller.rb +6 -6
  8. data/app/controllers/smithy/contents_controller.rb +3 -3
  9. data/app/controllers/smithy/images_controller.rb +3 -3
  10. data/app/controllers/smithy/page_contents_controller.rb +4 -4
  11. data/app/controllers/smithy/pages_controller.rb +3 -3
  12. data/app/controllers/smithy/settings_controller.rb +3 -3
  13. data/app/controllers/smithy/templates_controller.rb +5 -5
  14. data/app/models/smithy/asset.rb +4 -5
  15. data/app/models/smithy/content.rb +0 -2
  16. data/app/models/smithy/content_block.rb +1 -3
  17. data/app/models/smithy/content_block_template.rb +1 -3
  18. data/app/models/smithy/image.rb +0 -2
  19. data/app/models/smithy/page.rb +5 -3
  20. data/app/models/smithy/page_content.rb +3 -5
  21. data/app/models/smithy/page_list.rb +0 -2
  22. data/app/models/smithy/permitted_params.rb +57 -0
  23. data/app/models/smithy/setting.rb +0 -1
  24. data/app/models/smithy/template.rb +6 -9
  25. data/app/models/smithy/template_container.rb +1 -3
  26. data/app/views/smithy/assets/edit.html.erb +1 -1
  27. data/app/views/smithy/assets/new.html.erb +4 -10
  28. data/config/initializers/dragonfly.rb +18 -38
  29. data/config/routes.rb +8 -8
  30. data/lib/smithy/content_blocks/registry.rb +1 -1
  31. data/lib/smithy/dependencies.rb +0 -1
  32. data/lib/smithy/dragonfly/asset_helper.rb +11 -11
  33. data/lib/smithy/dragonfly/remote_data_store.rb +3 -9
  34. data/lib/smithy/dragonfly.rb +1 -1
  35. data/lib/smithy/engine.rb +2 -1
  36. data/lib/smithy/formatter.rb +4 -5
  37. data/lib/smithy/version.rb +1 -1
  38. metadata +120 -220
@@ -1,48 +1,28 @@
1
- require 'uri'
2
1
  require 'dragonfly'
3
- begin
4
- require 'rack/cache'
5
- rescue LoadError => e
6
- puts "Couldn't find rack-cache - make sure you have it in your Gemfile:"
7
- puts " gem 'rack-cache', :require => 'rack/cache'"
8
- puts " or configure dragonfly manually instead of using 'dragonfly/rails/images'"
9
- raise e
10
- end
11
-
12
- ## initialize Dragonfly ##
13
- app = Dragonfly[:files]
14
- app.configure_with(:rails)
15
- app.configure_with(:imagemagick)
16
2
 
17
- # set the cache lifetime
18
- app.cache_duration = 3600*24*365*3 # 3 years in seconds
3
+ # Configure
4
+ Dragonfly.app.configure do
5
+ plugin :imagemagick
19
6
 
20
- ### Extend active record ###
21
- app.define_macro(ActiveRecord::Base, :image_accessor)
22
- app.define_macro(ActiveRecord::Base, :file_accessor)
7
+ protect_from_dos_attacks true
8
+ secret "7fb765cbc9f1d92d5d1a56a43193d34d4f9b54dced3e62cb4e42f25d2500dd0f"
23
9
 
24
- ## configure it ##
25
- Dragonfly[:files].configure do |c|
26
- # Convert absolute location needs to be specified
27
- # to avoid issues with Phusion Passenger not using $PATH
28
- c.convert_command = `which convert`.strip.presence || "/usr/local/bin/convert"
29
- c.identify_command = `which identify`.strip.presence || "/usr/local/bin/identify"
10
+ convert_command = `which convert`.strip.presence || "/usr/local/bin/convert"
11
+ identify_command = `which identify`.strip.presence || "/usr/local/bin/identify"
30
12
 
31
- c.allow_fetch_url = true
32
- c.allow_fetch_file = true
13
+ url_format '/uploads/assets/:job/:basename.:format'
33
14
 
34
- c.url_format = '/uploads/assets/:job/:basename.:format'
15
+ datastore Smithy::Asset.dragonfly_datastore
35
16
  end
36
17
 
37
- app.datastore = Smithy::Asset.dragonfly_datastore
18
+ # Logger
19
+ Dragonfly.logger = Rails.logger
38
20
 
39
- # ### Insert the middleware ###
40
- rack_cache_already_inserted = Rails.application.config.action_controller.perform_caching && Rails.application.config.action_dispatch.rack_cache
21
+ # Mount as middleware
22
+ Rails.application.middleware.use Dragonfly::Middleware
41
23
 
42
- Rails.application.middleware.insert 0, Rack::Cache, {
43
- :verbose => true,
44
- :metastore => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/meta"), # URI encoded in case of spaces
45
- :entitystore => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/body")
46
- } unless rack_cache_already_inserted
47
-
48
- Rails.application.middleware.insert_after Rack::Cache, Dragonfly::Middleware, :files
24
+ # Add model functionality
25
+ if defined?(ActiveRecord::Base)
26
+ ActiveRecord::Base.extend Dragonfly::Model
27
+ ActiveRecord::Base.extend Dragonfly::Model::Validations
28
+ end
data/config/routes.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  Smithy::Engine.routes.draw do
2
2
  root :to => 'pages#show'
3
3
  scope "/smithy" do
4
- match '/' => redirect('/smithy/pages')
5
- match '/login' => redirect('/'), :as => :login
6
- match '/logout' => redirect('/'), :as => :logout, :via => :delete
4
+ get '/' => redirect('/smithy/pages')
5
+ get '/login' => redirect('/'), :as => :login unless has_named_route?(:login)
6
+ delete '/logout' => redirect('/'), :as => :logout unless has_named_route?(:logout)
7
7
  # CMS admin
8
8
  resources :assets
9
9
  resources :content_blocks
@@ -12,7 +12,7 @@ Smithy::Engine.routes.draw do
12
12
  collection do
13
13
  get :order
14
14
  end
15
- resources :contents, :controller => "PageContents", :except => [ :index ] do
15
+ resources :contents, :controller => "page_contents", :except => [ :index ] do
16
16
  member do
17
17
  get :preview
18
18
  end
@@ -31,8 +31,8 @@ Smithy::Engine.routes.draw do
31
31
  # end
32
32
  end
33
33
  # Sitemap
34
- resource :sitemap, :controller => "Sitemap", :only => [ :show ]
35
- match '/templates/javascripts/*javascript' => 'templates#javascript', :defaults => { :format => 'js' }
36
- match '/templates/stylesheets/*stylesheet' => 'templates#stylesheet', :format => 'css'
37
- match '*path' => 'pages#show'
34
+ resource :sitemap, :controller => "sitemap", :only => [ :show ]
35
+ get '/templates/javascripts/*javascript' => 'templates#javascript', :defaults => { :format => 'js' }
36
+ get '/templates/stylesheets/*stylesheet' => 'templates#stylesheet', :format => 'css'
37
+ get '*path' => 'pages#show'
38
38
  end
@@ -20,7 +20,7 @@ module Smithy
20
20
  return unless ActiveRecord::Base.connection.table_exists?(content_block.table_name)
21
21
  content_block_name = content_block.to_s.demodulize
22
22
  @@content_blocks << content_block_name unless @@content_blocks.include?(content_block_name)
23
- cb = Smithy::ContentBlock.find_or_initialize_by_name(content_block_name)
23
+ cb = Smithy::ContentBlock.find_or_initialize_by(name: content_block_name)
24
24
  cb.save
25
25
  @@content_blocks
26
26
  end
@@ -16,4 +16,3 @@ require 'jquery/rails'
16
16
  require 'liquid'
17
17
  require 'sass-rails'
18
18
  require 'slodown'
19
-
@@ -1,3 +1,5 @@
1
+ require 'dragonfly/s3_data_store'
2
+
1
3
  module Smithy
2
4
  module Dragonfly
3
5
  module AssetHelper
@@ -21,20 +23,18 @@ module Smithy
21
23
 
22
24
  def dragonfly_datastore
23
25
  if ENV['AWS_ACCESS_KEY_ID'].present? && ENV['AWS_SECRET_ACCESS_KEY'].present? && ENV['AWS_S3_BUCKET'].present?
24
- datastore = ::Dragonfly::DataStorage::S3DataStore.new
25
- datastore.configure do |c|
26
- c.bucket_name = ENV['AWS_S3_BUCKET']
27
- c.access_key_id = ENV['AWS_ACCESS_KEY_ID']
28
- c.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
29
- # c.region = 'eu-west-1' # defaults to 'us-east-1'
30
- # c.storage_headers = {'some' => 'thing'} # defaults to {'x-amz-acl' => 'public-read'}
31
- # c.url_scheme = 'https' # defaults to 'http'
32
- # c.url_host = 'some.custom.host' # defaults to "<bucket_name>.s3.amazonaws.com"
26
+ Dragonfly.app.configure do
27
+ # Allow amazon s3 urls to work
28
+ fetch_url_whitelist [
29
+ /s3\.amazonaws\.com\/#{ENV['AWS_S3_BUCKET']}/,
30
+ /#{ENV['AWS_S3_BUCKET']}\.s3\.amazonaws\.com/
31
+ ]
33
32
  end
33
+ ::Dragonfly::S3DataStore.new(bucket_name: ENV['AWS_S3_BUCKET'], access_key_id: ENV['AWS_ACCESS_KEY_ID'], secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'])
34
34
  else
35
- datastore = ::Dragonfly::DataStorage::FileDataStore.new
35
+ Dragonfly.app.configure { fetch_url_whitelist [] }
36
+ ::Dragonfly::FileDataStore.new(root_path: Rails.root.join('public/system/dragonfly', Rails.env), server_root: Rails.root.join('public'))
36
37
  end
37
- datastore
38
38
  end
39
39
 
40
40
  def dragonfly_remote_datastore
@@ -3,19 +3,13 @@ module Smithy
3
3
  module Dragonfly
4
4
  module DataStorage
5
5
  class RemoteDataStore
6
- include ::Dragonfly::Configurable
7
-
8
- def store(temp_object, opts={})
6
+ def write(content, opts={})
9
7
  # raise "Sorry friend, this datastore is read-only."
10
8
  end
11
9
 
12
- def retrieve(uid)
10
+ def read(uid)
13
11
  response = HTTParty.get uid, :timeout => 3
14
- unless response.ok?
15
- #raise Forbidden if response.code == 403
16
- raise DataNotFound
17
- end
18
-
12
+ raise DataNotFound unless response.ok?
19
13
  content = response.body
20
14
  extra_data = {}
21
15
  [
@@ -23,7 +23,7 @@ module Smithy
23
23
  end
24
24
 
25
25
  def self.app
26
- ::Dragonfly[:files]
26
+ ::Dragonfly.app
27
27
  end
28
28
 
29
29
  end
data/lib/smithy/engine.rb CHANGED
@@ -35,7 +35,8 @@ module Smithy
35
35
  # we need to require all our model files so that ContentBlocks
36
36
  # are registered with the engine
37
37
  Dir[Smithy::Engine.root.join('app', 'models', 'smithy', '*.rb')].each do |file|
38
- require_dependency file if ActiveRecord::Base.connection.table_exists?(file.pluralize)
38
+ table_name = File.basename(file, '.rb').pluralize
39
+ require_dependency file if ActiveRecord::Base.connection.table_exists?(table_name)
39
40
  end
40
41
  end
41
42
 
@@ -13,11 +13,10 @@ module Smithy
13
13
  def sanitize_config
14
14
  {
15
15
  elements: %w(
16
- p br a span sub sup strong em div hr abbr
17
- ul ol li
18
- blockquote pre code
19
- h1 h2 h3 h4 h5 h6
20
- img object param del
16
+ p div ul ol li blockquote pre h1 h2 h3 h4 h5 h6 object
17
+ hr param
18
+ a span sub sup strong em abbr code del small big
19
+ br img
21
20
  ),
22
21
  attributes: {
23
22
  :all => ['class', 'style', 'title', 'id'],
@@ -1,3 +1,3 @@
1
1
  module Smithy
2
- VERSION = "0.0.3"
2
+ VERSION = "0.4.0"
3
3
  end