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

Content blocks should be editable in settings UI #82

Merged
merged 1 commit into from
Apr 26, 2016

Conversation

mjgiarlo
Copy link
Member

@mjgiarlo mjgiarlo commented Apr 15, 2016

Fixes #74


def displayable_content_block(content_block, class_string = '', id_string = '')
return if content_block.value.blank?
raw("<div id='#{id_string}' class='#{class_string}'>#{content_block.value}</div>")
Copy link
Member

Choose a reason for hiding this comment

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

Maybe:

content_tag :div, content_block.value,  id: id_string, class: class_string

Copy link
Member

Choose a reason for hiding this comment

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

Instead of passing the class and id, how about we pass options: {} and pass it through to the content_tag?

@mjgiarlo mjgiarlo changed the title [WIP] Shameless green version of content blocks editable in settings UI. Content blocks should be editable in settings UI Apr 21, 2016
@mjgiarlo mjgiarlo force-pushed the add_content_blocks_to_settings branch 3 times, most recently from 828c031 to 5195eaa Compare April 22, 2016 02:23
@@ -0,0 +1 @@
@import 'batch_edit/batch_edit';

Choose a reason for hiding this comment

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

Prefer double-quoted strings

@mjgiarlo mjgiarlo force-pushed the add_content_blocks_to_settings branch from 5195eaa to 8196b60 Compare April 22, 2016 02:31
@mjgiarlo mjgiarlo changed the title Content blocks should be editable in settings UI [WIP] Content blocks should be editable in settings UI Apr 22, 2016
@@ -24,6 +24,9 @@ Metrics/LineLength:
Exclude:
- 'app/controllers/catalog_controller.rb'

Metrics/AbcSize:
Exclude:
- 'app/helpers/content_block_helper.rb'
Copy link
Member

Choose a reason for hiding this comment

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

Instead of excluding this, maybe we can figure out how to simplify those methods?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's the editable_content_block method in particular, which has a score of 16 (the threshold is 15). Extracting form_for into its own method, like you suggested, may do the trick. I'll have a go at this later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Killed this method.

@cbeer cbeer force-pushed the add_content_blocks_to_settings branch from 8196b60 to 6866e25 Compare April 22, 2016 15:44
@mjgiarlo mjgiarlo force-pushed the add_content_blocks_to_settings branch from 6866e25 to d0f27f0 Compare April 25, 2016 23:21
@@ -4,6 +4,15 @@
let!(:site) do
assign(:site, Site.create!(application_name: "MyString", institution_name: "My Inst Name"))
end
let(:announcement_text) { ContentBlock.find_or_create_by(name: ContentBlock::ANNOUNCEMENT)}
let(:marketing_text) { ContentBlock.find_or_create_by(name: ContentBlock::MARKETING)}
let(:featured_researcher) { ContentBlock.find_or_create_by(name: ContentBlock::RESEARCHER)}

Choose a reason for hiding this comment

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

Style/SpaceInsideBlockBraces: Space missing inside }.

@mjgiarlo mjgiarlo force-pushed the add_content_blocks_to_settings branch 4 times, most recently from c419570 to 0015b01 Compare April 26, 2016 00:33
@mjgiarlo mjgiarlo changed the title [WIP] Content blocks should be editable in settings UI Content blocks should be editable in settings UI Apr 26, 2016

def instance
first || create
end
end

def announcement_text
Copy link
Member

Choose a reason for hiding this comment

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

IMHO these methods do not belong on the site model. You should extract this stuff into a Form object which is responsible for saving the site and any content blocks.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd like to defer creating a new form object, if at all possible.

Copy link
Member

Choose a reason for hiding this comment

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

We're getting ContentBlock from sufia, I imagine? Instead of adding our own accessors here, would it make sense to set up the expected AR associations to that model?

Copy link
Member Author

@mjgiarlo mjgiarlo Apr 26, 2016

Choose a reason for hiding this comment

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

@cbeer Correct, that model is provided by Sufia. Do you have something like the following in mind?

class Site < ActiveRecord::Base
  # ...
  has_many :content_blocks
  # ...
  class << self
    delegate :account, ..., :content_blocks, to: :instance
    delegate :announcement_text, :marketing_text, :featured_researcher, to: :content_blocks
    # ...
  end
end

If so, I'll need to create some convenience methods in Sufia (#announcement_text, #marketing_text, #featured_researcher) first.

@mjgiarlo mjgiarlo force-pushed the add_content_blocks_to_settings branch from 21c2df1 to d38bc66 Compare April 26, 2016 22:22
@atz atz merged commit 9ff1100 into master Apr 26, 2016
@atz atz deleted the add_content_blocks_to_settings branch April 26, 2016 23:44
@atz atz removed the in progress label Apr 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants