Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update guides/source/plugins.md [ci skip] #30261

Merged
merged 1 commit into from
Aug 15, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 24 additions & 33 deletions guides/source/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ In this example you will add a method to String named `to_squawk`. To begin, cre
```ruby
# yaffle/test/core_ext_test.rb

require 'test_helper'
require "test_helper"

class CoreExtTest < ActiveSupport::TestCase
def test_to_squawk_prepends_the_word_squawk
Expand Down Expand Up @@ -104,14 +104,16 @@ Finished in 0.003358s, 595.6483 runs/s, 297.8242 assertions/s.

Great - now you are ready to start development.

In `lib/yaffle.rb`, add `require 'yaffle/core_ext'`:
In `lib/yaffle.rb`, add `require "yaffle/core_ext"`:

```ruby
# yaffle/lib/yaffle.rb

require 'yaffle/core_ext'
require "yaffle/railtie"
require "yaffle/core_ext"

module Yaffle
# Your code goes here...
end
```

Expand All @@ -120,7 +122,7 @@ Finally, create the `core_ext.rb` file and add the `to_squawk` method:
```ruby
# yaffle/lib/yaffle/core_ext.rb

String.class_eval do
class String
def to_squawk
"squawk! #{self}".strip
end
Expand Down Expand Up @@ -152,7 +154,7 @@ To begin, set up your files so that you have:
```ruby
# yaffle/test/acts_as_yaffle_test.rb

require 'test_helper'
require "test_helper"

class ActsAsYaffleTest < ActiveSupport::TestCase
end
Expand All @@ -161,10 +163,12 @@ end
```ruby
# yaffle/lib/yaffle.rb

require 'yaffle/core_ext'
require 'yaffle/acts_as_yaffle'
require "yaffle/railtie"
require "yaffle/core_ext"
require "yaffle/acts_as_yaffle"

module Yaffle
# Your code goes here...
end
```

Expand All @@ -173,7 +177,6 @@ end

module Yaffle
module ActsAsYaffle
# your code will go here
end
end
```
Expand All @@ -189,7 +192,7 @@ To start out, write a failing test that shows the behavior you'd like:
```ruby
# yaffle/test/acts_as_yaffle_test.rb

require 'test_helper'
require "test_helper"

class ActsAsYaffleTest < ActiveSupport::TestCase
def test_a_hickwalls_yaffle_text_field_should_be_last_squawk
Expand Down Expand Up @@ -276,12 +279,8 @@ module Yaffle
module ActsAsYaffle
extend ActiveSupport::Concern

included do
end

module ClassMethods
class_methods do
def acts_as_yaffle(options = {})
# your code will go here
end
end
end
Expand Down Expand Up @@ -335,10 +334,7 @@ module Yaffle
module ActsAsYaffle
extend ActiveSupport::Concern

included do
end

module ClassMethods
class_methods do
def acts_as_yaffle(options = {})
cattr_accessor :yaffle_text_field, default: (options[:yaffle_text_field] || :last_squawk).to_s
end
Expand Down Expand Up @@ -370,7 +366,7 @@ To start out, write a failing test that shows the behavior you'd like:

```ruby
# yaffle/test/acts_as_yaffle_test.rb
require 'test_helper'
require "test_helper"

class ActsAsYaffleTest < ActiveSupport::TestCase
def test_a_hickwalls_yaffle_text_field_should_be_last_squawk
Expand Down Expand Up @@ -406,19 +402,14 @@ module Yaffle
extend ActiveSupport::Concern

included do
def squawk(string)
write_attribute(self.class.yaffle_text_field, string.to_squawk)
end
end

module ClassMethods
class_methods do
def acts_as_yaffle(options = {})
cattr_accessor :yaffle_text_field, default: (options[:yaffle_text_field] || :last_squawk).to_s

include Yaffle::ActsAsYaffle::LocalInstanceMethods
end
end

module LocalInstanceMethods
def squawk(string)
write_attribute(self.class.yaffle_text_field, string.to_squawk)
end
end
end
Expand Down Expand Up @@ -449,7 +440,7 @@ Generators
----------

Generators can be included in your gem simply by creating them in a lib/generators directory of your plugin. More information about
the creation of generators can be found in the [Generators Guide](generators.html)
the creation of generators can be found in the [Generators Guide](generators.html).

Publishing Your Gem
-------------------
Expand All @@ -458,13 +449,13 @@ Gem plugins currently in development can easily be shared from any Git repositor
commit the code to a Git repository (like GitHub) and add a line to the Gemfile of the application in question:

```ruby
gem 'yaffle', git: 'git://github.com/yaffle_watcher/yaffle.git'
gem "yaffle", git: "https://github.com/rails/yaffle.git"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we keep the link outside the rails org?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed it guided by that one day there might be a user by https://github.com/yaffle_watcher

```

After running `bundle install`, your gem functionality will be available to the application.

When the gem is ready to be shared as a formal release, it can be published to [RubyGems](http://www.rubygems.org).
For more information about publishing gems to RubyGems, see: [Creating and Publishing Your First Ruby Gem](http://blog.thepete.net/2010/11/creating-and-publishing-your-first-ruby.html).
When the gem is ready to be shared as a formal release, it can be published to [RubyGems](https://rubygems.org).
For more information about publishing gems to RubyGems, see: [Publishing your gem](http://guides.rubygems.org/publishing).

RDoc Documentation
------------------
Expand All @@ -478,7 +469,7 @@ The first step is to update the README file with detailed information about how
* How to add the functionality to the app (several examples of common use cases)
* Warnings, gotchas or tips that might help users and save them time

Once your README is solid, go through and add rdoc comments to all of the methods that developers will use. It's also customary to add '#:nodoc:' comments to those parts of the code that are not included in the public API.
Once your README is solid, go through and add rdoc comments to all of the methods that developers will use. It's also customary to add `#:nodoc:` comments to those parts of the code that are not included in the public API.

Once your comments are good to go, navigate to your plugin directory and run:

Expand Down