Commits

Joris van Rooij committed 78c1c49

Gemified the project.
Still needs to be tested, though.

Comments (0)

Files changed (11)

 Debian is the preferred platform of choice. If you encounter problems
 caused by Debian-specific hacks, please let me know. The interpreter
 string has been set to `ruby1.9.1`, but you can easily change that in
-`sinatra-mvc.rb` if you wish. Don't worry, that's the only place the 
+the `bin` directory  if you wish. Don't worry, that's the only place the 
 "weird" interpreter string is used.
 
 Throughout the documentation Debian-specific help will be provided. Other
 administrator to install the packages for you):
 
     # apt-get install ruby1.9.1-full libmysqlclient-dev libpq-dev libsqlite3-dev
-    # gem1.9.1 install bundler
 
 You'll have to make sure the Ruby gem path is in your terminal's `$PATH`.
 For Debian, adding the following line to your `~/.bashrc` will do just
 
 First, you'll need to download the source tree. Since this is a
 development project, you'll have to use the latest and greatest release
-(e.g. the Mercurial tip) for the time being.
+(e.g. the Mercurial tip) for the time being. For Debian, use `gem1.9.1`
+instead of `gem`.
 
-    $ hg clone ssh://gescheurd.wasda.nl/~jorrizza/src/sinatra-mvc my_project
+    $ cd $HOME/src
+    $ hg clone ssh://gescheurd.wasda.nl/~jorrizza/src/sinatra-mvc
+    $ cd sinatra-mvc
+    $ gem build sinatra-mvc.gemspec
+    # gem install sinatra-mvc-0.1.gem
+
+Now we've got sinatra-mvc installed, let's start our own project.
+
+    $ cd $HOME/src
+    $ sinatra-mvc-project my_project
     $ cd my_project
 
+Yay! A project!
+
 Using bundler, we can install all of our gems without getting in the way
 of your host Ruby installation. The following command will install the
 gems in the `vendor/` directory and add the gem's applications in `bin/`.
 
     $ bundle install --path vendor --binstubs
 
-To test your local bunch of gems, let's generate an HTML file out of this
-documentation.
-
-    $ bin/maruku README.md
-
-This'll generate a nice HTML file for you.
-
 Updating gems is pretty easily done. Now you've got your bundle complete,
 you'll just have to run:
 
 Joris will update Sinatra MVC every once in a while. To get the latest
 updates from his repository, just pull (and merge if needed).
 
+    $ cd $HOME/src/sinatra-mvc
     $ hg pull
-    $ hg merge
+    $ hg update
+    $ gem build sinatra-mvc.gemspec
+    # gem install sinatra-mvc-0.1.gem
 
 Configuration
 -------------
 will serve all the static files and handle the application calls at the
 same time. Just simply run:
 
-    $ ./sinatra-mvc.rb
+    $ cd my_project
+    $ sinatra-mvc
 
 This will run your application in development mode, allowing you to see
 the access log in the terminal and tracebacks when you've made an _oops_.
 defined in your `models` directory. If you just want to migrate your models
 (e.g. update the database to reflect your models), just run:
 
-    $ ./sinatra-mvc.rb upgradedb
+    $ cd my_project
+    $ sinatra-mvc upgradedb
 
 This will only update the tables in such a way it can't modify any of the
 data already present. To do that, you'll have to write migrations. This
 
 To run a script, simply call:
 
-    $ ./sinatra-mvc.rb <scriptname without .rb>
+    $ cd my_project
+    $ sinatra-mvc <scriptname without .rb>
 
 Single Character Reserved Variables
 -----------------------------------
 #!/usr/bin/env ruby1.9.1
 
-require 'sinatra-mvc'
+# Determine the location of our project
+PROJECT = ENV['PROJECT'] ? ENV['PROJECT'] : '.'
+
+require 'sinatra-mvc'

bin/sinatra-mvc-project

+#!/usr/bin/env ruby1.9.1
+# Creates a new project.
+
+require 'fileutils'
+require 'rubygems'
+
+unless ARGV[0]
+  $stderr.puts 'Please supply the name of the new project'
+  exit 1
+end
+
+skel = File.join File.dirname(Gem.bin_path('sinatra-mvc')), '..', 'skel'
+
+begin
+  FileUtils.cp_r skel, ARGV[0], :verbose => true
+rescue
+  $stderr.puts $!
+  exit 1
+end
+
+puts "Finished. Finalize the project by running the following command in %s:" % ARGV[0]
+puts "bundle install --path vendor --binstubs"

