Permalink
Browse files

Add forem:views generator, which copies over the forem views into you…

…r application
  • Loading branch information...
radar committed Sep 15, 2011
1 parent b11f562 commit 1b3b89a9b3adc5054e6ca7389e48aa5b0ed1fce5
Showing with 43 additions and 0 deletions.
  1. +24 −0 lib/generators/forem/views_generator.rb
  2. +19 −0 spec/generators/views_generator.rb
@@ -0,0 +1,24 @@
+# Thanks to plataformatec/devise
+# The code used to inspire this generator!
+require 'rails/generators'
+module Forem
+ module Generators
+ class ViewsGenerator < Rails::Generators::Base #:nodoc:
+ source_root File.expand_path("../../../../app/views/forem", __FILE__)
+ desc "Used to copy forem's views to your application's views."
+
+ def copy_views
+ view_directory :admin
+ view_directory :forums
+ view_directory :posts
+ view_directory :topics
+ end
+
+ protected
+
+ def view_directory(name)
+ directory name.to_s, "app/views/forem/#{name}"
+ end
+ end
+ end
+end
@@ -0,0 +1,19 @@
+require 'spec_helper'
+require 'generators/forem/views_generator'
+
+describe Forem::Generators::ViewsGenerator do
+ let(:views) { Rails.root + "app/views" }
+
+ # Ensure directory is missing before generator is running
+ before { FileUtils.rm_r(views + "forem") }
+ # And clean up once we are done
+ after { FileUtils.rm_r(views + "forem") }
+
+ it "copies over files" do
+ capture(:stdout) { described_class.start([], :destination_root => Rails.root) }
+ dirs = ["forem", "forem/admin", "forem/forums", "forem/posts", "forem/topics"]
+ dirs.each do |dir|
+ assert File.directory?(views + dir), "did not generate #{dir}"
+ end
+ end
+end

0 comments on commit 1b3b89a

Please sign in to comment.