Permalink
Browse files

Merge pull request #1 from jordelver/master

Customisations as discussed :)
  • Loading branch information...
2 parents 08ccf9e + c57c70b commit 2653544832566a551ca70a639bfa49d26e5478c4 Steve England committed Dec 2, 2011
Showing with 231 additions and 6 deletions.
  1. +0 −3 README
  2. +29 −0 README.md
  3. +202 −3 template.rb
View
3 README
@@ -1,3 +0,0 @@
-USAGE
-
-rails plugin new noodall-thing --full -Om https://raw.github.com/stengland/noodall-plugin-template/master/template.rb
View
@@ -0,0 +1,29 @@
+Creating a New Noodall Component
+================================
+Instructions for extracting/creating a Noodall component gem
+
+Setup
+-----
+Generate a new component/plugin template
+
+ * `rails plugin new noodall-component-<name> --full -Om https://raw.github.com/stengland/noodall-plugin-template/master/template.rb`
+
+This generates a Rails Engine and applies our customisations.
+
+Process
+-------
+* Copy/create models in `app/models`
+
+* Copy/create views in `app/views/admin/components` and `app/views/components`
+
+* Setup slots for the new component under `test/dummy/config/initializers/noodall.rb`
+
+* Add new slots to `test/dummy/app/models/content_page.rb`
+
+* Add the new component slot to `test/dummy/app/views/nodes/content_page.html.erb`
+
+* Add cucumber tests and/or unit tests
+
+* Setup factories in `/factories`
+
+* Fill in the `*.gemspec` file
View
@@ -1,5 +1,9 @@
+rvmrc = "rvm 1.9.2@#{app_path} --create"
+create_file '.rvmrc', rvmrc
+
append_file 'Gemfile', do
<<-RUBY
+gem "mm-versionable", '0.2.5'
gem "noodall-ui"
gem 'bson_ext'
gem "dragonfly"
@@ -43,11 +47,11 @@ def editor?
create_file 'test/dummy/config/mongo.yml' do
<<-YAML
development:
- database: noodall-articles_development
+ database: #{app_path}_development
test:
- database: noodall-articles_test
+ database: #{app_path}_test
production:
- database: noodall-articles_production
+ database: #{app_path}_production
YAML
end
@@ -60,6 +64,31 @@ def editor?
RUBY
end
+create_file 'test/dummy/config/initializers/noodall.rb' do
+ <<-RUBY
+# Add your Noodall:Node slots here
+#
+# Noodall::Node.slot :<slot name>, <component name>
+#
+# For example:
+#
+# Noodall::Node.slot :carousel, Carousel
+ RUBY
+end
+
+create_file 'test/dummy/config/initializers/noodall_dragonfly.rb' do
+ <<-RUBY
+# Configuration for processing and encoding
+app = Dragonfly::App[:noodall_assets]
+app.configure_with(:imagemagick)
+app.configure_with(:rails)
+app.datastore = Dragonfly::DataStorage::MongoDataStore.new :db => MongoMapper.database
+
+# For more info about Dragonfly configuration please visit
+# http://markevans.github.com/dragonfly/
+ RUBY
+end
+
inject_into_class 'test/dummy/app/controllers/application_controller.rb', 'ApplicationController' do
<<-RUBY
@@current_user = User.find_or_create_by_full_name("Demo User")
@@ -88,8 +117,178 @@ def anybody_signed_in?
RUBY
end
+create_file 'test/dummy/app/models/content_page.rb' do
+ <<-RUBY
+class ContentPage < Noodall::Node
+ # Define which Node Templates can be used as children of Nodes using this template
+ sub_templates ContentPage
+
+ # Define the number of each slot type this Node Template allows. Slots are defined in 'config/initializers/noodall.rb'
+ # small_slots 4
+end
+ RUBY
+end
+
+create_file 'test/dummy/app/views/admin/nodes/_content_page.html.erb' do
+ <<-'RUBY'
+<%= render :partial => 'noodall/admin/nodes/body', :locals => { :f => f } %>
+<% content_for :component_table do %>
+<!--
+ modify this table to look like your template and link slots to correct anchors
+<table class="component-table">
+ <tr>
+ <td rowspan="2" class="content"></td>
+ <td colspan="2" rowspan="4" class="content"></td>
+ <td><a href="#small_component_form_0" class="slot_link">4</a></td>
+ </tr>
+ <tr>
+ <td><a href="#small_component_form_1" class="slot_link">5</a></td>
+ </tr>
+ <tr>
+ <td></td>
+ <td><a href="#small_component_form_2" class="slot_link">6</a></td>
+ </tr>
+ <tr>
+ <td></td>
+ <td><a href="#small_component_form_3" class="slot_link">7</a></td>
+ </tr>
+ <tr>
+ <td></td>
+ <td colspan="2"><a href="#wide_component_form_0" class="slot_link">1</a></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td></td>
+ <td colspan="2"><a href="#wide_component_form_1" class="slot_link">2</a></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td></td>
+ <td colspan="2"><a href="#wide_component_form_2" class="slot_link">3</a></td>
+ <td></td>
+ </tr>
+ <tr>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ </tr>
+</table>
+-->
+<% end -%>
+ RUBY
+end
+
+create_file 'test/dummy/app/views/nodes/content_page.html.erb' do
+ <<-RUBY
+<h1><%= @node.title %></h1>
+
+<%= @node.body.html_safe %>
+
+<!--
+Add a slot for your new component here
+<%= component @node, '<component_name>_slot_0' %>
+-->
+ RUBY
+end
+
generate 'cucumber:install'
prepend_file 'features/support/env.rb', 'ENV["RAILS_ROOT"] ||= File.expand_path(File.dirname(__FILE__) + "/../../test/dummy")'
gsub_file 'features/support/env.rb', ':transaction', ':truncation'
+
+create_file 'features/step_definitions/component_steps.rb' do
+ <<-'RUBY'
+Given /^I am editing content$/ do
+ @_content = Factory(:content_page)
+ visit noodall_admin_node_path(@_content)
+end
+
+Given /^place a "([^"]*)" component in a slot$/ do |component_name|
+ slot_name = case component_name
+ when 'Carousel'
+ 'Carousel Slot'
+ else
+ 'Large Slot'
+ end
+ within('ol#slot-list') do
+ click_link slot_name
+ end
+ within "#fancybox-content" do
+ select component_name, :from => 'Select the type of component'
+ end
+end
+
+When /^I view the content$/ do
+ # If we haven't saved the component yet do so
+ if page.find('#fancybox-content').visible?
+ within "#fancybox-content" do
+ click_button 'Save'
+ end
+ sleep 2
+ click_button 'Publish'
+ end
+ visit node_path(@_content)
+end
+ RUBY
+end
+
+create_file 'features/support/noodall.rb' do
+ <<-RUBY
+# Load Noodall specific stuff
+require 'noodall/permalinks'
+World(Noodall::Permalinks)
+ RUBY
+end
+
+create_file 'factories/asset.rb' do
+ <<-'RUBY'
+Factory.define :asset do |asset|
+ asset.tags { Faker::Lorem.words(4) }
+ asset.title { "Image asset" }
+ asset.description { "The asset description" }
+ asset.file { Fakerama::Asset::Photo.landscape }
+end
+
+Factory.define :txt_asset, :parent => :asset do |asset|
+ asset.title { "A text file asset" }
+ asset.description { "The text file asset description" }
+ asset.file { Fakerama::Asset::Document.txt }
+end
+
+Factory.define :zip_asset, :parent => :asset do |asset|
+ asset.title { "A zip file asset" }
+ asset.description { "The zip file asset description" }
+ asset.file {File.new(File.expand_path("../../files/test.zip", __FILE__))}
+end
+
+Factory.define :document_asset, :parent => :asset do |asset|
+ asset.title { "Document asset" }
+ asset.file { File.new("#{Rails.root}/spec/files/test.pdf") }
+end
+ RUBY
+end
+
+create_file 'factories/content_page.rb' do
+ <<-RUBY
+Factory.define :content_page do |content_page|
+ content_page.title { Faker::Lorem.words(3).join(' ') }
+ content_page.body { Faker::Lorem.paragraphs(6) }
+ content_page.published_at { Time.now }
+ content_page.publish true
+end
+ RUBY
+end
+
+create_file 'features/support/factory_girl.rb' do
+ <<-RUBY
+require 'factory_girl'
+require 'fakerama'
+FactoryGirl.definition_file_paths = [
+ File.expand_path(File.dirname(__FILE__) + '/../../factories')
+]
+FactoryGirl.find_definitions
+ RUBY
+end
+

0 comments on commit 2653544

Please sign in to comment.