lib/sinatra-mvc.rb

 # 
 # Joris van Rooij <jorrizza@jrrzz.net>
 # http://www.jrrzz.net/
-#
 
+# Check if we've got a PROJECT defined.
+raise RuntimeError, 'PROJECT is not defined!' unless PROJECT
+
+# A hack for now, but at least it's better than nothing.
 Encoding.default_external = 'UTF-8'
 
 # Project include path.
-$:.push File.dirname(__FILE__)
+$:.push PROJECT
 
 # We use Bundler to manage deps.
 require 'bundler/setup'
 require 'sinatra-mvc/load_utils'
 require 'sinatra-mvc/conditional_form_field'
 require 'sinatra-mvc/escaping'
+
+# Start the classic mode.
+set :run, true

lib/sinatra-mvc/load_app.rb

 # the controllers (app components if you will).
 
 def load_app(dir)
-  Dir.glob(File.join dir, '**', '*.rb').each do |file|
+  Dir.glob(File.join PROJECT, dir, '**', '*.rb').each do |file|
     load file
   end
 end

lib/sinatra-mvc/load_utils.rb

 # when that utility is called as a command line option.
 
 if ARGV[0]
-  if File.exists? "utils/#{ARGV[0]}.rb"
+  util = File.join(PROJECT, 'utils', "#{ARGV[0]}.rb")
+  if File.exists? util
     printf "Running util %s.\n", ARGV[0]
-    require "utils/#{ARGV[0]}"
+    require util
     exit
   else
     printf ">> Util %s does not exist. Continue as normal.\n", ARGV[0]

lib/sinatra-mvc/settings.rb

   end
 end
 
-Settings.load File.join(File.dirname(__FILE__), '..', 'conf', 'settings.yml')
+Settings.load File.join(PROJECT, 'conf', 'settings.yml')
 
 # Now we have to feed the Sinatra settings
 Settings.settings.each_pair do |setting, value|
   case setting
   when 'views_root', 'translations'
-    set setting.to_sym, File.join(File.dirname(__FILE__), '..', value)
+    set setting.to_sym, File.join(PROJECT, value)
   else
     set setting.to_sym, value
   end

sinatra-mvc.gemspec

   s.author = 'Joris van Rooij'
   s.email = 'jorrizza@jrrzz.net'
   s.bindir = 'bin'
-  s.executables = ['sinatra-mvc']
+  s.executables = %w[sinatra-mvc sinatra-mvc-project]
   s.default_executable = 'sinatra-mvc'
   s.add_dependency('bundler',  '~> 1.0')
+
+  s.files = %w[
+  bin
+  bin/sinatra-mvc
+  lib
+  lib/sinatra-mvc
+  lib/sinatra-mvc/escaping.rb
+  lib/sinatra-mvc/load_utils.rb
+  lib/sinatra-mvc/render_params.rb
+  lib/sinatra-mvc/database_connection.rb
+  lib/sinatra-mvc/load_app.rb
+  lib/sinatra-mvc/post_handler.rb
+  lib/sinatra-mvc/flash_messages.rb
+  lib/sinatra-mvc/session_store.rb
+  lib/sinatra-mvc/view_prefix.rb
+  lib/sinatra-mvc/settings.rb
+  lib/sinatra-mvc/conditional_form_field.rb
+  lib/sinatra-mvc.rb
+  skel
+  skel/app
+  skel/app/not_found.rb
+  skel/app/index.rb
+  skel/i18n
+  skel/i18n/en.yml
+  skel/conf
+  skel/conf/settings.yml
+  skel/views
+  skel/views/docs.md
+  skel/views/layout.erubis
+  skel/views/index.erubis
+  skel/views/not_found.erubis
+  skel/views/flash_message.erubis
+  skel/utils
+  skel/utils/upgradedb.rb
+  skel/utils/initdb.rb
+  skel/config.ru
+  skel/models
+  skel/public
+  skel/Gemfile
+  LICENSE
+  README.md
+  ]
 end

skel/Gemfile.lock

-GEM
-  remote: http://rubygems.org/
-  specs:
-    RedCloth (4.2.3)
-    abstract (1.0.0)
-    addressable (2.2.2)
-    daemons (1.1.0)
-    data_mapper (1.0.2)
-      dm-aggregates (= 1.0.2)
-      dm-constraints (= 1.0.2)
-      dm-core (= 1.0.2)
-      dm-migrations (= 1.0.2)
-      dm-serializer (= 1.0.2)
-      dm-timestamps (= 1.0.2)
-      dm-transactions (= 1.0.2)
-      dm-types (= 1.0.2)
-      dm-validations (= 1.0.2)
-    data_objects (0.10.2)
-      addressable (~> 2.1)
-    dm-adjust (1.0.2)
-      dm-core (~> 1.0.2)
-    dm-aggregates (1.0.2)
-      dm-core (~> 1.0.2)
-    dm-constraints (1.0.2)
-      dm-core (~> 1.0.2)
-      dm-migrations (~> 1.0.2)
-    dm-core (1.0.2)
-      addressable (~> 2.2)
-      extlib (~> 0.9.15)
-    dm-do-adapter (1.0.2)
-      data_objects (~> 0.10.2)
-      dm-core (~> 1.0.2)
-    dm-is-list (1.0.2)
-      dm-adjust (~> 1.0.2)
-      dm-core (~> 1.0.2)
-    dm-is-tree (1.0.2)
-      dm-core (~> 1.0.2)
-    dm-migrations (1.0.2)
-      dm-core (~> 1.0.2)
-    dm-mysql-adapter (1.0.2)
-      dm-do-adapter (~> 1.0.2)
-      do_mysql (~> 0.10.2)
-    dm-postgres-adapter (1.0.2)
-      dm-do-adapter (~> 1.0.2)
-      do_postgres (~> 0.10.2)
-    dm-serializer (1.0.2)
-      dm-core (~> 1.0.2)
-      fastercsv (~> 1.5.3)
-      json_pure (~> 1.4)
-    dm-sqlite-adapter (1.0.2)
-      dm-do-adapter (~> 1.0.2)
-      do_sqlite3 (~> 0.10.2)
-    dm-tags (1.0.2)
-      dm-core (~> 1.0.2)
-    dm-timestamps (1.0.2)
-      dm-core (~> 1.0.2)
-    dm-transactions (1.0.2)
-      dm-core (~> 1.0.2)
-    dm-types (1.0.2)
-      dm-core (~> 1.0.2)
-      fastercsv (~> 1.5.3)
-      json_pure (~> 1.4)
-      stringex (~> 1.1.0)
-      uuidtools (~> 2.1.1)
-    dm-validations (1.0.2)
-      dm-core (~> 1.0.2)
-    do_mysql (0.10.2)
-      data_objects (= 0.10.2)
-    do_postgres (0.10.2)
-      data_objects (= 0.10.2)
-    do_sqlite3 (0.10.2)
-      data_objects (= 0.10.2)
-    erubis (2.6.6)
-      abstract (>= 1.0.0)
-    eventmachine (0.12.10)
-    extlib (0.9.15)
-    fastercsv (1.5.3)
-    json_pure (1.4.6)
-    less (1.2.21)
-      mutter (>= 0.4.2)
-      treetop (>= 1.4.2)
-    liquid (2.2.2)
-    maruku (0.6.0)
-      syntax (>= 1.0.0)
-    memcache-client (1.8.5)
-    mutter (0.5.3)
-    polyglot (0.3.1)
-    r18n-core (0.4.8)
-    rack (1.2.1)
-    rack-flash (0.1.1)
-      rack
-    rdiscount (1.6.5)
-    sinatra (1.1.0)
-      rack (~> 1.1)
-      tilt (~> 1.1)
-    sinatra-r18n (0.4.8)
-      r18n-core (= 0.4.8)
-    sinatra-redirect-with-flash (0.1.2)
-      rack-flash (>= 0.1.1)
-      sinatra (>= 0.9.1)
-    stringex (1.1.0)
-    syntax (1.0.0)
-    thin (1.2.7)
-      daemons (>= 1.0.9)
-      eventmachine (>= 0.12.6)
-      rack (>= 1.0.0)
-    tilt (1.1)
-    treetop (1.4.9)
-      polyglot (>= 0.3.1)
-    uuidtools (2.1.1)
-
-PLATFORMS
-  ruby
-
-DEPENDENCIES
-  RedCloth
-  data_mapper
-  dm-is-list
-  dm-is-tree
-  dm-mysql-adapter
-  dm-postgres-adapter
-  dm-sqlite-adapter
-  dm-tags
-  dm-timestamps
-  erubis
-  less
-  liquid
-  maruku
-  memcache-client
-  rack-flash
-  rdiscount
-  sinatra (>= 1.1)
-  sinatra-r18n
-  sinatra-redirect-with-flash
-  thin
-  tilt
 # Rackup file for Sinatra-MVC
 
-$: << File.dirname(__FILE__)
+PROJECT = File.dirname(__FILE__)
 require 'sinatra-mvc'
 run Sinatra::Application

skel/views/docs.md

-../README.md
+../../README.md