WaYdotNET - No public Twitter messages.
formats

Use Padrino and sprockets with sprockets-helpers

Published on March 30, 2013 by WaYdotNET in ruby

Thanks to @arthur_chiu and his post on how to integrate sprockets in Padrino with sprockets-helpers, i’ve create my version :D :D:D:D

1) Create padrino-sprockets in config/sprockets.rb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module Padrino::Sprockets
  def self.registered(base)
    base.set :sprockets, ::Sprockets::Environment.new(Padrino.root)
 
    # Add folder
    base.sprockets.append_path 'assets/javascripts'
    base.sprockets.append_path 'assets/stylesheets'
    base.sprockets.append_path 'assets/images'
    base.set :digest_assets, true
 
    # compress file
    if PADRINO_ENV == 'development'
      base.sprockets.js_compressor = Uglifier.new(mangle: true)
      base.sprockets.css_compressor = YUI::CssCompressor.new
    end
 
    # sprockets-helpers
    base.helpers Sprockets::Helpers
    # We can configure `sprockets-helpers` to find the correct assets for us.
    Sprockets::Helpers.configure do |config|
      manifest_path      = File.join(Padrino.root,'public','assets','manifest.json')
      config.environment = base.sprockets
      config.prefix      = '/assets'
      config.manifest    = Sprockets::Manifest.new(base.sprockets, manifest_path)
      config.digest      = true
      config.public_path = base.public_folder
    end
 
    # call sprockets :D
    if PADRINO_ENV == 'development'
      base.get '/assets/*splat' do
        env['PATH_INFO'].gsub!(%r{\A/?assets}, '')
        settings.sprockets.call(env)
      end
    end
  end
end

In this file you need add all your asset’s folder..

2) Load this file at startup application:
config/boot.rb

1
2
3
4
5
# after this line
Bundler.require(:default, PADRINO_ENV)
 
# add this
require Padrino.root('config/sprockets')

3) register Padrino::Sprockets in your application

1
2
3
4
5
6
Module Foo
  class App < Padrino::Application
   register Padrino::Sprockets
 
  end
end

4) Use js,css sprockets version in you layout, es:

layout.slim

1
link href= stylesheet_path('app') media="screen" type="text/css" rel="stylesheet"

instead

1
= stylesheet_link_tag :app

5) Use Rakefile to create asstes to pre-compilation :D :D

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
PADRINO_ENV  = ENV['PADRINO_ENV'] ||= ENV['RACK_ENV'] ||= 'development'  unless defined?(PADRINO_ENV)
 
require 'bundler/setup'
require 'padrino-core/cli/rake'
 
 
require 'sprockets/../rake/sprocketstask'
 
 Bundler.require(PADRINO_ENV)
require File.expand_path("../config/boot.rb", __FILE__)
 
PadrinoTasks.use(:database)
PadrinoTasks.use(:minirecord)
PadrinoTasks.init
 
# Use fake application 
module FakeSprock
  class App < Padrino::Application
    register Padrino::Sprockets
  end
end
 
SPROCKETS = FakeSprock::App.sprockets
 
# or your real app name
# SPROCKETS = RealAppName::App.sprockets
 
Rake::SprocketsTask.new do |t|
  manifest_path = File.join(Padrino.root,'public','assets')
  t.environment = SPROCKETS
  t.output      = File.join(Padrino.root,'public','assets')
  t.manifest    = Sprockets::Manifest.new(SPROCKETS, manifest_path)
  t.assets      = %w[app.js app.css *.png *.gif *.jpg]
end

and call it with

1
rake assets

To conitnue use stylesheet_link_tag and javascript_include_tag, need to close this issue

Thanks again at @padrino-core.
Special tanks:
DAddYE
@arthur_chiu

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
formats

Padrino 0.11.0 Released – Padrino Lives!

Published on March 23, 2013 by WaYdotNET in ruby

The Padrino team is very pleased to finally be able to announce the 0.11.0 release of the Padrino Framework! We have been working on this release for almost a year now and we have had dozens of contributors helping us stabilize Padrino. We know our release cycle got out whack and this version took too long to release. We all take accountability for that and will work to pick up release momentum and release patch and minor versions more often.

Since our 0.10.7 release, development on Padrino has been moving forward very actively and as such this is probably our biggest release in terms of code modified and issues resolved that we have had in years. We are very proud of this release which includes several major improvements:

