Barry Goldwater vs. Nelson Rockefeller. Ronald Reagan vs. Gerald Ford. Ted Kennedy vs. Jimmy Carter. The two parties’ presidential nomination fights have often pitted ideologues against pragmatists, and this year’s Republican primary is yet another example.

One contender after another — Rick Perry, Michele Bachmann, Newt Gingrich, Herman Cain and now Rick Santorum — has claimed to be the “true” conservative alternative to Mitt Romney, the purported Massachusetts moderate.

Each has argued that staying true to party doctrine on taxes, government spending and abortion is not only morally right but also politically expedient. The only way to beat President Obama in November, they argue, is to present the voters with a clear ideological alternative. “You win by giving people a choice,” Santorum said during a recent visit to Texas.

These Republicans need to read “Flagrant Conduct,” a superb new book by University of Minnesota law professor Dale Carpenter. It tells the story of the dramatic 2003 victory for gay rights at the Supreme Court, in which the justices struck down a Texas ban on homosexual ­sodomy.

Justice Anthony M. Kennedy’s opinion for the majority in that case, Lawrence v. Texas, relied on — and expanded — doctrine that the court had previously invoked to guarantee constitutional rights to contraception and abortion, much to conservatives’ consternation.

And while Lawrence had no direct bearing on the question of gay marriage, the reasoning and the rhetoric of Kennedy’s opinion encouraged subsequent lawsuits seeking a constitutional right to same-sex nuptials.

In short, Lawrence was a huge setback for social-issues conservatives. But, as Carpenter shows, it was a defeat for which the ultra-right had only itself to blame.

Enacted in 1973 as part of a backlash against the fledgling gay rights movement, the Homosexual Conduct Law made Texas one of the few states that banned private, consensual sex between people of the same gender.

The statute registered Texas’s moral condemnation of gay sex, and, indeed, its condemnation of just being gay. But it was rarely enforced — until 1998, when two Harris County men, John Lawrence and Tyron Garner, were arrested and duly convicted of engaging in sex.

With the help of lawyers from Lambda Legal Defense, Lawrence and Garner asked a three-judge panel of a state court of appeals, all of whose members were Republican, to overturn their convictions.

In June 2000, the Texas court did so, ruling in a split decision that the Homosexual Conduct Law violated the state constitution’s equal rights amendment because it treated people unequally based on the gender of their sexual partners.

The case could well have ended there, with a ruling that applied only to 14 counties in southeastern Texas. And it would have ended, if the Harris County district attorney, a Republican, had decided to accept the defeat of a law that served no practical purpose and that two pretty conservative Republican judges considered an affront to basic notions of fairness.

But by that point the ideological purists of the Texas Republican Party would not let that happen. It was an election year, and the ruling came out just days before the state Republican convention in Houston. The party faithful adopted a resolution calling for the electoral defeat of the insufficiently conservative “activist” appeals-court judges who had struck down the sodomy law. The party platform denounced homosexual behavior as “contrary to the fundamental, unchanging truths that have been ordained by God.”

Taking the hint, the Harris County district attorney appealed the panel’s ruling to the full nine-judge appeals court. In March 2001, the full court voted 7 to 2 to uphold the Texas law, without even bothering to hear oral argument.

The state’s highest court, also dominated by Republicans, refused to hear Lawrence and Garner’s appeal, and so the case went to the U.S. Supreme Court, which not only struck down Texas’s idiotic and unjust law but also prohibited any state from ever again making or enforcing such a law — while laying the legal basis for more possible gay rights victories in the future.

There’s a lesson here for those who would lead today’s Republican Party down the path of ideological purity. In fact, there’s a lesson here for everyone.