1) Totally Redesigned Admin
2) New brand identity on the way
3) Upgraded Sinatra and http_router
4) CSRF Form Protection
5) ActiveSupport::SafeBuffer
6) New Rakefile format
7) Gemified Apps
8) Performance Tools
9) App Namespacing
10) Project Modules
11) Optimized Reloader

http://www.padrinorb.com/blog/padrino-0-11-0-released-padrino-lives

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
formats

Usage ImageSorcery with CarrierWave by gem

Published on August 22, 2012 by WaYdotNET in AiS, ruby

CarrierWave::ImageSorcery

https://github.com/WaYdotNET/carrierwave-imagesorcery

Additional processing to use ImageSorcery into CarrierWave.

Installation

Add this line to your application’s Gemfile:

1
gem 'carrierwave-imagesorcery'

And then execute:

1
$ bundle

Or install it yourself as:

1
$ gem install carrierwave-imagesorcery

Usage

To use those, you should include specified module (ImageSorcery) into your uploader and use processors:

1
2
3
4
5
class AvatarUploader < CarrierWave::Uploader::Base
  include CarrierWave::ImageSorcery
  .....
 
end

Method implemented

1
2
3
4
5
6
convert
dimensions
resize_to_limit
resize_to_fit
resize_to_fill
resize_and_pad

Example

1
2
3
4
5
6
7
8
9
class Uploader < CarrierWave::Uploader::Base
##
# Image manipulator library:
include CarrierWave::ImageSorcery
 
process :resize_and_pad => [900,300,"#ffeecc", 'South']
process :resize_to_fit => [1024, 768]
 
end

Example custom method

An example to implement custom method

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Uploader < CarrierWave::Uploader::Base
include CarrierWave::ImageSorcery
process :watermark_text
 
def watermark_text(text = "© #{Time.now.year} - Carlo Bertini [WaYdotNET]")
  manipulate! do |img|
    args  = {
      font: 'Helvetica', fill: 'white', stroke: '#00770080',
      gravity: 'South', pointsize: 20, draw: " text 0,0 \"#{text}\" "
    }
    img.manipulate! args
    img
  end
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am ‘Added some feature’)
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Author

endorse

WaYdotNET, you can follow me on twitter @WaYdotNET or take a look at my site waydotnet.com

Copyright

Copyright (C) 2012 Carlo Bertini – @WaYdotNET

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
formats

The library is a simple API in Ruby for Microsoft Translator V2

MsTranslate

The library is a simple API in Ruby for Microsoft Translator V2

The Microsoft Translator services can be used in web or client applications to perform language translation operations. The services support users who are not familiar with the default language of a page or application, or those desiring to communicate with people of a different language group.

Installation

Add this line to your application’s Gemfile:

1
gem 'ms_translate'

And then execute:

1
$ bundle

Or install it yourself as:

1
$ gem install ms_translate

Usage

first step set your appId

1
$ MsTranslate::Api.appId = 'MyRealAppId'

traNslate method:

1
2
$ MsTranslate::Api.translate('Hello World!)
$ => Ciao, Mondo!

Method not implemented

  1. Microsoft.Translator.AddTranslation Method
  2. Microsoft.Translator.AddTranslationArray Method

Test

You need to insert your appId into

1
2
# File 'spec/lib/ms_translate/api_spec.rb'
@api_real =  'INSERT_YOUR_APPID'

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Author

endorse

WaYdotNET, you can follow me on twitter @WaYdotNET or take a look at my site waydotnet.com

Copyright

Copyright (C) 2012 Carlo Bertini – @WaYdotNET

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
formats

Padrino-admin Twitter Bootstrap v2.0 is ready

(Padrino Admin TwitterBootstrap 2.0)

  • Padrino-Modal: rack-flash and delete function into modal :D
  • highlights error field
  • tof helper: Automatic replace true or false with relative image (list.slim and list.haml)
  • Breadcrumbs
  • Automatic time_ago_in_words when column model is created_at or updated_at
  • Migrate function for MiniRecord

Padrino-Modal

All result from rack-flash and delete request, now is automatic insert into modal javascript plugin

highlights error field

tof_helper

Automatic replace true or false with relative image (list.slim and list.haml)

Breadcrumbs

Automatic Breadcrumbs system:

time_ago_in_words

Automatic time_ago_in_words when column model is created_at or updated_at

MiniRecord migrate

Migrate function for MiniRecord

Demo:

http://padrino.waydotnet.com/admin
user: [email protected]
password: test

By WaYdotNET

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn